//Initialize Fusion namespace
if (window.Fusion === undefined) window.Fusion = {};
if (window.Fusion.doPostLoad === undefined) window.Fusion.doPostLoad = false;
if (window.Fusion.webApp === undefined) window.Fusion.webApp = "/";
if (window.Fusion.protocol === undefined) window.Fusion.protocol = "//"; // could be "http://" or "https://" too
if (window.Fusion.warnings === undefined) window.Fusion.warnings = [];
if (window.Fusion.parameters === undefined) window.Fusion.parameters = {};
if (window.Fusion.adQueue === undefined) window.Fusion.adQueue = [];
if (window.Fusion.affiliate === undefined) window.Fusion.affiliate = undefined;
if (window.Fusion.ATTR_PAYLOAD === undefined) window.Fusion.ATTR_PAYLOAD = "Payload";

/**
 * Adds a warning if a field in window.Fusion doesn't exist.
 */
window.Fusion.assertFieldExists = function(field) {
	if (window.Fusion[field] === undefined) {
		window.Fusion.warnings.push("Assertion failed: Field \"" + field + "\" is undefined");
		return false;
	} else return true;
}

/**
 * Shows all warnings.
 */
window.Fusion.showWarnings = function(){
	var w, msg = window.Fusion.warnings.length ? window.Fusion.warnings.length + " warning/s:\n" + window.Fusion.warnings.join("\n") : "No warnings.";
	if (!window.Fusion.warnings.length || !(w = window.open("about:blank", "_blank", "width=800,height=600"))) alert(msg);
	else {
		w.document.open("text/plain");
		w.document.writeln(msg);
		w.document.close();
	}
}

/**
 * Randomizes a number in the interval [low, high)
 */
window.Fusion.randomInterval = function (low, high){ return Math.floor((Math.random() * (high - low)) + low); }

/**
 * Randomizes a string (character a-z) of length len.
 */
window.Fusion.randomAsciiString = function (len){
	var ret = "";
	while (len-- > 0)
		ret += String.fromCharCode(window.Fusion.randomInterval('a'.charCodeAt(0), 'z'.charCodeAt(0) + 1));
	return ret;
}

/**
 * Does a minimal HTML encoding of a string.
 */
window.Fusion.htmlEncode = function (s) {
	return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\'/g, "&#39;").replace(/\"/g, "&quot;");
}

/**
 * Expands special symbols in a component attribute.
 */
window.Fusion.expandAttribute = function (comp, attr, visited) {
	if (!visited) visited = [];
	var funcs = { "htmlEncode": window.Fusion.htmlEncode, "uriEncode": encodeURIComponent };
	return comp.attributes[attr].replace(/(\{{1,2})%([^%]+)%\}/g, function(match, braces, content){
		if (braces.length == 2) return "{%" + content + "%}"; // double braces quote
		var parts = content.split(":");
		var content = parts.pop().replace(/^([^\.]+)\.?(.*)$/, function (match2, prefix, suffix){
			switch (prefix){
				case "Fusion": 
					if (window.Fusion[suffix] === undefined) {
						window.Fusion.warnings.push("Tried to expand unknown Fusion attribute: " + suffix);
						return "Fusion." + suffix;
					} else return window.Fusion[suffix].toString();
				case "attribute":
					if (suffix in visited) {
						window.Fusion.warnings.push("Expanding attribute '" + attribute + "' causes infinite recursion. Stack is " + visited);
						return match2;
					} else {
						visited.push(suffix);
						var ret = window.Fusion.expandAttribute(comp, visited);
						visited.pop();
						return ret;
					}
				case "r": return window.Fusion.randomAsciiString(suffix ? parseInt(suffix, 10) : 5);
				case "eventUrl": return window.Fusion.getAdvertEventUrl(comp.ad, suffix);
				case "adId": return comp.ad.toString();
				default: window.Fusion.warnings.push("Tried to expand unknown macro: " + match2); return match2;
			}
		});
		while (parts.length > 0) {
			var funcName = parts.pop();
			var f = funcs[funcName];
			if (f === undefined) window.Fusion.warnings.push("Bad macro function: " + funcName);
			else content = f(content);
		}
		return content;
	});
}

window.Fusion.getComponent = function(placementName){
	if (window.Fusion.assertFieldExists("adComponents")) {
		var components = window.Fusion.adComponents[placementName];
		var component = null;
		if (typeof(components) != typeof([]) || components.length == 0){
			//window.Fusion.warnings.push("Tried to show ad for non-existing placement " + placementName);
			return null;
		} else if (typeof((component = components.shift()).attributes[window.Fusion.ATTR_PAYLOAD]) != typeof("")){
			window.Fusion.warnings.push("Component on placement " + placementName + 
					" for ad " + component.ad + " missing " + window.Fusion.ATTR_PAYLOAD + " attribute");
			return null;
		} else return window.Fusion.expandAttribute(component, window.Fusion.ATTR_PAYLOAD);
	} else return null;
}

/**
 * Constructs the base URL for an advert event call.
 * @param advertId The advert for which the event happened.
 * @param eventName The name of the event
 * @param redirectUrl Optional. If provided, the event counter will redirect the request to this URL. 
 */
