var body_loaded=false;

function bodyload(){
	body_loaded=true;
}

//flash detection
var MM_contentVersion = 8;
var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
if ( plugin ) {
		var words = navigator.plugins["Shockwave Flash"].description.split(" ");
	    for (var i = 0; i < words.length; ++i)
	    {
		if (isNaN(parseInt(words[i])))
		continue;
		var MM_PluginVersion = words[i];
	    }
	var MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;
}
else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0
   && (navigator.appVersion.indexOf("Win") != -1)) {
	document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n'); //FS hide this from IE4.5 Mac by splitting the tag
	document.write('on error resume next \n');
	document.write('MM_FlashCanPlay = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & MM_contentVersion)))\n');
	document.write('</SCR' + 'IPT\> \n');
}

var flashString;
var tempObj;
var flashCount=1;
//printFlash uses innerHTML to render flash objs to get around the IE flash rendering issue
function printFlash(id, src, wmode, menu, bgcolor, width, height, quality, base, flashvars, noflash, scriptaccess, fullscreen){

	if(MM_FlashCanPlay && getcookie("showflash")!="false" ){

		flashString = '<object type="application/x-shockwave-flash" data="' + src + '" width="' + width + '" height="' + height + '" id="' + id + 'Flash"><param name="movie" value="' + src + '"></param><param name="quality" value="' + quality + '"></param>';
		if(base){
		flashString+='<param name="base" value="' + base + '"></param>';
		}
		if(scriptaccess){
		flashString+='<param name="allowScriptAccess" value="' + scriptaccess + '"></param>';
		}
		if(fullscreen){
		flashString+='<param name="allowFullScreen" value="' + fullscreen + '"></param>';
		}		
		flashString+='<param name="flashvars" value="' + flashvars + '" ></param><param name="bgcolor" value="' + bgcolor + '" ></param><param name="menu" value="' + menu + '" ></param><param name="wmode" value="' + wmode + '" ></param><param name="salign" value="tl" ></param>';

		flashString+='</object>';	
	}else{

		flashString=noflash;

	}

	if(is_safari && !body_loaded)
		document.write(flashString)
	else
		document.getElementById(id).innerHTML = flashString;


}


function dropdownMenuToggle(whichOne){
	theStyle = document.getElementById(whichOne).style;

	if (theStyle.display == "none") {
		theStyle.display = "block";
	} else
		theStyle.display = "none";
}



//Ajax Data Loading

var xmlDataArray = new Array;
var	myXMLHTTPRequest;
var	myXMLHTTPRequest2;
var intervalHolder;
var containerGlobal;
var loaderGlobal;


function checkJSLoad(container){


	tempArray=document.getElementById(container).innerHTML.split('<SCRIPT');
	jsArrayLength=tempArray.length;
	head = document.getElementsByTagName("head");
//alert(document.getElementById(container).innerHTML)
	for(jsLoadCount=1;jsLoadCount<jsArrayLength;jsLoadCount++){


		scriptString=tempArray[jsLoadCount].split('</SCRIPT>')[0];
		theSrc="";
		theScript="";
		scriptTagEndLoc=scriptString.indexOf(" type=text/javascript>");
		scriptTagEndLocLength=22;
		if(scriptTagEndLoc=-1){//look for the type att with quotes
			scriptTagEndLoc=scriptString.indexOf(' type="text/javascript">');
			scriptTagEndLocLength=24;
		}

		theScript=scriptString.substring(scriptTagEndLoc+scriptTagEndLocLength,scriptString.length);

		if(is_safari)
			eval(theScript)
		else {
			script = document.createElement("script");
			head[0].appendChild(script);

			script.type = "text/javascript";
			if(theSrc)script.src = theSrc;
			if(theScript)script.text = theScript;
		}

	}


}

