var W3CDOM = (document.getElementById && document.getElementsByTagName);
var vFlashVersion = fGetFlashVersion();
var vFlashWModeOK = fGetFlashWModeOK();
var vSiteRoot = fGetRoot();
if(document.location.search.indexOf("flash=0")>-1) vFlashVersion = 0;
if(document.location.search.indexOf("flash=1")>-1) vFlashWModeOK = 0;
var vFlashOK = (vFlashVersion>4);
/* Date */
function fWriteDate(){
	var dt = new Date();
	var d = "Sunday|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday".split("|");
	var m = "January|February|March|April|May|June|July|August|September|October|November|December".split("|");
	var t = "|st|nd|rd|th".split("|");
	var c = dt.getDate();
	var e = c%10;
	var f = Math.floor(c/10);
	document.write("<span class='day'>"+d[dt.getDay()]+"</span> "+c+"<sup>"+t[(e>3||f==1)?4:e]+"</sup> "+m[dt.getMonth()]+" "+dt.getFullYear());
}
function fRandomNum(range){
var num = Math.floor(Math.random()*range)+1;
return num;
}
function fWriteProduct(file){
	if(vFlashOK){
		fWriteFlash("_assets/media/products/swfProd"+file+".swf",null,null,null,"TL");
	}else {
		document.write('<img src="'+vSiteRoot+'_assets/media/products/imgProd'+file+'.jpg" alt="" />');
	}
}
function fWriteSWF(file, fileType){
	if(vFlashOK){
		fWriteFlash("_assets/media/swf"+file+".swf",null,null,null,"TL");
		}else {
		document.write('<img src="'+vSiteRoot+'_assets/media/img'+file+'.'+fileType+'" alt="" />');
		}
}
function fWriteSWFBanner(){
	var num = fRandomNum(2);
	if(vFlashOK){
		fWriteFlash("_assets/media/banners/swfBanner"+num+".swf",null,null,null,"TL");
		}else {
		document.write('<img src="'+vSiteRoot+'_assets/media/banners/imgBanner'+num+'.jpg" alt="" />');
		}
}
function fWriteSWFMap(){
	if(vFlashOK){
		fWriteFlash("_assets/media/swfMap.swf",null,null,null,"TL");
		}else {
		fToggleIDMap("iMap1");
		}
}

function fWriteFlash(swf,fid,bgcolor,transparent,noscale){
	var swf = vSiteRoot + swf;
	var txt = "";
	txt += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="100%" height="100%" ';
 	if(fid) txt += 'id="'+fid+'" ' ;
	txt += 'codebase="//download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0">';
txt += '<param name="movie" value="'+swf+'" />';
	txt += '<param name="menu" value="false" />';
 	if(bgcolor) txt += '<param name="bgcolor" value="'+bgcolor+'" />';
	if(noscale) txt += '<param name="scale" value="noscale" /><param name="salign" value="'+noscale+'" />';
	if(transparent) txt += '<param name="wmode" value="transparent" />';
	txt += '<embed src="'+swf+'" menu="false" width="100%" height="100%" ';
 	if(fid) txt += 'id="'+fid+'" name="'+fid+'" ' ;
	if(bgcolor) txt += 'bgcolor="'+bgcolor+'" ';
	if(noscale) txt += 'scale="noscale" salign="'+noscale+'" ';
	if(transparent) txt += 'wmode="transparent" ';
	txt += 'swLiveConnect="true" type="application/x-shockwave-flash "';
	txt += 'pluginspage="//www.macromedia.com/go/getflashplayer" />';
	txt += '</object>';
	document.write(txt);
}

var aAssID = new Array();
var prevIDMap = "";
function fToggleIDMap(id){
	if (!document.getElementById) return;
	if(prevIDMap != ""){
	var po = document.getElementById(prevIDMap);
	aAssID[prevIDMap] = !aAssID[prevIDMap];
	var visState = (aAssID[prevIDMap]) ? 'block' : 'none';
	if(po.style) po = po.style;
	po.display = visState;
	}
	fToggleID(id);
	prevIDMap = id;
}
var prevIDDir = "";
function fToggleIDDir(id){
	if (!document.getElementById) return;
	if(prevIDDir != ""){
		if(prevIDDir == id){
			fToggleID(id);
			prevIDDir = "";
		}else{
			var po = document.getElementById(prevIDDir);
			aAssID[prevIDDir] = !aAssID[prevIDDir];
			var visState = (aAssID[prevIDDir]) ? 'block' : 'none';
			if(po.style) po = po.style;
			po.display = visState;
			fToggleID(id);
			prevIDDir = id;
		}
	}else{
	fToggleID(id);
	prevIDDir = id;
	}
}
var prevIDSummary = "";
function fToggleIDSummary(id){
	if (!document.getElementById) return;
	if(prevIDSummary != ""){
		if(prevIDSummary == id){
			fToggleID(id);
			prevIDSummary = "";
			fToggleOverview();
		}else{
			var po = document.getElementById(prevIDSummary);
			aAssID[prevIDSummary] = !aAssID[prevIDSummary];
			var visState = (aAssID[prevIDSummary]) ? 'block' : 'none';
			if(po.style) po = po.style;
			po.display = visState;
			fToggleID(id);
			prevIDSummary = id;
		}
	}else{
	fToggleID(id);
	prevIDSummary = id;
	fToggleOverview();
	}
}
function fToggleOverview(){
	var o = document.getElementById("iOverview");
	if(o==null) return;
	if(o.style) o = o.style;
	var visState = (o.display == 'none') ? 'block' : 'none';
	o.display = visState;
}