window.Fusion.getAdvertEventUrl = function (advertId, eventName, redirectUrl){
	var url = window.Fusion.getUrlToFile("event");
	url += "/" + window.Fusion.randomAsciiString(5);
	url += "/" + encodeURIComponent(window.Fusion.mediaZone);
	url += "/" + encodeURIComponent(advertId);
	url += "/" + encodeURIComponent(eventName)
	if (window.Fusion.affiliate !== undefined)
		url += "/" + encodeURIComponent(window.Fusion.affiliate);
	if (redirectUrl !== undefined)
		url += "?url=" + encodeURIComponent(redirectUrl);
	return url;
}

/**
 * Notify the ad server that an event has occurred for an ad.
 *
 * Please note that adding a call to this function in, e.g., a 
 * link's onclick event doesn't always work as it doesn't capture 
 * clicks from right-clicks or middle-clicks.
 * 
 * @param advertId The ID of the advert
 * @param eventName The name of the event (e.g., "click")
 * @param redirectUrl The URL to redirect the user to. If this parameter
 * is unspecified, response from the servlet is "204 no content".
 * @param target The name of the window to open (equivalent to the "target"
 * attribute in HTML anchors). Defaults to "_blank".
 */
window.Fusion.countAdvertEvent = function (advertId, eventName, redirectUrl, target) {
	var url = window.Fusion.getAdvertEventUrl(advertId, eventName, redirectUrl);
	if (redirectUrl !== undefined) {
		// target defined? if not, use a new window
		if (target === undefined) target = "_blank";
		// acrobatics to get around popup blockers
		if (!window.open(url, target)) location.href = url;
	} else {
		// No redirect, do an asynchronous call and ignore whatever 
		// response there is (since it will be a 204). Add a random
		// string to prevent caching.
		var img = new Image();
		img.src = url;
	}
}

/**
 * Shows an ad for a placement.
 */
window.Fusion.space = function(placementName, placeholderTag) {
	if (window.Fusion.adComponents !== undefined) { // show directly
		var componentContent = window.Fusion.getComponent(placementName);
		if ((typeof componentContent) == (typeof "")) document.write(componentContent);
	} else if (window.Fusion.canDoPostLoad() && window.Fusion.doPostLoad) { // queue call
		window.Fusion.adQueue.push(new window.Fusion.QueuedAd(placementName, placeholderTag));
	} else { 
		// something is amiss
	}
}

/**
 * Performs an ad call, and shows the sole ad from that call.
 */
window.Fusion.SingleSpace = function (layout) {
	if (layout === undefined){ 
		window.Fusion.warnings.push("Missing layout in SingleSpace");
		return;
	}
	this.mediaZone = window.Fusion.mediaZone;
	this.affiliate = window.Fusion.affiliate;
	this.parameters = {};
	var prm = window.Fusion.parameters;
	// make deep copy of parameters
	for (var p in prm){
		if (typeof(prm[p]) == typeof([])) {
			var v = this.parameters[p] = [];
			for (var i = 0; i < prm[p].length; ++i)
				v.push(prm[p][i]);
		} else this.parameters[p] = prm[p];
	}
	this.show = function () {
		this.url = window.Fusion.getJsUrl(
				this.mediaZone || window.Fusion.mediaZone, 
				layout, 
				this.affiliate || window.Fusion.affiliate, 
				this.parameters || window.Fusion.parameters);
		window.Fusion.onAdsLoaded = function (ads) {
			var ncomponents = 0;
			var payload = undefined, component = undefined;
			for (var i in ads){
				if ((ncomponents += ads[i].length) > 1){
					window.Fusion.warnings.push("SingleSpace call returned more than one component");
					return;
				} else if (ads[i].length > 0) payload = (component = ads[i][0]).attributes[window.Fusion.ATTR_PAYLOAD];
			}
			if (payload === undefined) {
				window.Fusion.warnings.push(ncomponents > 0 
						? "None of the " + ncomponents + " components found had attribute " +  window.Fusion.ATTR_PAYLOAD
						: "No components found for SingleSpace call");
			} else document.write(window.Fusion.expandAttribute(component, window.Fusion.ATTR_PAYLOAD));
		} // onAdsLoaded(ads)
		document.writeln("<script type=\"text/javascript\" src=\"" + window.Fusion.htmlEncode(this.url) + "\">");
		document.writeln("</script>");
	} // show()
}

/**
 * Gets an absolute URL to a "file" in the Fusion webapp.
 */ 
window.Fusion.getUrlToFile = function (file) {
	window.Fusion.assertFieldExists("protocol");
	window.Fusion.assertFieldExists("webApp");
	window.Fusion.assertFieldExists("adServer");
	return window.Fusion.protocol + window.Fusion.adServer + Fusion.webApp + file;
}

window.Fusion.getJsUrl = function(mediaZone, layout, affiliate, params){
	var baseUrl = window.Fusion.getUrlToFile("js");
	// Add mandatory params
	baseUrl += "/" + window.Fusion.randomAsciiString(5);
	baseUrl += "/" + encodeURIComponent(mediaZone);
	baseUrl += "/" + encodeURIComponent(layout);
	// Add affiliate, if one is specified
	if (affiliate !== undefined)
		baseUrl += "/" + encodeURIComponent(affiliate);
	// Add optional params
	var queryString = "";
	for (var i in params){
		var allValues;
		if (typeof(params[i]) == typeof([]) && params[i].constructor == [].constructor)
			allValues = params[i];
		else allValues = [params[i]];
		for (var j = 0; j < allValues.length; ++j){
			if (queryString.length > 0) queryString += "&";
			queryString += encodeURIComponent(i) + "=" + encodeURIComponent(allValues[j] + "");
		}
	}
	if (queryString.length > 0) queryString = "?" + queryString;
	return baseUrl + queryString;
}