function xmlDataLoad(xmlSource, xslSource, container, aSync, loader, afterFunction){

	if('undefined' == typeof afterFunction) {afterFunction="dummyFunction()";}
	window.clearInterval(intervalHolder);
	document.getElementById(loader).style.display = "block";

	if (is_ie && !is_opera) {


		var xml = new ActiveXObject("Microsoft.XMLDOM")
		xml.async = aSync
		xml.load(xmlSource)// Load XSL
		var xsl = new ActiveXObject("Microsoft.XMLDOM")
		xsl.async = aSync
		xsl.load(xslSource)// Transform

		if(!aSync){
			document.write(xml.transformNode(xsl));
		}else{

			xmlDataArray[0]=xml;
			xmlDataArray[1]=xsl;

			intervalHolder = window.setInterval("xmlDataLoadListener(xmlDataArray[0],xmlDataArray[1],'"+container+"','"+loader+"','"+afterFunction+"')",100);

		}

		//return true;


	} else if (is_moz) {

			var xslStylesheet;
			var myDOM;
			var xmlDoc;
			myXMLHTTPRequest = new XMLHttpRequest();
			myXMLHTTPRequest2 = new XMLHttpRequest();

			myXMLHTTPRequest.open("GET", xslSource, aSync);
			myXMLHTTPRequest.send(null);

			// load the xml file, example1.xml

			myXMLHTTPRequest2.open("GET", xmlSource, aSync);
			myXMLHTTPRequest2.send(null);


			containerGlobal=container;
			loaderGlobal=loader;
			//myXMLHTTPRequest.onreadystatechange = stateHandler;
			//myXMLHTTPRequest2.onreadystatechange = stateHandler;

			intervalHolder = window.setInterval("xmlDataLoadListenerMoz(myXMLHTTPRequest2,myXMLHTTPRequest,'"+container+"','"+loader+"','"+afterFunction+"')",100);


	} else {



		var safariXmlRequest = new XMLHttpRequest;
		function safariReadystateHandler()
		{
			if(safariXmlRequest.readyState == 4)
			{

				document.getElementById(container).innerHTML = safariXmlRequest.responseText;
				document.getElementById(loader).style.display = "none";

				checkJSLoad(container)
				eval(afterFunction);
			}
		}
		safariXmlRequest.onreadystatechange = safariReadystateHandler;
		safariXmlRequest.open("GET", xmlSource, true);
		safariXmlRequest.send(null);




	}


	//return false;


}

function xmlDataLoadListener(xmlObj, xslObj, container, loader, afterFunction){

			if (xmlObj.readyState == 4 && xslObj.readyState == 4) {
				document.getElementById(container).innerHTML = xmlObj.transformNode(xslObj);

				checkJSLoad(container)
				document.getElementById(loader).style.display = "none";
				eval(afterFunction);
				window.clearInterval(intervalHolder);
			}

}

function xmlDataLoadListenerMoz(xmlObj, xslObj, container, loader, afterFunction){

			if (xmlObj.readyState == 4 && xslObj.readyState == 4) {

					window.clearInterval(intervalHolder);
 					xslStylesheet = xslObj.responseXML;
					xmlDoc = xmlObj.responseXML;

 					var xsltProcessor = new XSLTProcessor();
					xsltProcessor.importStylesheet(xslStylesheet);

					xmlLoadComplete=1;
					var fragment = xsltProcessor.transformToFragment(xmlDoc, window.document);
					document.getElementById(containerGlobal).innerHTML = "";
					document.getElementById(containerGlobal).appendChild(fragment);
					document.getElementById(loader).style.display = "none";
					eval(afterFunction);


			}

}

function dummyFunction(){}

function showContentArea(contentarea){

	document.getElementById(contentarea).style.visibility="visible";

}