function fToggleID(id){
	if (!document.getElementById) return;
	var o = document.getElementById(id);
	if(o==null) return;
	aAssID[id] = !aAssID[id];
	var visState = (aAssID[id]) ? 'block' : 'none';
	if(o.style) o = o.style;
	o.display = visState;
}


window.onload = function(){
	fInitialiseMenu("iLangM", true);
	fInitialiseMenuArc("rptYears__ctl", false);

	fInitSuckerFish();

}
var currentMenu = null, mytimer = null, timerOn = false;
function fInitialiseMenu(idStr, move) { if(!W3CDOM) return;
	for(var ni=1; document.getElementById(idStr+ni); ni++){
		var menuStr = idStr+ni;
		var menuIStr = idStr+"I"+ni;
		var menu = document.getElementById(menuStr);
		var menuI = document.getElementById(menuIStr);
		menu._name = menuStr;
		menuI._myMenu = menu;
		if(menu == null || menuI == null) return;
		if(menu["childNodes"]==null) return;
		var node;
		for(var i=0; i<menu.childNodes.length; i++) {
			if(menu.childNodes[i].childNodes.length<1) continue;
			node = menu.childNodes[i].childNodes[0];
			if(node.nodeName.toLowerCase()!="a") continue;
			node.onfocus=function() { stopTime(); }
			node.onblur=function() { menu.hideMenu(); }
		}
		currentMenu = menu;
		menuI.onmouseover = function(){ if(currentMenu){ currentMenu.style.visibility = "hidden"; currentMenu = null;
			this.showMenu(); stopTime(); }	}
		menu.onmouseover = function(){ if(currentMenu){ currentMenu.style.visibility = "hidden"; currentMenu = null;
			this.showMenu(); }	}
		menuI.showMenu = function(){
			if(move) this._myMenu.style.left = this.offsetLeft+"px";
			this._myMenu.style.visibility = "visible"; currentMenu = this._myMenu; fHideShowSelectBox(true);	}
		menuI.onfocus	 = function(){ this.onmouseover(); }
		menuI.onblur	 = function(){ this.onmouseout(); }
		menu.showMenu = function(){ this.style.visibility = "visible"; currentMenu = this; stopTime(); }
		menu.hideMenu = function(){
			if (!timerOn) { mytimer = setTimeout("killMenu('" + this._name + "');", 400); timerOn = true; } }
		menu.onmouseout = function(){ this.hideMenu(); }
		menuI.onmouseout = function(){ this._myMenu.hideMenu(); }
	}
}
/*News Archive Menu*/
var currentMenuArc = null;
function fInitialiseMenuArc(idStr, move) { if(!W3CDOM) return;
	for(var ni=1; document.getElementById(idStr+ni+"_lnkYear"); ni++){
		var menuIStr = idStr+ni+"_lnkYear";
		var menuStr = idStr+ni+"_lnkYearChild";
		var menu = document.getElementById(menuStr);
		var menuI = document.getElementById(menuIStr);
		menu._name = menuStr;
		menuI._myMenu = menu;
		if(menu == null || menuI == null) return;
		if(menu["childNodes"]==null) return;
		var node;
		for(var i=0; i<menu.childNodes.length; i++) {
			if(menu.childNodes[i].childNodes.length<1) continue;
			node = menu.childNodes[i].childNodes[0];
			if(node.nodeName.toLowerCase()!="a") continue;
			node.onfocus=function() { stopTime(); }
			node.onblur=function() { menu.hideMenu(); }
		}
		currentMenuArc = menu;
		menuI.onmouseover = function(){ if(currentMenuArc){ currentMenuArc.style.visibility = "hidden"; currentMenuArc = null;
			this.showMenu(); stopTime(); }	}
		menu.onmouseover = function(){ if(currentMenuArc){ currentMenuArc.style.visibility = "hidden"; currentMenuArc = null;
			this.showMenu(); }	}
		menuI.showMenu = function(){
			if(move) this._myMenu.style.left = this.offsetLeft+"px";
			this._myMenu.style.visibility = "visible"; currentMenuArc = this._myMenu; fHideShowSelectBox(true);	}
		menuI.onfocus	 = function(){ this.onmouseover(); }
		menuI.onblur	 = function(){ this.onmouseout(); }
		menu.showMenu = function(){ this.style.visibility = "visible"; currentMenuArc = this; stopTime(); }
		menu.hideMenu = function(){
			if (!timerOn) { mytimer = setTimeout("killMenu('" + this._name + "');", 400); timerOn = true; } }
		menu.onmouseout = function(){ this.hideMenu(); }
		menuI.onmouseout = function(){ this._myMenu.hideMenu(); }
	}
}
function killMenu(id) { if(!W3CDOM) return; id = document.getElementById(id); id.style.visibility = "hidden"; stopTime(); fHideShowSelectBox(false); }
function stopTime(){ if(mytimer){ clearTimeout(mytimer); mytimer = null; timerOn = false; } }

