String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); };

function loadVideoPlayer(template, player, clip, bgcolor, templateVersion,container) {
	var request = getXMLObj();
	request.onreadystatechange = function(){
		if (request.readyState == 4 && request.status == 200){
			res = request.responseText;
			eval(res.trim());
			switch(templateVersion) {
				case "small" :	width='400'; height='365'; break;
				case "cbcSmall" : width='359'; height='400'; break;
				case "medium" : width='740'; height='460'; break;
				case "large" : width='990'; height='592'; break;
				case "olympicsLargeSinglePlaylist" : width='956'; height='561'; break;
				case "olympicsLargeSingleClip" : width='586'; height='379'; break;
				case "olympicsSmallSingleClip" : width='360'; height='248'; break;
			}
			var so = new SWFObject(streamPath, 'video', width, height, '9', bgcolor);
			so.addParam('allowScriptAccess', 'always');
			if((navigator.userAgent.toLowerCase()).indexOf('windows') == -1) {	so.addParam('wmode', 'transparent');}
			so.addParam('allowFullScreen', 'true');
			so.addParam('scale', 'noscale'); 
			so.addParam('salign', 'TL');

			so.addVariable('playerId', player);
			if(clip != "")	{so.addVariable('referralObject', clip);}
			so.addVariable('referralPlaylistId', "null");
			so.addVariable('referralParentPlaylistId', "null");
			so.useExpressInstall('/tvarts/includes/swfobject/expressinstall.swf');
			(container) ? so.write(container) : so.write('videoPlayer');
		}
	};
	 
	request.open("GET", "/tvarts/templates/maven.php?template="+template+"&templateVersion="+templateVersion, true);
	request.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	request.send(null);
}

//XML OBJECT
function getXMLObj() {
	
	/*var doc = null;
	if (typeof window.ActiveXObject != 'undefined' ) doc = new ActiveXObject("Microsoft.XMLHTTP");
	else doc = new XMLHttpRequest();
	return doc;*/
	
	var xhr;
	if (window.XMLHttpRequest) {
	  xhr = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) {
	  xhr = new ActiveXObject("Msxml2.XMLHTTP");
	}

	return xhr;
	
}

function swapAd() {
	$('masthead-ad').innerHTML = "";
	iframe = document.createElement("iframe");
	iframe.style.width="728px";
	iframe.style.height="90px";
	iframe.scrolling = "no";
	iframe.setAttribute("frameborder","0");
	iframe.setAttribute("border","0");
	
	iframe.src = "/tvarts/includes/getAdSrc.php?advertising_zone="+advertising_zone+"&ord="+ord;
	$('masthead-ad').appendChild(iframe);
	
	//new PeriodicalExecuter(swapAd, 120);
}


//©2006 Bad Math Inc. (http://www.badmath.com/)  Free to use, so long as this credit line is included.

//convert any <img> tags with '.png' in the filename to use MS's AlphaImageLoader on IE/Win, to support PNG transparency
//'x.gif' (single-pixel transparent gif) is required

//USAGE: include this script, and put the following HTML line at the bottom of your page:
// <script type="text/javascript" language="JavaScript">ieMakeTransparentPNGs();</script>



function ieMakeTransparentPNGs() {
	if ( 
		((navigator.userAgent.toLowerCase()).indexOf('msie') + 1) && 		//'+1' because indexOf returns -1 if string is not found
		((navigator.userAgent.toLowerCase()).indexOf('windows') + 1)  && 
		!((navigator.userAgent.toLowerCase()).indexOf('opera') + 1) 		//Opera reports itself as MSIE/Windows, but also adds an 'Opera' string
		) { 	

		for (i=0;i<document.images.length;i++) {
			if (document.images[i].src.toLowerCase().indexOf('.png') + 1) {
				var pngImage = document.images[i];
				pngImage.style.width = pngImage.offsetWidth;
				pngImage.style.height = pngImage.offsetHeight;
				pngImage.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+pngImage.src+"',sizingMethod='scale');";
				pngImage.src = '/tvarts/templates/images/transparent.gif';

			}
		}
	}
}

var QueryString = {
	init : function () {
		this.url = location.toString();
		this.qs = this.url.split("?")[1] || this.url.split("#")[1];
		//this.qs = this.url.split("?")[1];
		(this.qs) ? this.qsPairs = this.qs.split("&") : this.qsPairs = [];
	},
	
	baseurl : function() {	(this.url.indexOf('www.cbc.ca') != -1) ? b_url = 'www.cbc.ca' : b_url = 'www.dev.nm.cbc.ca'; return b_url;},
	
	hasQueryString : function() {
		(this.qs) ? res = true : res = false;
		return res;
	},
	
	hasParameter : function(param) {
		(this.qs.indexOf(param) != -1) ? res=true : res=false;
		return res;
	},
	
	getParameter : function(param) {
		if (QueryString.hasParameter(param)) {
			for(i=0;i<this.qsPairs.length; i++) {
				if (this.qsPairs[i].split("=")[0] == param) {
					res = this.qsPairs[i].split("=")[1];
				}
			}
		}
		else {
			res = null;
		}
		return res;
	}
}