/**
 * Makes a smarttag call.
 */
window.Fusion.loadAds = function () {
	window.Fusion.assertFieldExists("mediaZone");
	window.Fusion.assertFieldExists("layout");
	window.Fusion.adScriptUrl = window.Fusion.getJsUrl(
			window.Fusion.mediaZone, window.Fusion.layout, 
			window.Fusion.affiliate, window.Fusion.parameters);
	// Include script
	if (window.Fusion.doPostLoad && window.Fusion.canDoPostLoad()) {
		var onLoaded = function(ads){ 
			window.Fusion.adComponents = ads; 
			while (window.Fusion.adQueue.length > 0)
				window.Fusion.adQueue.shift().showDynamic(); 
		}; 
		if(window.Fusion.doPostLoad && window.addEventListener){ // DOM events
			window.Fusion.onAdsLoaded = onLoaded;
			window.addEventListener("load", window.Fusion.postLoadAds, false);
		} else if (window.Fusion.doPostLoad && window.attachEvent){ // IE
			window.Fusion.onAdsLoaded = onLoaded;
			window.attachEvent("onload", window.Fusion.postLoadAds);
		} else { // shouldn't happen thanks to canDoPostLoad
			window.Fusion.warnings.push("Browser deemed capable of post-loading but can't append event handlers");
		} 
	} else { // old, bad browsers or no post-loading: load immediately
		window.Fusion.onAdsLoaded = function (ads) { window.Fusion.adComponents = ads; };
		document.writeln("<script type=\"text/javascript\" src=\"" + window.Fusion.htmlEncode(window.Fusion.adScriptUrl) + "\">");
		document.writeln("</script>");
	}
}

/**
 * Returns true if the browser is deemed capable of post-loading ads. Currently checks
 * if the browser can handle events in a modern, DOM-ish way, rather than using the old,
 * bad way of redefining window.onload. (If they can, it would be rather strange if they
 * can't handle other DOM constructs needed, like appendChild and getElementById.)
 */
window.Fusion.canDoPostLoad = function(){
	return !!(window.addEventListener || window.attachEvent);
}

/**
 * Post-loads ads when document has finished loading. In many cases,
 * it might be better to set doPostLoad to false and place the loadAds
 * call directly beneath the main content, so that stat counters etc
 * won't delay the ads.
 */
window.Fusion.postLoadAds = function () {
	var scriptElement = document.createElement("script");
	scriptElement.setAttribute("type", "text/javascript");
	scriptElement.setAttribute("src", window.Fusion.adScriptUrl);
	document.body.appendChild(scriptElement);
}

window.Fusion.QueuedAd = function (placement, placeholderTag) {
	this.placement = placement;
	this.id = "Fusion_queuedAd_" + window.Fusion.QueuedAd.serial++ + "_" + new Date().getTime().toString(32);
	if (placeholderTag === undefined) placeholderTag = "div";
	document.writeln("<" + placeholderTag + 
		" style=\"height:100%;width:100%;margin:0px;padding:0px;\" class=\"Fusion_queuedAd\" id=\"" + 
		this.id + "\"></" + placeholderTag + ">");
	this.showDynamic = function () {
		if (!document.getElementById) {
			window.Fusion.warnings.push("document.getElementById not supported when showing post-loaded ads");
			return;
		}
		var content = window.Fusion.getComponent(this.placement);
		var element = document.getElementById(this.id);
		if (content !== undefined) { // show ad
			element.innerHTML = content;
		} else { // remove placeholder element
			element.parentNode.removeChild(element);
		}
	}
}
window.Fusion.QueuedAd.serial = 0;

/**
 * Handlers for the metadata information sent to fireOnAdsLoaded
 */