function fHideShowSelectBox(show){
	if(!document.forms["frmOrder"]) return; if(!document.forms.frmOrder["frmPack"]) return;
	var myForm = document.forms.frmOrder;
	myForm.frmPackTXT.value = myForm.frmPack.options[myForm.frmPack.selectedIndex].text;
	fApplyStyle(myForm.frmPack, "display", ((!show) ? "block" : "none"));
	fApplyStyle(myForm.frmPackTXT, "display", ((show) ? "block" : "none"));
}
function sfMouseEvents(sfEls) {
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onfocus = function() { this.className += " hover"; }
		sfEls[i].onblur = function() { this.className = this.className.replace(new RegExp(" hover\\b"), ""); }
		sfEls[i].onmouseover = function() { this.className += " hover"; }
		sfEls[i].onmouseout = function() { this.className = this.className.replace(new RegExp(" hover\\b"), ""); }
	}
}

fInitSuckerFish = function(){
	if(!document.getElementById("iNavArchive")) return;
	sfMouseEvents(document.getElementById("iNavArchive").getElementsByTagName("LI"));
}

function fGetRoot(){
	if (!document.getElementById) document.getElementById = function() { return "/"; }
	var l = document.getElementById("iPathFinder");
	if(!l||!l.href) return "/";
	l = String(l.href);
	l = l.substring(0, l.indexOf("_assets/"));
	return l;
}

//window.attachEvent("onload", fInitSuckerFish);
function getElementsByCondition(condition,container){	container = container || document; var all = container.all || container.getElementsByTagName('*'); var arr = new Array(); var e; for(var k=0; k<all.length; k++){ e = all[k]; if(condition(e,k)) arr[arr.length] = e; } return arr; }
function fImgSwap(id, src){	var e = document.getElementById(id); if(e==null) return; e.src = src; }
function fApplyStyle(id, style, prop){ var e = (typeof(id)=="string")?document.getElementById(id):id; if(e==null) return; if(e.style) e = e.style; e[style] = prop; }
function fInitALinks() { var n = document.getElementsByTagName("A"); if(n==null) return; for (var i=0; i<n.length; i++) { fAddEvent(n[i], "focus", fALinkFocus); fAddEvent(n[i], "blur", fALinkBlur); } }
function fALinkFocus(e){ if(!e) var e = window.event; e = (e.target) ? e.target : e.srcElement; e.className = " focus"; }
function fALinkBlur(e){	if(!e) var e = window.event; e = (e.target) ? e.target : e.srcElement; e.className = e.className.replace(new RegExp(" focus\\b"), ""); }
function fAddEvent(obj, evType, fn){ if(obj.addEventListener){ obj.addEventListener(evType, fn, false); return true; } else if(obj.attachEvent){ var r = obj.attachEvent("on"+evType, fn); return r; } else return false; }
if(!Array.prototype.pop) {
	function array_pop(){ lastElement = this[this.length-1]; this.length = Math.max(this.length-1,0); return lastElement;	}
	Array.prototype.pop = array_pop;
}
function fGetFlashWModeOK(){return (navigator.platform.toLowerCase().indexOf("win")>-1)&&(navigator.appVersion.toLowerCase().indexOf('msie')>-1);}
function fGetFlashVersion(){var latestV=8;flVersion=0;var agent=navigator.userAgent.toLowerCase();if(agent.indexOf("mozilla/3")!=-1&&agent.indexOf("msie")==-1){flVersion=0;}if(navigator.plugins!=null&&navigator.plugins.length>0){var flashPlugin=navigator.plugins['Shockwave Flash'];if(typeof flashPlugin=='object'){for(var i=latestV;i>=3;i--){if(flashPlugin.description.indexOf(i+'.')!=-1){flVersion=i;break;}}}}else if(agent.indexOf("msie")!=-1&&parseInt(navigator.appVersion)>=4&&agent.indexOf("win")!=-1&&agent.indexOf("16bit")==-1){var doc='<scr'+'ipt language="VBScript"\> \n';doc+='On Error Resume Next \n';doc+='Dim obFlash \n';doc+='For i = '+latestV+' To 3 Step -1 \n';doc+='   Set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash." & i) \n';doc+='   If IsObject(obFlash) Then \n';doc+='      flVersion = i \n';doc+='      Exit For \n';doc+='   End If \n';doc+='Next \n';doc+='</scr'+'ipt\> \n';document.write(doc);}else if(agent.indexOf("webtv/2.5")!=-1)flVersion=3;else if(agent.indexOf("webtv")!=-1)flVersion=2;else{flVersion=-1;}return flVersion;}
