/*        __//__ __ .____________________________________________
         /_///_//_///_                  /  v2.02  /  (c) 2010+  /
    _____________/                                           
  */
	/* onLoad / onResize / onScroll
	   ---- Use eg. ----
	   dlLoad.add(function() { alert("example"); });
	   -------------
	*/
	var cVersion = "2.02";
	function dlVersion (type) {
		if (type == undefined)
			alert("Version "+cVersion);
		else 
			return "Version "+cVersion;
	}
	dlLoad = {
		add:function(func) {
			var wLoad = window.onload;
			if (typeof window.onload != 'function') {
				window.onload = function() { func(); }
			} else {
				window.onload = function() { wLoad(); func(); }
			}
		}
	};
	dlResize = {
		add:function(func) {
			var wResize = window.onresize;
			if (typeof window.onresize != 'function') {
				window.onresize = function() { func(); }
			} else {
				window.onresize = function() { wResize(); func(); }
			}
		}
	};
	dlScroll = {
		add:function(func) {
			var wScroll = window.onscroll;
			if (typeof window.onscroll != 'function') {
				window.onscroll = function() { func(); }
			} else {
				window.onscroll = function() { wScroll(); func(); }
			}
		}
	};
	var hiddenSWF = null;   // Used to hide SWF through function hideSWF();
	var oScreen = { oW:0, oH:0, cW:0, cH:0, sW:0, setup:function() {
		this.oW = document.body.offsetWidth;
		this.oH = document.body.offsetHeight;
		if (document.documentElement && (document.documentElement.clientWidth != 0)) {
			this.cW = document.documentElement.clientWidth;
			this.cH = document.documentElement.clientHeight;
		} else {
			this.cW = document.body.clientWidth;
			this.cH = document.body.clientHeight;
		}
		if( typeof( window.pageYOffset ) == "number") {
			this.sT = window.pageYOffset;
		} else if (document.body.scrollTop) {
			this.sT = document.body.scrollTop;
		} else if (document.documentElement) {
			this.sT = document.documentElement.scrollTop;
		}
		if (document.body.scrollWidth) {
			this.oW = (document.body.scrollWidth>this.oW)?document.body.scrollWidth:this.oW;
		}
		if (document.body.scrollHeight) {
			this.oH = (document.body.scrollHeight>this.oH)?document.body.scrollHeight:this.oH;
		}
	}};
	function getObj(name) {
		return document.getElementById(name);
	}
	function dlTabInitialise() {
		var obj = document.getElementById("tabContainer");
		var liNodes = obj.getElementsByTagName("LI");
		var aTags = [];
		for (var i=0; i<liNodes.length; i++) {
			if (liNodes[i].tagName == "LI") {
				var aNodes = liNodes[i].getElementsByTagName("A");
				for (var j=0; j<aNodes.length; j++) {
					if (aNodes[j].tagName == "A") {
						aTags[aTags.length] = aNodes[j];
						//aNodes[j].className = (aNodes[j].className == "")?"tabItem":"tabItem "+aNodes[j].className;
						aNodes[j].onclick = function() { return dlTabToggle(this); };
						aNodes[j].innerHTML = "<span>" + aNodes[j].innerHTML + "</span>";
						break;
					}
				}
			}
		}	
		var nodeItem = 0;
		for (var i=0; i<liNodes.length; i++) {
			if (liNodes[i].tagName == "LI") {
				var divNodes = liNodes[i].getElementsByTagName("DIV");
				for (var j=0; j<divNodes.length; j++) {
					if (divNodes[j].tagName == "DIV") {
						divNodes[j].id = getTabname(aTags[nodeItem].href);
						divNodes[j].className = (aTags[nodeItem].className.indexOf("selected") == -1)?divNodes[j].className:divNodes[j].className+" selected";
						//-- Resize --
						/*
						if (aTags[nodeItem].className.indexOf("selected") != -1) {
							document.getElementById("tabContainer").style.height = (divNodes[j].clientHeight+aTags[nodeItem].clientHeight)+"px";
						}
						*/
						nodeItem++;
						break;
					}
				}
			}
		}
	}
	function dlTabToggle(item) {
		clickedTab = getTabname(item.href);
		var obj = document.getElementById("tabContainer");
		var nodes = obj.getElementsByTagName("A");
		for (var i=0; i<nodes.length; i++) {
			if (nodes[i].tagName == "A") {
				itemTab = getTabname(nodes[i].href);
				oTab = document.getElementById(itemTab);
				if (itemTab != clickedTab) {
					if (nodes[i].className == "tabItem selected") {
						nodes[i].className = "tabItem";
						oTab.className = oTab.className.replace(" selected","");
					}
				} else {
						nodes[i].className = "tabItem selected";
						if (oTab.className.indexOf(" selected") == -1)
							oTab.className = oTab.className + " selected";
						//-- Resize --
						//document.getElementById("tabContainer").style.height = (oTab.clientHeight+nodes[i].clientHeight)+"px";
				}
			}
		}
		return false;
	}
	function getTabname(sHref) {
		return (sHref.substring(sHref.indexOf("#")+1,sHref.length));
	}
	/* SWF Mask */
	var oMask = new objNode("mask",'',0,0,0,0);
	var oFlash = null;
	
	function getLocation(fullLoc) {
		if (fullLoc != undefined) {
			splitLoc = fullLoc.split("/");
			splitLoc[splitLoc.length-1] = "";
			return splitLoc.join("/");
		} else {
			return "";
		}
	}
	function getTranscript(trans) {
		trans = (trans == undefined)?"":trans;
		return trans
	}
	
	function objNode(name, swf, flv, jpg, x, y, w, h, fw, fh, trans, title) {
		this.name = name;
		this.show = false;
		this.filename = swf;
		this.flashvars = {
			swf:flv,
			jpg:jpg,
			loc:getLocation(this.filename),
			trans:trans,
			defaultVideo:flv,
			defaultVideoTitle:title
		};
		this.obj = function() {
			return document.getElementById(this.name) 
		};
		this.x = x;
		this.y = y;
		this.w = w;
		this.h = h;
		this.setup = function (x,y,w,h) {
			this.x = (x == null)?this.x:x;
			this.y = (y == null)?this.y:y;
			this.w = (w == null)?this.w:w;
			this.h = (h == null)?this.h:h;
			if (x != null) this.obj().style.left = this.x + "px";
			if (y != null) this.obj().style.top = this.y + "px";
			if (w != null) this.obj().style.width = this.w + "px";
			if (h != null) this.obj().style.height = this.h + "px";
		};
		this.flash = { w:fw, h:fh };
	}

	var storeW = 0;
	var storeH = 0;
	function toggleMask(description,format,title) {
		// format { swf, flv, jpg, w, h, trans }
		var loadObj = document.getElementById("loader");
		var objContainer = document.getElementById("dynamicContent");
		objContainer.innerHTML = "<div id='loadDiv'></div>";
		var obj = document.getElementById("loadDiv");
		var videoTitle = document.getElementById("videoTitle");
		var longDesc = document.getElementById("longDesc");
		oScreen.setup();
		if (typeof description != "object") {
			if (format != null) {
				format.trans = (format.trans == undefined)?"":format.trans;
				oFlash = new objNode("flashObj",format.swf,format.flv,format.jpg,0,0,format.w+10,format.h+70,format.w,format.h,format.trans,description);
				if (typeof format.longDesc != "undefined") {
					longDesc.longdesc = format.longDesc;
				}
			} else {
				oFlash = new objNode("flashObj");
			}
			if (!oMask.show) {
				storeW = format.w;
				storeH = format.h;
				if(format.trans!=undefined && format.trans!="") {
					obj.style.width = storeW+"px";
					obj.style.height = storeH+"px";
					obj.style.color = "#333333";
					obj.style.backgroundColor = "#FFFFFF";
					obj.innerHTML = "<div style='margin:5px;overflow:scroll;height:"+((storeH-10)+"px")+"'>"+format.trans+"</div>";
					obj.style.height = storeH+"px";
				}
				if (oFlash.filename != "" && oFlash.flashvars.swf != "") {
					swfobject.embedSWF(oFlash.filename, "loadDiv", format.w, format.h, "9.0.0", false, oFlash.flashvars, { wmode:"transparent" }, {});
				}
				if (title != true) videoTitle.style.display = "none";
				videoTitle.style.width = (format.w - 14)+"px";
				videoTitle.innerHTML = description;
				var xClose = document.getElementById("xClose");
				if (xClose!=undefined) {
					xClose.style.left = (format.w + 14 - 80)+"px";
				}
				document.getElementById("maskFlashContainer").style.width = oFlash.w+"px";
				oMask.show = true;
				oMask.setup(null,null,oScreen.oW,oScreen.oH);
				oFlash.setup((oScreen.cW-oFlash.w)/2,((oScreen.cH-oFlash.h)/2)+oScreen.sT,null,null);
				oMask.obj().style.display = "block";
				oFlash.obj().style.display = "block";
				objContainer.style.display = "block";
				oFlash.obj().focus();
			} else {
				if (hiddenSWF != null) {
					hiddenSWF.style.visibility = "visible";
					hiddenSWF = null;
				}
				oMask.show = false;
				oMask.obj().style.display = "none";
				oFlash.obj().style.display = "none";
				storeW = (storeW == 0)?320:storeW;
				storeH = (storeH == 0)?240:storeH;
				swfobject.embedSWF("/Portals/0/content/swf/blank.swf", "loadDiv", storeW, storeH, "9.0.0", false, {}, { wmode:"transparent" }, {});
			}
		} else {
			if (!oMask.show) {	
				format.trans = (format.trans == undefined)?"":format.trans;
				oFlash = new objNode("flashObj",format.swf,format.flv,format.jpg,0,0,format.w+10,format.h+70,format.w,format.h,format.trans);
				if (typeof format.longDesc != "undefined") {
					longDesc.longdesc = format.longDesc;
				}
				videoTitle.style.width = (oFlash.w - 10)+"px";
				videoTitle.style.height = (format.h - 12)+"px";
				var xClose = document.getElementById("xClose");
				if (xClose!=undefined) {
					xClose.style.left = (format.w + 14 - 80)+"px";
				}
				var formatDesc = "<span class='transcriptHeader'>Transcript : "+description[0]+"</span><br/><br/>";
				for (i=1; i<description.length; i++) {
					formatDesc = formatDesc + description[i]+"<br/><br/>"
				}
				if (title != true) videoTitle.style.display = "none";
				videoTitle.innerHTML = formatDesc;
				objContainer.style.display = "none";
				oMask.show = true;
				oMask.setup(null,null,oScreen.oW,oScreen.oH);
				oFlash.setup((oScreen.cW-oFlash.w)/2,((oScreen.cH-oFlash.h)/2)+oScreen.sT,null,null);
				oMask.obj().style.display = "block";
				oFlash.obj().style.display = "block";
				oFlash.obj().style.width = (format.w + 14)+"px";
				oFlash.obj().style.backgroundColor = "#FFFFFF";
				oFlash.obj().style.color = "#000000";
				oFlash.obj().focus();
			} else {
				if (hiddenSWF != null) {
					hiddenSWF.style.visibility = "visible";
					hiddenSWF = null;
				}
				oMask.show = false;
				oMask.obj().style.display = "none";
				obj.style.display = "none";
			}
		}
	}

	dlResize.add(
		function() {
			if (oMask.show) {
				oScreen.setup();
				if ((oFlash.x != ((oScreen.cW-oFlash.w)/2)) || (oFlash.y != ((oScreen.cH-oFlash.h)/2))) {
					oFlash.setup((oScreen.cW-oFlash.w)/2,((oScreen.cH-oFlash.h)/2)+oScreen.sT,null,null);
				}
				if (document.documentElement.scrollWidth) {
					oScreen.oW = document.documentElement.scrollWidth;
				}
				if ((oMask.w != oScreen.oW) || (oMask.h != oScreen.oH)) {
					oMask.setup(null,null,oScreen.oW,oScreen.oH);
				}
			}
		}
	);
	dlScroll.add(
		function() {
			if (oFlash != null && oMask.show) {
				oScreen.setup();
				oFlash.setup((oScreen.cW-oFlash.w)/2,((oScreen.cH-oFlash.h)/2)+oScreen.sT,null,null);
			}
		}
	);

	/*
			=== AJAX ===
	*/
	var xmlHTTP;
	var requestType = "";
	var oLoadData = null;
	
	var displayType = "flash";
	
	function createXMLHttpRequest() {
		if (window.ActiveXObject) {
			xmlHTTP = new ActiveXObject("Microsoft.XMLHTTP");
		} else if (window.XMLHttpRequest) {
			xmlHTTP = new XMLHttpRequest();
		}
	}

	function startRequest(oLoadInfo) {
		oLoadData = oLoadInfo;
		createXMLHttpRequest();
		xmlHTTP.onreadystatechange = handleStateChange;
		xmlHTTP.open("GET", oLoadData.file+"?ts="+new Date().getTime(), true);
		xmlHTTP.send(null);
	}
	
	function handleStateChange() {
		if (xmlHTTP.readyState == 4) {
			if (xmlHTTP.status == 0) {
				alert("Server script required!");
			}
			if (xmlHTTP.status == 200) {
				xmlOutput();
			}
			if (xmlHTTP.status == 404) {
				alert("Load error!");
			}
		}
	}
	
	function xmlOutput() {
		var xmlDoc = xmlHTTP.responseXML;
		var xmlData = xmlDoc.getElementsByTagName(oLoadData.item)[0];
		displayMask(xmlData);
	}

	function displayMask(xmlData) {
		var oXml = {
			swf : xmlData.getElementsByTagName("swf")[0].childNodes[0].nodeValue,
			flv : xmlData.getElementsByTagName("flv")[0].childNodes[0].nodeValue,
			jpg : xmlData.getElementsByTagName("jpg")[0].childNodes[0].nodeValue,
			w : parseInt(xmlData.getElementsByTagName("swf")[0].getAttribute("width"),10),
			h : parseInt(xmlData.getElementsByTagName("swf")[0].getAttribute("height"),10),
			trans : xmlData.getElementsByTagName("trans")[0].childNodes[0].nodeValue
		}
		if (oLoadData.trans) {
			oXml.swf = "";
			oXml.flv = "";
		}
		var desc = xmlData.getElementsByTagName("desc")[0].childNodes[0].nodeValue;
		toggleMask(desc,oXml);
	}
	function hideSWF(name) {
		hiddenSWF = getObj(name);
		hiddenSWF.style.visibility = "hidden";
	}