window.Fusion.adSelectionMetaDataHandlers = {
	"warnings" : function (warnings) {
		for (var i = 0; i < warnings.length; ++i)
			window.Fusion.warnings.push(warnings[i]);
	},
	"diagnostics" : function (root) {
		function indent(n){ var r = ""; while (n-- > 0) r += "    "; return r; }
		function entry2html(entry, depth){
			var cls = "status-" + window.Fusion.htmlEncode(entry.status.toLowerCase());
			var msg = window.Fusion.htmlEncode(entry.message);
			if (entry.subEntries.length == 0){
				return indent(depth) + "<li class=\"" + cls + "\">" + msg + "</li>\n";
			} else {
				return (indent(depth) + "<li class=\"" + cls + "\">\n" + 
					indent(depth + 1) + msg + "\n" + 
					entries2html(entry.subEntries, depth + 1) + "\n" + 
					indent(depth) + "</li>\n");
			}
		}
		function entries2html(entries, depth){
			var items = [];
			for (var i = 0; i < entries.length; ++i) 
				items.push(entry2html(entries[i], depth + 1));
			if (items.length > 0){
				items.unshift(indent(depth) + "<ul>\n");
				items.push(indent(depth) + "</ul>\n");
			}
			return items.join("");
		}
		var win = window.open("about:blank", "_blank");
		if (win) {
			var oldProtocol = window.Fusion.protocol;
			window.Fusion.protocol = "http://";
			with (win.document){
				open("text/html");
				writeln("<html><head>");
				writeln(indent(1) + "<title>Selection diagnostics</title>");
				writeln(indent(1) + "<link rel=\"stylesheet\" href=\"" + 
						window.Fusion.htmlEncode(window.Fusion.getUrlToFile("util/diagnostics.css")) + "\" />");
				writeln(indent(1) + "<script type=\"text/javascript\" src=\"" + 
						window.Fusion.htmlEncode(window.Fusion.getUrlToFile("util/sorttable.js")) + "\"></script>");
				writeln("</head><body>");
				if (root.table){
					writeln("<table class=\"sortable\">");
					writeln(indent(1) + "<caption>Inspected ads</caption>");
					writeln(indent(1) + "<thead>");
					writeln(indent(2) + "<tr>");
					var headers = root.table.headers; 
					for (var i = 0; i < headers.length; ++i)
						writeln(indent(3) + "<th>" + window.Fusion.htmlEncode(headers[i]) + "</th>");
					writeln(indent(2) + "</tr>");
					writeln(indent(1) + "</thead>");
					writeln(indent(1) + "<tbody>");
					for (var i = 0; i < root.table.rows.length; ++i){
						writeln(indent(2) + "<tr>");
						var row = root.table.rows[i];
						for (var j = 0; j < row.length; ++j){
							var c = window.Fusion.htmlEncode(row[j].status.toLowerCase());
							var m = window.Fusion.htmlEncode(row[j].message);
							writeln(indent(3) + "<td class=\"status-" + c + "\">" + m + "</td>");
						}
						writeln(indent(2) + "</tr>");
					}
					writeln(indent(1) + "</tbody>");
					writeln("</table>");
				}
				if (root.tree){
					writeln("<ul>");
					writeln(indent(1) + "<li>");
					writeln(indent(2) + "Selection log:");
					writeln(entries2html(root.tree.subEntries, 3));
					writeln(indent(1) + "</li>");
					writeln("</ul>");
				}
				writeln("</body></html>");
				close();
			}
			window.Fusion.protocol = oldProtocol;
		} else alert("You browser's popup blocker stopped diagnostics window from showing.");
	}
};

/**
 * Called when the ads have finished loading.
 */
window.Fusion.fireOnAdsLoaded = function(ads, metadata){
	if (window.Fusion.assertFieldExists("onAdsLoaded")) {
		window.Fusion.onAdsLoaded(ads);
		delete window.Fusion.onAdsLoaded;
	}
	if (typeof metadata != "object") return;
	var handlers = window.Fusion.adSelectionMetaDataHandlers;
	for (var i in metadata){
		if (handlers[i] !== undefined) handlers[i](metadata[i]);
	}
}

// -- compatibility issues below

if (typeof(window.encodeURIComponent) != typeof(function(){})) {
	// Unicode URL encoding for old browsers
	window.encodeURIComponent = function(s){
		var unicodeEscapes = [
			"%00", "%01", "%02", "%03", "%04", "%05", "%06", "%07", 
			"%08", "%09", "%0A", "%0B", "%0C", "%0D", "%0E", "%0F", 
			"%10", "%11", "%12", "%13", "%14", "%15", "%16", "%17", 
			"%18", "%19", "%1A", "%1B", "%1C", "%1D", "%1E", "%1F", 
			"%20", "!", "%22", "%23", "%24", "%25", "%26", "\'", 
			"(", ")", "*", "%2B", "%2C", "-", ".", "%2F", 
			"0", "1", "2", "3", "4", "5", "6", "7", 
			"8", "9", "%3A", "%3B", "%3C", "%3D", "%3E", "%3F", 
			"%40", "A", "B", "C", "D", "E", "F", "G", 
			"H", "I", "J", "K", "L", "M", "N", "O", 
			"P", "Q", "R", "S", "T", "U", "V", "W", 
			"X", "Y", "Z", "%5B", "%5C", "%5D", "%5E", "_", 
			"%60", "a", "b", "c", "d", "e", "f", "g", 
			"h", "i", "j", "k", "l", "m", "n", "o", 
			"p", "q", "r", "s", "t", "u", "v", "w", 
			"x", "y", "z", "%7B", "%7C", "%7D", "~", "%7F", 
			"%C2%80", "%C2%81", "%C2%82", "%C2%83", "%C2%84", "%C2%85", "%C2%86", "%C2%87", 
			"%C2%88", "%C2%89", "%C2%8A", "%C2%8B", "%C2%8C", "%C2%8D", "%C2%8E", "%C2%8F", 
			"%C2%90", "%C2%91", "%C2%92", "%C2%93", "%C2%94", "%C2%95", "%C2%96", "%C2%97", 
			"%C2%98", "%C2%99", "%C2%9A", "%C2%9B", "%C2%9C", "%C2%9D", "%C2%9E", "%C2%9F", 
			"%C2%A0", "%C2%A1", "%C2%A2", "%C2%A3", "%C2%A4", "%C2%A5", "%C2%A6", "%C2%A7", 
			"%C2%A8", "%C2%A9", "%C2%AA", "%C2%AB", "%C2%AC", "%C2%AD", "%C2%AE", "%C2%AF", 
			"%C2%B0", "%C2%B1", "%C2%B2", "%C2%B3", "%C2%B4", "%C2%B5", "%C2%B6", "%C2%B7", 
			"%C2%B8", "%C2%B9", "%C2%BA", "%C2%BB", "%C2%BC", "%C2%BD", "%C2%BE", "%C2%BF", 
			"%C3%80", "%C3%81", "%C3%82", "%C3%83", "%C3%84", "%C3%85", "%C3%86", "%C3%87", 
			"%C3%88", "%C3%89", "%C3%8A", "%C3%8B", "%C3%8C", "%C3%8D", "%C3%8E", "%C3%8F", 
			"%C3%90", "%C3%91", "%C3%92", "%C3%93", "%C3%94", "%C3%95", "%C3%96", "%C3%97", 
			"%C3%98", "%C3%99", "%C3%9A", "%C3%9B", "%C3%9C", "%C3%9D", "%C3%9E", "%C3%9F", 
			"%C3%A0", "%C3%A1", "%C3%A2", "%C3%A3", "%C3%A4", "%C3%A5", "%C3%A6", "%C3%A7", 
			"%C3%A8", "%C3%A9", "%C3%AA", "%C3%AB", "%C3%AC", "%C3%AD", "%C3%AE", "%C3%AF", 
			"%C3%B0", "%C3%B1", "%C3%B2", "%C3%B3", "%C3%B4", "%C3%B5", "%C3%B6", "%C3%B7", 
			"%C3%B8", "%C3%B9", "%C3%BA", "%C3%BB", "%C3%BC", "%C3%BD", "%C3%BE", "%C3%BF"];
		var ret = "";
		for (var i = 0; i < s.length; ++i)
			ret += unicodeEscapes[s.charCodeAt(i)];
		return ret;
	} // encodeURIComponent
} // if not encodeURIComponent


