/**
 * Builds the function that will set the 'href' attribute of the theme skin
 * controls (min, max, etc) when clicked.
 */
function getVTSkinFunc(el, dyn) {
	
	return function(lnk, path) {
		lnk.href = getVTSkinPrefix(el, dyn) + path.split('').reverse().join('');
	}
}

/**
 * Determines the WebSEAL prefix currently in use by using the 'src' attribute
 * of an <img> element on the page and an Image object with the same path. The
 * dynamically generated image will not have the WebSEAL prefix (if there is
 * one) making it possible to extract the prefix.
 */
function getVTSkinPrefix(el, dyn) {

	var d = document;
	if (!d || !d.getElementById) {
		return '';
	}
	var p1 = d.getElementById(el);
	if (!p1 || 'string' != typeof (p1 = p1.src)) {
		return '';
	}
	if ('undefined' == typeof Image) {
		return '';
	}
	var p2 = new Image();
	if (!p2) {
		return '';
	}
	p2.src = dyn;
	if ('string' != typeof (p2 = p2.src)) {
		return '';
	}
	if (p1 != p2) {
		for (var b = 0; b < p2.length; ++b) {
			if (p1.charAt(b) != p2.charAt(b)) {
				break;
			}
		}
		var e = p1.lastIndexOf(p2.substring(b)) - 1;
		if (e > b) {
			return '/' + p1.substring(b, e);
		}
	}
	return '';
}