function defaultAjaxContent(lang){

	var searchString=document.location.search
	var varPairs = searchString.substring(1,searchString.length).split("=")

	if(varPairs[0]=="tab"){

		if(varPairs[1]=="news")
			xmlDataLoad('/strings/'+lang+'/rss.xml','/layout/rss.xsl','ajaxcontentarea',true,'loader','showContentArea("ajaxcontentarea")');
		if(varPairs[1]=="zealot")
			xmlDataLoad('/features/protoss/zealot.xml','/layout/protoss-zealot-ajax.xsl','ajaxcontentarea',true,'loader','showContentArea("ajaxcontentarea")');
		if(varPairs[1]=="immortal")
			xmlDataLoad('/features/protoss/immortal.xml','/layout/protoss-immortal-ajax.xsl','ajaxcontentarea',true,'loader','showContentArea("ajaxcontentarea")');
		if(varPairs[1]=="stalker")
			xmlDataLoad('/features/protoss/stalker.xml','/layout/protoss-stalker-ajax.xsl','ajaxcontentarea',true,'loader','showContentArea("ajaxcontentarea")');
		if(varPairs[1]=="phaseprism")
			xmlDataLoad('/features/protoss/phaseprism.xml','/layout/protoss-phaseprism-ajax.xsl','ajaxcontentarea',true,'loader','showContentArea("ajaxcontentarea")');
		if(varPairs[1]=="phoenix")
			xmlDataLoad('/features/protoss/phoenix.xml','/layout/protoss-phoenix-ajax.xsl','ajaxcontentarea',true,'loader','showContentArea("ajaxcontentarea")');
		if(varPairs[1]=="colossus")
			xmlDataLoad('/features/protoss/colossus.xml','/layout/protoss-colossus-ajax.xsl','ajaxcontentarea',true,'loader','showContentArea("ajaxcontentarea")');
		if(varPairs[1]=="warpray")
			xmlDataLoad('/features/protoss/warpray.xml','/layout/protoss-warpray-ajax.xsl','ajaxcontentarea',true,'loader','showContentArea("ajaxcontentarea")');
		if(varPairs[1]=="twilightarchon")
			xmlDataLoad('/features/protoss/twilightarchon.xml','/layout/protoss-twilightarchon-ajax.xsl','ajaxcontentarea',true,'loader','showContentArea("ajaxcontentarea")');
		if(varPairs[1]=="darktemplar")
			xmlDataLoad('/features/protoss/darktemplar.xml','/layout/protoss-darktemplar-ajax.xsl','ajaxcontentarea',true,'loader','showContentArea("ajaxcontentarea")');
		if(varPairs[1]=="gateway")
			xmlDataLoad('/features/protoss/gateway.xml','/layout/protoss-gateway-ajax.xsl','ajaxcontentarea',true,'loader','showContentArea("ajaxcontentarea")');
		if(varPairs[1]=="stargate")
			xmlDataLoad('/features/protoss/stargate.xml','/layout/protoss-stargate-ajax.xsl','ajaxcontentarea',true,'loader','showContentArea("ajaxcontentarea")');
		if(varPairs[1]=="marine")
			xmlDataLoad('/features/terran/marine.xml','/layout/terran-marine-ajax.xsl','ajaxcontentarea',true,'loader','showContentArea("ajaxcontentarea")');
		if(varPairs[1]=="reaper")
			xmlDataLoad('/features/terran/reaper.xml','/layout/terran-reaper-ajax.xsl','ajaxcontentarea',true,'loader','showContentArea("ajaxcontentarea")');
		if(varPairs[1]=="ghost")
			xmlDataLoad('/features/terran/ghost.xml','/layout/terran-ghost-ajax.xsl','ajaxcontentarea',true,'loader','showContentArea("ajaxcontentarea")');
		if(varPairs[1]=="viking")
			xmlDataLoad('/features/terran/viking.xml','/layout/terran-viking-ajax.xsl','ajaxcontentarea',true,'loader','showContentArea("ajaxcontentarea")');
		if(varPairs[1]=="banshee")
			xmlDataLoad('/features/terran/banshee.xml','/layout/terran-banshee-ajax.xsl','ajaxcontentarea',true,'loader','showContentArea("ajaxcontentarea")');
		if(varPairs[1]=="thor")
			xmlDataLoad('/features/terran/thor.xml','/layout/terran-thor-ajax.xsl','ajaxcontentarea',true,'loader','showContentArea("ajaxcontentarea")');
		if(varPairs[1]=="commandcenter")
			xmlDataLoad('/features/terran/commandcenter.xml','/layout/terran-commandcenter-ajax.xsl','ajaxcontentarea',true,'loader','showContentArea("ajaxcontentarea")');

	} else {

		showContentArea("ajaxcontentarea");

	}


}


function selectLang(theDisplay, cookieValue) {
	document.getElementById("dropdownHiddenLang").style.display = "none";
	document.getElementById("displayLang").innerHTML = theDisplay;

	window.location += "?locale=" + cookieValue
}

function getexpirydate(nodays){
	var UTCstring;
	Today = new Date();
	nomilli=Date.parse(Today);
	Today.setTime(nomilli+nodays*24*60*60*1000);
	UTCstring = Today.toUTCString();
	return UTCstring;
}

function getcookie(cookiename) {
	 var cookiestring=""+document.cookie;
	 var index1=cookiestring.indexOf(cookiename);
	 if (index1==-1 || cookiename=="") return "";
	 var index2=cookiestring.indexOf(';',index1);
	 if (index2==-1) index2=cookiestring.length;
	 return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}
function setm(name,value,expire,domain){
	var expireString="EXPIRES="+ getexpirydate(365)+";"
	var domainString="DOMAIN="+ domain
	if(expire=="session")
		expireString="";
	if(!domain)
		domainString="";
	cookiestring=name+"="+escape(value)+";"+expireString+"PATH=/;"+domainString;
	document.cookie=cookiestring;
}

function toggleFlash(){

	if(MM_FlashCanPlay){
		if(getcookie("showflash")=="false")
			setcookie("showflash", "true");
		else
			setcookie("showflash", "false");
	}
	document.location.reload();

}

function showNoflashMessage(){

	if(!MM_FlashCanPlay){

		document.getElementById("noflash-message").style.display="block";

	}

}

ticked = 0;
animationLock = false;