/**
 * Browser detect code
 *
 */

// Initialize Fusion.Detect namespace
 if(!window.Fusion.Detect) window.Fusion.Detect = {};
 if(!window.Fusion.Detect.values) window.Fusion.Detect.values = {};
 if(!window.Fusion.Detect.agent) window.Fusion.Detect.agent = navigator.userAgent.toLowerCase();
 if(!window.Fusion.Detect.appVer) window.Fusion.Detect.appVer = navigator.appVersion.toLowerCase();	

 var flashVersion = 10;
 var hasFlashPlayer = false;
 var mediaPlayerVersion = 0;
 var hasWindowsMediaPlayer = false;
 var hasRealPlayerG2 = false;
 var hasRealPlayer4 = false;
 var hasRealPlayer5 = false;
 var hasSilverlight = false;
 var qtPlayerVersion = 0;
 var hasQTPlayer = false;

window.Fusion.Detect.doDetect = function()
{
	window.Fusion.Detect.detectBrowser();
	window.Fusion.Detect.detectOS();
	window.Fusion.Detect.detectPlugins();
	window.Fusion.Detect.detectResolution();
	window.Fusion.Detect.detectTime();
	window.Fusion.Detect.getPlugins();
	window.Fusion.Detect.addToParameters();
}

// Add detected values to smarttag call parameters
window.Fusion.Detect.addToParameters = function()
{
	for (var i in window.Fusion.Detect.values)
	{
		var allValues;
		if (typeof(window.Fusion.Detect.values[i]) != typeof([]))
		{
			allValues = [window.Fusion.Detect.values[i]];
		}
		else
		{
			allValues = window.Fusion.Detect.values[i];
		}
		
		for (var j = 0; j < allValues.length; ++j)
		{
			window.Fusion.parameters[i] = allValues[j];
		}
	}
}

window.Fusion.Detect.detectBrowser = function()
{
	window.Fusion.Detect.BrowserDetect.init();
	window.Fusion.Detect.values["browserName"] = window.Fusion.Detect.BrowserDetect.browser;
	window.Fusion.Detect.values["browserVersion"] = window.Fusion.Detect.BrowserDetect.version;	
	window.Fusion.Detect.values["browser"] = window.Fusion.Detect.BrowserDetect.browser + window.Fusion.Detect.BrowserDetect.version;
	
}



window.Fusion.Detect.detectOS = function()
{
	var isWin = (window.Fusion.Detect.agent.indexOf('win') != -1);
	var os = "";
	if ((window.Fusion.Detect.agent.indexOf('windows nt 6.0') != -1) && isWin)
	{
		os = "winvista";
	}
	else if ((window.Fusion.Detect.agent.indexOf('nt') != -1) && (window.Fusion.Detect.agent.indexOf('5.1') != -1) && isWin)
	{
		os = "winxp";
	}
	else if (((window.Fusion.Detect.agent.indexOf('win 9x 4.90') != -1) || (window.Fusion.Detect.agent.indexOf('windows me') != -1)) && isWin)
	{
		os = "winme";
	}
	else if ((window.Fusion.Detect.agent.indexOf('nt 5.0') != -1) && isWin)
	{
		os = "win2000";
	}
	else if ((window.Fusion.Detect.agent.indexOf('nt') != -1) && isWin)
	{
		os = "winnt";
	}
	else if ((window.Fusion.Detect.agent.indexOf('98') != -1) && isWin)
	{
		os = "win98";
	}
	else if ((window.Fusion.Detect.agent.indexOf('95') != -1) && isWin)
	{
		os = "win95";
	}
	else if (window.Fusion.Detect.agent.indexOf('macintosh') != -1)
	{
		os = "mac";
	}
	else if(window.Fusion.Detect.agent.indexOf('linux') != -1)
	{
		os = "linux";
	}
	else
	{
		os = "other";
	}
	
	window.Fusion.Detect.values["os"] = os;
	
}

window.Fusion.Detect.detectResolution = function()
{
	var resolution = "";
	
	if(window.screen)
	{
		var height = window.screen.height;
		var width = window.screen.width;
	    window.Fusion.Detect.values["screenRes"] = width + "x" + height;
		window.Fusion.Detect.values["screenWidth"]  = width;
		window.Fusion.Detect.values["screenHeight"] = height;
	}
	else
	{
		window.Fusion.Detect.values["screenRes"] = "n/a";
	}
	
	//Browser size
	var browserWidth = 0, browserHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) 
	{
	  //Non-IE
	  browserWidth = window.innerWidth;
	  browserHeight = window.innerHeight;
	}
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
	{
	  //IE 6+ in 'standards compliant mode'
	  browserWidth = document.documentElement.clientWidth;
	  browserHeight = document.documentElement.clientHeight;
	}
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
	{
	  //IE 4 compatible
	  browserWidth = document.body.clientWidth;
	  browserHeight = document.body.clientHeight;
	}
 	window.Fusion.Detect.values["browserWidth"] = browserWidth;
	window.Fusion.Detect.values["browserHeight"] = browserHeight;
	
}

window.Fusion.Detect.detectTime = function()
{
	var date = new Date();
	var hours = date.getHours();
	var minutes = date.getMinutes();
	
	if (hours < 10)
		hours = "0" + new String(hours);
		
	if (minutes < 10)
		minutes = "0" + new String(minutes);	
		
	window.Fusion.Detect.values["time"] = hours + minutes;	
}

window.Fusion.Detect.detectPlugins = function()
{
	
	if ((navigator.plugins != null) && (navigator.plugins.length > 0)) 
	{
		var mplayer =  (navigator.mimeTypes && 
						navigator.mimeTypes["application/x-mplayer2"] &&
					 	navigator.mimeTypes["application/x-mplayer2"].enabledPlugin) ?
					 	navigator.mimeTypes["application/x-mplayer2"].enabledPlugin : 0;
    	
    	if(mplayer) { window.Fusion.Detect.values["wm"] = 6; }
    	else { window.Fusion.Detect.values["wm"] = 0; }
		
		var rvplayer = 	(navigator.mimeTypes &&
						 navigator.mimeTypes['audio/x-pn-realaudio-plugin'] &&
				  		 navigator.mimeTypes['audio/x-pn-realaudio-plugin'].enabledPlugin) ?
				  		 navigator.mimeTypes['audio/x-pn-realaudio-plugin'].enabledPlugin : 0;

		if (rvplayer)
		{
			window.Fusion.Detect.values["rv"] = 6;
		}
		else
		{
			window.Fusion.Detect.values["rv"] = 0;
		}
		
		var silverlight = (navigator.mimeTypes &&
						 navigator.mimeTypes['application/x-silverlight'] &&
				  		 navigator.mimeTypes['application/x-silverlight'].enabledPlugin) ?
				  		 navigator.mimeTypes['application/x-silverlight'].enabledPlugin : 0;
		if(silverlight)
		{
			window.Fusion.Detect.values["silverlight"] = 1;
		}
	
		var quickPlugin = navigator.plugins['Quicktime'];
		if (typeof(quickPlugin) == 'object')
		{
			window.Fusion.Detect.values["qt"] = 5;
		}
		else
		{
			window.Fusion.Detect.values["qt"] = 0;
		}
	
		var flash =    (navigator.mimeTypes && 
                    navigator.mimeTypes["application/x-shockwave-flash"] &&
                    navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin) ?
                    navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;

		if (flash && flash.description) 
		{
			var numStart = flash.description.indexOf(".");
			while (/^\d$/.test(flash.description.charAt(--numStart)));
			++numStart;
			window.Fusion.Detect.values["flash"] = parseInt(flash.description.substring(numStart));
		}
		else
		{
			window.Fusion.Detect.values["flash"] = "0";
		}
	}
	else if((window.Fusion.Detect.agent.indexOf('win') != -1) && (window.Fusion.Detect.agent.indexOf('opera') == -1))
	{
		
		document.write(
		'\x3cSCRIPT LANGUAGE=VBScript\x3e\n'+
			'on error resume next\n'+
			'hasWindowsMediaPlayer = IsObject(CreateObject("WMPlayer.OCX"))\n'+
			'hasRealPlayerG2 = IsObject(CreateObject("rmocx.RealPlayer G2 Control"))\n'+
			'hasRealPlayer5 = IsObject(CreateObject("RealPlayer.RealPlayer(tm) ActiveX Control (32-bit)"))\n'+
			'hasRealPlayer4  = IsObject(CreateObject("RealVideo.RealVideo(tm) ActiveX Control (32-bit)"))\n'+
			'hasSilverlight = IsObject(CreateObject("AgControl.AgControl"))\n'+
			
         	'Do While flashVersion > 0' + '\n' +
            	'On Error Resume Next' + '\n' +
            	'hasFlashPlayer = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & flashVersion)))' + '\n' +
            	'If hasFlashPlayer = true Then Exit Do' + '\n' +
            	'flashVersion = flashVersion - 1' + '\n' +
         	'Loop' + '\n' +
			'\x3c/SCRIPT\x3e\n');
	}
}