function fiatLux(thisImage)
{
 if(!animationLock)
 {
	animationLock = true;
	imageHolder = new Image();
	document.getElementById("lightBoxRoot").style.visibility = "hidden";
	document.getElementById("lightBoxRoot").style.opacity = 0;
	document.getElementById("lightBoxRoot").style.filter = "alpha(opacity=0)";
	document.getElementsByTagName("body")[0].appendChild(document.getElementById("blackDrop"));
	document.getElementsByTagName("body")[0].appendChild(document.getElementById("lightBoxRoot"));
	imageHolder.src = thisImage;
	windowWidth = (window.innerWidth) ? window.innerWidth : document.documentElement.clientWidth;
	windowHeight = (window.innerHeight) ? window.innerHeight : document.documentElement.clientHeight;
	scrollDistance = (navigator.userAgent.indexOf("Safari")==-1) ? document.documentElement.scrollTop : window.pageYOffset;
	displayLightBox();
 }
}

function displayLightBox()
{
	if(imageHolder.complete)
	{
		document.getElementById("lightBoxHolder").style.width = imageHolder.width + "px";
		document.getElementById("lightBoxHolder").style.height = imageHolder.height + "px";
		document.getElementById("lightBoxHolder").style.backgroundImage = "url("+imageHolder.src+")";
		document.getElementById("lightBoxRoot").style.width = imageHolder.width + 20 + "px";
		document.getElementById("lightBoxRoot").style.height = imageHolder.height + 20 + "px";
		document.getElementById("lightBoxRoot").style.left = (windowWidth/2)-(imageHolder.width/2) + "px";
//		document.getElementById("lightBoxRoot").style.top = (windowHeight/2)-(imageHolder.height/2)-10 + "px";
		document.getElementById("blackDrop").style.display = "block";
		document.getElementById("blackDrop").style.height = document.body.scrollHeight+"px";
		document.getElementById("lightBoxRoot").style.top = 40+scrollDistance+"px";
		document.getElementById("lightBoxRoot").style.visibility = "visible";
//		fadeAnimationHolder = window.setInterval("fadeLightBox()",25);
/*NO MORE FADING*/
		document.getElementById("lightBoxRoot").style.filter = "alpha(opacity=100)";
		document.getElementById("lightBoxRoot").style.opacity = "1";
		animationLock = false;
/**/
	}
	else window.setTimeout("displayLightBox();",250);
}
/*DEPRECATED:
function fadeLightBox()
{
	if(ticked==20)
	{
		window.clearInterval(fadeAnimationHolder);
		ticked = 0;
		delete imageHolder;
		animationLock = false;
	}
	else
	{
		document.getElementById("lightBoxRoot").style.opacity = ticked/10;
		document.getElementById("lightBoxRoot").style.filter = "alpha(opacity="+(ticked/10)*100+")";
		ticked += 10;
	}
}
END DEPRECATED*/
function closeLightbox(e)
{
	if(!animationLock)
	{
		document.getElementById("lightBoxRoot").style.visibility = "hidden";
		document.getElementById("lightBoxRoot").style.opacity = 0;
		document.getElementById("lightBoxRoot").style.filter = "alpha(opacity=0)";
		document.getElementById("blackDrop").style.display = "none";
	}

	if(e) {
		if(e.stopPropagation) {
			e.stopPropagation();
		}
		e.cancelBubble = true;
		return false;
	}
}

function FnGetLink(mylink)
{
	window.location=mylink;
}


ctx = "/"
function unitloop(flv,img,dir,w,h,targ,noskin)
{
			var so = new SWFObject(ctx+"flash/global/unit_loop.swf", targ+"-id", w, h, "9");
			so.addParam("base", ctx+"flash/global/");
			so.addParam("allowScriptAccess", "always");
			so.addParam("allowFullScreen", "true");
			so.addVariable("vidArr", flv+":"+img+":"+dir)
			if(noskin) so.addVariable("noskin", noskin)
			so.write(targ);
}

function blizzvideo(flv,img,dir,w,h,targ,autoplay,agegate)
{
	var so = new SWFObject("http://us.media.blizzard.com/blizzard/movies/player/video_loader2.swf", targ+"-id", w, h, "9");
	so.addParam("base", "http://us.media.blizzard.com/blizzard/movies/player/"); 
	so.addParam("allowScriptAccess", "always");
	so.addParam("allowFullScreen", "true");
	so.addVariable("vidArr", flv+":"+img+":"+dir)
	so.addVariable("autoplay", autoplay||"false")
	so.addVariable("agegatereq", agegate||"false")
	so.addVariable("showplaybtn", "true")
	so.write(targ);   
}