window.Fusion.Detect.getPlugins = function()
{
	if(hasFlashPlayer)
	{ 
		window.Fusion.Detect.values["flash"] = flashVersion; 
	}  

	if(hasWindowsMediaPlayer)
	{	
		window.Fusion.Detect.values["wm"] = 9;
	}

	if(hasRealPlayerG2)
	{
		window.Fusion.Detect.values["rv"] = 3;
	}
	if(hasRealPlayer4)
	{
		window.Fusion.Detect.values["rv"] = 4;
	}
	if(hasRealPlayer5)
	{
		window.Fusion.Detect.values["rv"] = 5;
	}
	
	if(hasSilverlight)
	{
		window.Fusion.Detect.values["silverlight"] = 1;
	}
}

window.Fusion.Detect.printParameters = function()
{
	for(var i in window.Fusion.Detect.values)
	 {
		document.write(i + ":" + window.Fusion.Detect.values[i] + "<br/>")
	}
	document.write(navigator.userAgent + "<br/><br/>");
	document.write(navigator.appVersion + "<br/><br/>");	
}
window.Fusion.Detect.BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "unknown";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "1337";
		this.OS = this.searchString(this.dataOS) || "unknown";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			versionSearch: "Chrome/",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.userAgent,
			subString: "Windows NT 6.0",
			identity: "Vista"
		},
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
window.Fusion.Detect.doDetect();


/**
 * SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
if(typeof deconcept == "undefined") var deconcept = new Object();
if(typeof deconcept.util == "undefined") deconcept.util = new Object();
if(typeof deconcept.SWFObject_FusionUtil == "undefined") deconcept.SWFObject_FusionUtil = new Object();
deconcept.SWFObject_Fusion = function(swf, id, w, h, ver, c, quality, xiRedirectUrl, redirectUrl, detectKey) {
	if (!document.getElementById) { return; }
	this.DETECT_KEY = detectKey ? detectKey : 'detectflash';
	this.skipDetect = deconcept.util.getRequestParameter(this.DETECT_KEY);
	this.params = new Object();
	this.variables = new Object();
	this.attributes = new Array();
	if(swf) { this.setAttribute('swf', swf); }
	if(id) { this.setAttribute('id', id); }
	if(w) { this.setAttribute('width', w); }
	if(h) { this.setAttribute('height', h); }
	if(ver) { this.setAttribute('version', new deconcept.PlayerVersion(ver.toString().split("."))); }
	this.installedVer = deconcept.SWFObject_FusionUtil.getPlayerVersion();
	if (!window.opera && document.all && this.installedVer.major > 7) {
		// only add the onunload cleanup if the Flash Player version supports External Interface and we are in IE
		deconcept.SWFObject_Fusion.doPrepUnload = true;
	}
	if(c) { this.addParam('bgcolor', c); }
	var q = quality ? quality : 'high';
	this.addParam('quality', q);
	this.setAttribute('useExpressInstall', false);
	this.setAttribute('doExpressInstall', false);
	var xir = (xiRedirectUrl) ? xiRedirectUrl : window.location;
	this.setAttribute('xiRedirectUrl', xir);
	this.setAttribute('redirectUrl', '');
	if(redirectUrl) { this.setAttribute('redirectUrl', redirectUrl); }
}
deconcept.SWFObject_Fusion.prototype = {
	useExpressInstall: function(path) {
		this.xiSWFPath = !path ? "expressinstall.swf" : path;
		this.setAttribute('useExpressInstall', true);
	},
	setAttribute: function(name, value){
		this.attributes[name] = value;
	},
	getAttribute: function(name){
		return this.attributes[name];
	},
	addParam: function(name, value){
		this.params[name] = value;
	},
	getParams: function(){
		return this.params;
	},
	addVariable: function(name, value){
		this.variables[name] = value;
	},
	getVariable: function(name){
		return this.variables[name];
	},
	getVariables: function(){
		return this.variables;
	},
	getVariablePairs: function(){
		var variablePairs = new Array();
		var key;
		var variables = this.getVariables();
		for(key in variables){
			variablePairs[variablePairs.length] = key +"="+ variables[key];
		}
		return variablePairs;
	},
	getSWFHTML: function() {
		var swfNode = "";
		if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) { // netscape plugin architecture
			if (this.getAttribute("doExpressInstall")) {
				this.addVariable("MMplayerType", "PlugIn");
				this.setAttribute('swf', this.xiSWFPath);
			}
			swfNode = '<embed type="application/x-shockwave-flash" src="'+ this.getAttribute('swf') +'" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'" style="'+ this.getAttribute('style') +'"';
			swfNode += ' id="'+ this.getAttribute('id') +'" name="'+ this.getAttribute('id') +'" ';
			var params = this.getParams();
			 for(var key in params){ swfNode += [key] +'="'+ params[key] +'" '; }
			var pairs = this.getVariablePairs().join("&");
			 if (pairs.length > 0){ swfNode += 'flashvars="'+ pairs +'"'; }
			swfNode += '/>';
		} else { // PC IE
			if (this.getAttribute("doExpressInstall")) {
				this.addVariable("MMplayerType", "ActiveX");
				this.setAttribute('swf', this.xiSWFPath);
			}
			swfNode = '<object id="'+ this.getAttribute('id') +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'" style="'+ this.getAttribute('style') +'">';
			swfNode += '<param name="movie" value="'+ this.getAttribute('swf') +'" />';
			var params = this.getParams();
			for(var key in params) {
			 swfNode += '<param name="'+ key +'" value="'+ params[key] +'" />';
			}
			var pairs = this.getVariablePairs().join("&");
			if(pairs.length > 0) {swfNode += '<param name="flashvars" value="'+ pairs +'" />';}
			swfNode += "</object>";
		}
		return swfNode;
	},
	write: function(elementId){
		if(this.getAttribute('useExpressInstall')) {
			// check to see if we need to do an express install
			var expressInstallReqVer = new deconcept.PlayerVersion([6,0,65]);
			if (this.installedVer.versionIsValid(expressInstallReqVer) && !this.installedVer.versionIsValid(this.getAttribute('version'))) {
				this.setAttribute('doExpressInstall', true);
				this.addVariable("MMredirectURL", escape(this.getAttribute('xiRedirectUrl')));
				document.title = document.title.slice(0, 47) + " - Flash Player Installation";
				this.addVariable("MMdoctitle", document.title);
			}
		}
		if(this.skipDetect || this.getAttribute('doExpressInstall') || this.installedVer.versionIsValid(this.getAttribute('version'))){
			var n = (typeof elementId == 'string') ? document.getElementById(elementId) : elementId;
			n.innerHTML = this.getSWFHTML();
			return true;
		}else{
			if(this.getAttribute('redirectUrl') != "") {
				document.location.replace(this.getAttribute('redirectUrl'));
			}
		}
		return false;
	}
}

/* ---- detection functions ---- */
deconcept.SWFObject_FusionUtil.getPlayerVersion = function(){
	var PlayerVersion = new deconcept.PlayerVersion([0,0,0]);
	if(navigator.plugins && navigator.mimeTypes.length){
		var x = navigator.plugins["Shockwave Flash"];
		if(x && x.description) {
			PlayerVersion = new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
		}
	}else if (navigator.userAgent && navigator.userAgent.indexOf("Windows CE") >= 0){ // if Windows CE
		var axo = 1;
		var counter = 3;
		while(axo) {
			try {
				counter++;
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+ counter);
//				document.write("player v: "+ counter);
				PlayerVersion = new deconcept.PlayerVersion([counter,0,0]);
			} catch (e) {
				axo = null;
			}
		}
	} else { // Win IE (non mobile)
		// do minor version lookup in IE, but avoid fp6 crashing issues
		// see http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
		try{
			var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		}catch(e){
			try {
				var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
				PlayerVersion = new deconcept.PlayerVersion([6,0,21]);
				axo.AllowScriptAccess = "always"; // error if player version < 6.0.47 (thanks to Michael Williams @ Adobe for this code)
			} catch(e) {
				if (PlayerVersion.major == 6) {
					return PlayerVersion;
				}
			}
			try {
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			} catch(e) {}
		}
		if (axo != null) {
			PlayerVersion = new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
		}
	}
	return PlayerVersion;
}
deconcept.PlayerVersion = function(arrVersion){
	this.major = arrVersion[0] != null ? parseInt(arrVersion[0]) : 0;
	this.minor = arrVersion[1] != null ? parseInt(arrVersion[1]) : 0;
	this.rev = arrVersion[2] != null ? parseInt(arrVersion[2]) : 0;
}
deconcept.PlayerVersion.prototype.versionIsValid = function(fv){
	if(this.major < fv.major) return false;
	if(this.major > fv.major) return true;
	if(this.minor < fv.minor) return false;
	if(this.minor > fv.minor) return true;
	if(this.rev < fv.rev) return false;
	return true;
}
/* ---- get value of query string param ---- */
deconcept.util = {
	getRequestParameter: function(param) {
		var q = document.location.search || document.location.hash;
		if (param == null) { return q; }
		if(q) {
			var pairs = q.substring(1).split("&");
			for (var i=0; i < pairs.length; i++) {
				if (pairs[i].substring(0, pairs[i].indexOf("=")) == param) {
					return pairs[i].substring((pairs[i].indexOf("=")+1));
				}
			}
		}
		return "";
	}
}
/* fix for video streaming bug */
deconcept.SWFObject_FusionUtil.cleanupSWFs = function() {
	var objects = document.getElementsByTagName("OBJECT");
	for (var i = objects.length - 1; i >= 0; i--) {
		objects[i].style.display = 'none';
		for (var x in objects[i]) {
			if (typeof objects[i][x] == 'function') {
				objects[i][x] = function(){};
			}
		}
	}
}
// fixes bug in some fp9 versions see http://blog.deconcept.com/2006/07/28/swfobject-143-released/
if (deconcept.SWFObject_Fusion.doPrepUnload) {
	if (!deconcept.unloadSet) {
		deconcept.SWFObject_FusionUtil.prepUnload = function() {
			__flash_unloadHandler = function(){};
			__flash_savedUnloadHandler = function(){};
			window.attachEvent("onunload", deconcept.SWFObject_FusionUtil.cleanupSWFs);
		}
		window.attachEvent("onbeforeunload", deconcept.SWFObject_FusionUtil.prepUnload);
		deconcept.unloadSet = true;
	}
}
/* add document.getElementById if needed (mobile IE < 5) */
if (!document.getElementById && document.all) { document.getElementById = function(id) { return document.all[id]; }}

/* add some aliases for ease of use/backwards compatibility */
var SWFObject_Fusion = deconcept.SWFObject_Fusion;

// Run Fusion initiation hooks
(function () {
	if (window.Fusion.initiationHooks !== undefined){
		while (window.Fusion.initiationHooks.length > 0)
			window.Fusion.initiationHooks.shift()();
		delete window.Fusion.initiationHooks;
	}
})();
