var openDivAction;
var setNavAction;
var directGo;
var divIsOpen = false;
window.name = 'brandHKFrame';


function init()
{
	directGo = setIFrameAddress();//Check DirectGo
	
	openDivAction = new setOpenDiv();
	setNavAction = new setNav();
	
	setTime();
	new setWeather();
	initLightbox();
	searchControl();
	new corpVidTab();
}

function getFlashMovie(movieName)
{
	return (isIE) ? window[movieName] : document[movieName];
} 

function setOpenDiv()
{
	var mainDiv = d.getElementById('mainDiv');
	//var mainContent = d.getElementById('mainContent');
	var shadowL = d.getElementById('shadowL');
	var flashContainer = d.getElementById('flashContainer');
	var mainNav = d.getElementById('mainNav');
	var homeDetails = d.getElementById('homeDetails');
	var mask = d.getElementById('mask');
	var divArray = new Array(shadowL, flashContainer, mainNav, homeDetails, mask);
	var minW = flashContainer.offsetWidth;
	var maxW = 900;
	//var nav = mainNav.getElementsByTagName('a')[0];
	var flash;
	var offsetW;
	var self = this;
	
	mainDiv.minW = mainDiv.offsetWidth;
	mainDiv.maxW = mainDiv.minW + maxW - minW;
	mask.minW = mask.offsetWidth;
	mask.maxW = mask.minW + maxW - minW;
	
	this.init = function()
	{
		var tempX = 0;
		var tempW = 0;
		var offsetW = mask.offsetWidth;
		
		mainDiv.initW = mainDiv.offsetWidth;
		mainDiv.endL = 0;
		//mainContent.initL = 0;
		homeDetails.initW = homeDetails.offsetWidth;
		homeDetails.endW = 0;
		
		for (var i=0; i<divArray.length; i++)
		{
			if (divArray[i].initW != null)	tempW += homeDetails.initW;
		}
		offsetW -= tempW;
		
		for (var i=0; i<divArray.length; i++)
		{
			if (divArray[i].initW != null)	tempX += homeDetails.initW;
			divArray[i].initL = divArray[i].offsetLeft;
			divArray[i].endL = divArray[i].initL - offsetW - tempX;
		}
		
		//Center Div
		self.centerDiv();
		window.onresize = function() {self.centerDiv();};
		
		/*nav.onclick = function()
		{
			self.divOpenAction(!divIsOpen);
		};*/
		
		if (directGo)	this.divOpen(true, directGo);
		this.genSWF(directGo);
	};
	
	this.genSWF = function(directGo)
	{
		var flashvars = {xmlPath:"xml/", swfPath:"swf/", autoStart:((directGo)?"false":"true")};
		var params = {salign:"TL", wmode:"opaque"};
		var attributes = {name:"flash", id:"flash"};
		swfobject.embedSWF("swf/index.swf", "flash", "100%", "600", "10.0.0", "", flashvars, params, attributes);
	};
	
	this.centerDiv = function()
	{
		var w = d.body.clientWidth;
		offsetW = ((w > mainDiv.maxW)?	mainDiv.maxW:w) - mainDiv.minW;//Resize Flash
		if (offsetW < 0)	offsetW = 0;
		
		mainDiv.style.width = mainDiv.initW + offsetW + 'px';
		//mainContent.style.width = mainDiv.initW + offsetW + 'px';
		
		if (!divIsOpen)
		{
			flashContainer.style.width = (minW + offsetW) + 'px';
			if (flashContainer.offsetWidth < minW)	flashContainer.style.width = minW + 'px';
			
			for (var i=0; i<divArray.length; i++)
			{
				if (i > 1)	divArray[i].style.left = divArray[i].initL + offsetW + 'px';
			}
		}
		else
		{
			mask.style.width = (mask.minW + offsetW) + 'px';
		}
		
		mainDiv.style.left = Math.round((w - mainDiv.offsetWidth)/2) + 'px';
		if (mainDiv.offsetLeft < 0)	mainDiv.style.left = 0;
	};
	
	this.divOpenAction = function(isOpen)
	{
		if (divIsOpen == isOpen)	return;
		
		flash = getFlashMovie('flash');
		flash.sendTextToFlash(!isOpen);
		
		setTimeout(function(){self.divOpen(isOpen);}, 50);
	};
	
	this.divOpen = function(isOpen, directGo)
	{
		if (!isOpen)
		{
			mainDiv.L = mainDiv.initL - offsetW/2;
			mainDiv.W = mainDiv.initW + offsetW;
			flashContainer.style.width = (minW + offsetW) + 'px';
		}
		else
		{
			mask.style.width = (mask.minW + offsetW) + 'px';
		}
		
		for (var i=0; i<divArray.length; i++)
		{
			if (divArray[i].endL != null)	divArray[i].L = (isOpen)?	divArray[i].endL:divArray[i].initL;
			if (divArray[i].endW != null)	divArray[i].W = (isOpen)?	divArray[i].endW:divArray[i].initW;
			
			if (isOpen && i <= 1)	divArray[i].L = divArray[i].endL - offsetW;
			if (!isOpen && i > 1)	divArray[i].L = divArray[i].initL + offsetW;
			
			if (i == 0)	divArray[i].L = 0;
			
			new self.motion(divArray[i], directGo, 4);
		}
	
		divIsOpen = isOpen;
		
		//nav.getElementsByTagName('img')[0].src = (isOpen)?	'images/nav_open.gif':'images/nav.gif';
	};
	
	this.motion = function(obj, start, sp)
	{
		var LReady = true;
		var WReady = true;
		var selfMotion = this;
		obj.style.display = 'block';
		
		if (start)
		{
			if (obj.L != null)	obj.style.left = obj.L + 'px';
			if (obj.W != null)	obj.style.width = obj.W + 'px';
			if (obj.action)	obj.action();
			if (obj.W == 0)	obj.style.display = 'none';
			return;
		}
		
		if (obj.L != null)
		{
			obj.objL = obj.offsetLeft;
			obj.goStepL = (obj.L - obj.objL)/sp;
			if (obj.goStepL > 0)	obj.goStepL = Math.ceil(obj.goStepL);
			if (obj.goStepL < 0)	obj.goStepL = Math.floor(obj.goStepL);
			
			if (!(Math.abs(obj.objL - obj.L) < 1))
			{
				obj.objL += obj.goStepL;
				LReady = false;
			}
			else
			{
				obj.objL = obj.L;
				LReady = true;
			}
			
			obj.style.left = obj.objL + 'px';
		}
		
		if (obj.W != null)
		{
			obj.objW = obj.offsetWidth;
			obj.goStepW = (obj.W - obj.objW)/sp;
			if (obj.goStepW > 0)	obj.goStepW = Math.ceil(obj.goStepW);
			if (obj.goStepW < 0)	obj.goStepW = Math.floor(obj.goStepW);
			
			if (!(Math.abs(obj.objW - obj.W) < 30))
			{
				obj.objW += obj.goStepW;
				WReady = false;
			}
			else
			{
				obj.objW = obj.W;
				WReady = true;
			}
			
			obj.style.width = obj.objW + 'px';
		}
		
		if (LReady && WReady)
		{
			if (obj.objW == 0)	obj.style.display = 'none';
			clearTimeout(obj.timeOut);
			if (obj.action)	obj.action();
		}
		else
		{
			obj.timeOut = setTimeout(function(){self.motion(obj, start, sp);}, 10);
		}
	};
	
	this.init();
}

function setIFrameAddress()
{
	var mainIFrame = d.getElementById('mainIFrame');
	var hash = location.hash;
	if (hash == '')	return false;
	if (hash == '#/en/')	hash = '#/';
	
	var url = hash.replace('#', '');
	if (url == '/')	return false;
	
	mainIFrame.src = url;
	return true;
}

function setNav()
{
	var mainNav = d.getElementById('mainNav');
	var nav = getElementsByClassName(mainNav, 'nav')[0];
	var mainIFrame = d.getElementById('mainIFrame');
	var li = setChildNodes(nav, 'LI');
	var navList = new Array();
	var highlightNav;
	var highlightSubNav;
	
	var self = this;
	
	this.init = function()
	{
		for (var i=0; i<li.length; i++)
		{
			var a = li[i].getElementsByTagName('a')[0];
			a.section = a.className;
			a.url = a.href;
			if (a.target == 'mainIFrame')	a.href = 'javascript:;';
			a.navList = new Array();
			navList.push({id:a.section, btn:a});
			
			a.onclick = function()
			{
				//if (this == highlightNav)	return;
				//if (this.className.indexOf(' active') >= 0)	return;
				
				if (this.section == 'home')
				{
					openDivAction.divOpenAction(false);
				}
				else
				{
					openDivAction.divOpenAction(true);
				}
				
				var url = this.url;
				setTimeout(function(){mainIFrame.src = url;}, ((divIsOpen)?700:0));
				
				self.changeNav(this);
			}
			
			if (li[i].getElementsByTagName('ul').length > 0)	this.setSubNav(li[i], a);
		};
		this.navList = navList;
		
		var logo = d.getElementById('logo');
		logo.onclick = function()
		{
			openDivAction.divOpenAction(false);
			self.changeNav(navList[0].btn);
		}
		
		//Check Level
		if (!directGo)
		{
			this.changeNav(navList[0].btn);
		}
		else
		{
			var btn;
			for (var i=0; i<levelArray.length; i++)
			{
				if (i > 1)	break;
				if (i == 0)
				{
					for (var j=0; j<navList.length; j++)
					{
						if (levelArray[i] != navList[j].id)	continue;
						btn = navList[j].btn;
						if (levelArray.length == 1)	self.changeNav(btn, true);
						break;
					}
				}
				else if (i == 1)
				{
					if (!btn)	break;
					for (var j=0; j<btn.navList.length; j++)
					{
						if (levelArray[i] != btn.navList[j].id)	continue;
						self.changeNav(btn, true, true);
						self.changeSubNav(btn.navList[j].btn, true);
						break;
					}
				}
			}
		}
		
		this.setBotLink();
	};
	
	this.setBotLink = function()
	{
		var container = d.getElementById('shadowB');
		var a = container.getElementsByTagName('a');
		
		for (var i=0; i<a.length; i++)
		{
			if (!a[i].parentNode.getElementsByTagName('strong')[0])	continue;
			var btn = a[i].parentNode.getElementsByTagName('strong')[0];
			
			a[i].navID = btn.className;
			a[i].subNavID = a[i].className;
			a[i].url = a[i].href;
			if (a[i].target == 'mainIFrame')	a[i].href = 'javascript:;';
			a[i].onclick = function()
			{
				goSection(this.navID, this.subNavID);
				
				/*//changeTopHash(this);
				if (this.btn)		self.changeNav(this.btn, false, true, true);
				if (this.subBtn)	self.changeSubNav(this.subBtn);
				openDivAction.divOpenAction(true);
				
				var url = this.url;
				setTimeout(function(){mainIFrame.src = url;}, ((divIsOpen)?700:0));*/
			}
		}
	};
	
	this.changeNav = function(btn, start, notGoSub, notLink)
	{
		if (btn.className.indexOf(' active') < 0)	btn.className += ' active';
		if (btn.menu)	this.openSubNav(btn, true, start, notGoSub);
		
		if (highlightNav && btn != highlightNav)
		{
			highlightNav.className = highlightNav.className.replace(/ active/, '');
			if (highlightNav.menu)	this.openSubNav(highlightNav, false);
		}
		
		highlightNav = btn;
		if (!start && !notLink)	this.changeTopHash(btn);
	};
	
	this.setSubNav = function(container, btn)
	{
		var ul = container.getElementsByTagName('ul')[0];
		btn.initH = ul.offsetHeight;
		btn.endH = ul.scrollHeight;
		btn.menu = ul;
		
		var li = container.getElementsByTagName('li');
		for (var i=0; i<li.length; i++)
		{
			var a = li[i].getElementsByTagName('a')[0];
			a.section = a.className;
			a.url = a.href;
			btn.navList.push({id:a.section, btn:a});
			
			a.onclick = function()
			{
				//if (this == highlightSubNav)	return;
				//if (this.className.indexOf(' active') >= 0)	return;
				self.changeSubNav(this);
				openDivAction.divOpenAction(true);
			}
		};
	};
	
	this.changeSubNav = function(btn, notGoSub, url)
	{
		if (btn.className.indexOf(' active') < 0)	btn.className += ' active';
		if (highlightSubNav && btn != highlightSubNav)	highlightSubNav.className = highlightSubNav.className.replace(/ active/, '');
		highlightSubNav = btn;
		
		if (!notGoSub)	this.changeTopHash(btn, url);
	};
	
	this.openSubNav = function(btn, isOpen, start, notGoSub)
	{
		btn.menu.H = (isOpen)?	btn.endH:btn.initH;
		this.motion(btn.menu, start, 4);
		
		if (isOpen)	this.changeSubNav(btn.navList[0].btn, notGoSub);
	};

	this.changeTopHash = function(btn, link)
	{
		if (!btn.url)	return;
		//if (btn.url.indexOf('javascript:') >= 0)	return;
		
		var url = (link)?	link:btn.url;
		var array = url.split('/');
		if (array[0] == 'http:')
		{
			array.shift();
			array.shift();
		}
		array.shift();
		var path = array.join('/');
		var topUrl = top.location.href.replace(top.location.hash, '');
		
		top.location.href = topUrl + '#/' + path;
	};
	
	this.motion = function(obj, start, sp)
	{
		var LReady = true;
		var HReady = true;
		var selfMotion = this;
		
		if (start)
		{
			if (obj.L != null)	obj.style.left = obj.L + 'px';
			if (obj.H != null)	obj.style.height = obj.H + 'px';
			if (obj.action)	obj.action();
			return;
		}
		
		if (obj.L != null)
		{
			obj.objL = obj.offsetLeft;
			obj.goStepL = (obj.L - obj.objL)/sp;
			if (obj.goStepL > 0)	obj.goStepL = Math.ceil(obj.goStepL);
			if (obj.goStepL < 0)	obj.goStepL = Math.floor(obj.goStepL);
			
			if (!(Math.abs(obj.objL - obj.L) < 1))
			{
				obj.objL += obj.goStepL;
				LReady = false;
			}
			else
			{
				obj.objL = obj.L;
				LReady = true;
			}
			
			obj.style.left = obj.objL + 'px';
		}
		
		if (obj.H != null)
		{
			obj.objH = obj.offsetHeight;
			obj.goStepH = (obj.H - obj.objH)/sp;
			if (obj.goStepH > 0)	obj.goStepH = Math.ceil(obj.goStepH);
			if (obj.goStepH < 0)	obj.goStepH = Math.floor(obj.goStepH);
			
			if (!(Math.abs(obj.objH - obj.H) < 1))
			{
				obj.objH += obj.goStepH;
				HReady = false;
			}
			else
			{
				obj.objH = obj.H;
				HReady = true;
			}
			
			obj.style.height = obj.objH + 'px';
		}
		
		if (LReady && HReady)
		{
			clearTimeout(obj.timeOut);
			if (obj.action)	obj.action();
		}
		else
		{
			obj.timeOut = setTimeout(function(){self.motion(obj, start, sp);}, 10);
		}
	};
	
	this.init();
}

function goHome()
{
	openDivAction.divOpenAction(false);
	setNavAction.changeNav(setNavAction.navList[0].btn);
}

function goSection(id, subID, link)
{
	var url;
	var btn;
	var subBtn;
	var navList = setNavAction.navList;
	var mainIFrame = d.getElementById('mainIFrame');
			
	for (var j=0; j<navList.length; j++)
	{
		if (navList[j].id == id)
		{
			btn = navList[j].btn;
			for (var k=0; k<btn.navList.length; k++)
			{
				if (btn.navList[k].id == subID)
				{
					subBtn = btn.navList[k].btn;
					break;
				}
			};
			break;
		}
	};
	
	if (btn)
	{
		setNavAction.changeNav(btn, false, true, true);
		url = btn.url;
		
		if (subBtn)
		{
			setNavAction.changeSubNav(subBtn, false, link);
			url = (link)?	link:subBtn.url;
		}
	}
	
	openDivAction.divOpenAction(true);
	setTimeout(function(){mainIFrame.src = url;}, ((divIsOpen)?700:0));
}

//LightBox
var LightBoxDiv;
var LightBoxFlv;
var fileBottomNavCloseImage = '/en/images/btn_close.gif';

function showLightbox(div, flv, w, h)
{
	var width  = (w)?	w:700;
	var height = (h)?	h:395;
	LightBoxDiv = div;
	LightBoxFlv = flv;
	myLightbox.start('', width, height);
}

function showBox()
{
	var lightboxImage = d.getElementById('lightboxImage');
	lightboxImage.innerHTML = '';
	var div = createDiv(LightBoxDiv.id, LightBoxDiv.className);
	div.innerHTML = LightBoxDiv.innerHTML;
	lightboxImage.appendChild(div);
	//lightboxImage.appendChild(LightBoxDiv);
	//startFading(lightboxImage);
	
	if (LightBoxFlv)
	{
		setTimeout(function()
		{
			var flashvars = {};
			flashvars.swfPath = '/en/swf/SkinUnderAllNoCaption.swf';
			flashvars.flv = LightBoxFlv;
			
			var params = {};
			params.allowscriptaccess = 'always';
			params.allowfullscreen  = 'true';
			params.wmode = 'opaque';
			
			var attributes = {};
			
			swfobject.embedSWF('/en/swf/flvplayer.swf', 'videoSWF', 320, 285, '10.0.0', '', flashvars, params, attributes);
		}, 500);
	}
}

function endBox()
{
	//alert('end');
	/*if (LightBoxFlv)
	{
		if (!d.getElementById('videoSWF'))	return;
		var videoSWF = d.getElementById('videoSWF');
		videoSWF.parentNode.removeChild(videoSWF);
	}*/
	var lightboxImage = d.getElementById('lightboxImage');
	var div = setChildNodes(lightboxImage, 'DIV')[0];
	lightboxImage.removeChild(div);
}

function changeLanguage(newLang)
{
	var array = new Array('en', 'tc', 'sc');
	var lang;
	var url = top.location.href;
	//if (top.location.hash)	url = top.location.href.replace(top.location.hash, '');
	
	for (var i=0; i<array.length; i++)
	{
		if (url.indexOf('/' + array[i] + '/') < 0)	continue;
		lang = array[i];
		break;
	}
	if (!lang)	return;
	
	var urlArray = url.split('/' + array[i] + '/');
	url = urlArray.join('/' + newLang + '/');
	top.location.href = url;
}

/* Share Functions starts */
var currentPath = escape(document.URL);

function shareFacebook()
{
	var currentPath = escape(document.URL);
	var extLink = 'http://www.facebook.com/share.php?u=';
	var pageTitle = escape(d.title);
	window.open(extLink + currentPath + '&t=' + pageTitle);
	//alert(currentPath);
}
function shareMyspace()
{
	var extLink = 'http://www.myspace.com/Modules/PostTo/Pages/?u=';
	var pageTitle = escape(d.title);
	window.open(extLink + currentPath + '&t=' + pageTitle + '&c=%3Ca+href%3D%22' + currentPath + '%22%3E' + pageTitle + '%3C%2Fa%3E');
}

var result;

// wait until page is loaded to call API
BitlyClient.addPageLoadEvent(function(){
	BitlyCB.myShortenCallback = function(data) {
		// this is how to get a result of shortening a single url
		for (var r in data.results) {
			result = data.results[r];
			result['longUrl'] = r;
			break;
		}
		//alert(result['shortUrl']);
	}
	BitlyClient.shorten(document.location, 'BitlyCB.myShortenCallback');
});
	
function shareTwitter()
{
	if (!result)	return;
	var extLink = 'http://twitter.com/home?status=';
	var pageTitle = escape(d.title);
	window.open(extLink + pageTitle + '%3A+' + result['shortUrl']);
}
/* Share Functions ends */

function getServerTime(type)
{
	//get server time
	if (typeof(XMLHttpRequest) == 'undefined')
	{
		XMLHttpRequest = function()
		{
		    try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); }
				catch(e) {}
		    try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); }
				catch(e) {}
		    try { return new ActiveXObject("Msxml2.XMLHTTP"); }
				catch(e) {}
		    try { return new ActiveXObject("Microsoft.XMLHTTP"); }
				catch(e) {}
		    throw new Error("This browser does not support XMLHttpRequest.");
		};
	}

	xmlHttp = new XMLHttpRequest();
	if (!xmlHttp)	return;
	xmlHttp.open('GET', 'time.txt', false);
	xmlHttp.setRequestHeader('Range', 'bytes=-1');
	xmlHttp.send(null);
	
	severtime = new Date(xmlHttp.getResponseHeader('Date'));
	//alert('severtime:  ' + severtime)
	
	//get server date
	var year = severtime.getFullYear();
	var month = severtime.getMonth() + 1;
	var date = severtime.getDate();

	//get server time
	var hour = severtime.getHours();
	var minu = severtime.getMinutes();
	var seco = severtime.getSeconds();
	var time = severtime.getTime();
	
	if (type == 'date')
	{
		return severtime;
	}
	else if (type == 'year')
	{
		return year;
	}
	else
	{
		return time;
	}
}

function setTime()
{
	//if (!getServerTime('date'))	return;
	
	var container = d.getElementById('timeDiv');
	var monthArray = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
	var today = getServerTime('date');
	var year = today.getFullYear();
	var month = monthArray[today.getMonth()];
	var date = today.getDate();
	var hour = today.getHours();
	var min = today.getMinutes();
	
	container.innerHTML = date + ' ' + month + ', ' + year + ' ' + hour + ':' + min + ' HKT';
}

/*--------------
DOMParser for IE and Safari
---------------*/
if (typeof DOMParser == "undefined") {
   DOMParser = function () {}

   DOMParser.prototype.parseFromString = function (str, contentType) {
      if (typeof ActiveXObject != "undefined") {
         var d = new ActiveXObject("MSXML.DomDocument");
         d.loadXML(str);
         return d;
      } else if (typeof XMLHttpRequest != "undefined") {
         var req = new XMLHttpRequest;
         req.open("GET", "data:" + (contentType || "application/xml") +
                         ";charset=utf-8," + encodeURIComponent(str), false);
         if (req.overrideMimeType) {
            req.overrideMimeType(contentType);
         }
         req.send(null);
         return req.responseXML;
      }
   }
}

function loadXML(url)
{
	var x;
	var self = this;
	
	this.action = function()	{};

	if (typeof(XMLHttpRequest) == 'undefined')
	{
		XMLHttpRequest = function()
		{
		    try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); }
				catch(e) {}
		    try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); }
				catch(e) {}
		    try { return new ActiveXObject("Msxml2.XMLHTTP"); }
				catch(e) {}
		    try { return new ActiveXObject("Microsoft.XMLHTTP"); }
				catch(e) {}
		    throw new Error("This browser does not support XMLHttpRequest.");
		};
	}

	x = new XMLHttpRequest();
	if (x.overrideMimeType)	x.overrideMimeType('text/xml');
	
	if (x)
	{
		x.onreadystatechange = function()
		{
			if (x.readyState == 4 && x.status == 200)
			{
				self.action(x);
			}
		}
		x.open('GET', url, true);
		x.send(null);
	}
}

function getChildNodes(xml)
{
	var obj = new Object();
	
	for (var i=0; i<xml.length; i++)
	{
		if (!isIE)	if (xml[i].toString() == '[object Text]')	continue;
		var name = xml[i].nodeName.toString();
		var value = (xml[i].firstChild)	?	xml[i].firstChild.data.toString()	:	'';
		obj[name] = value;
	}
	
	return obj;
}

function getAttributes(xml)
{
	var obj = new Object();
	
	for (var i=0; i<xml.attributes.length; i++)
	{
		obj[xml.attributes[i].name.toString()] = xml.attributes[i].value.toString();
	}
	
	return obj;
}

function setWeather()
{
	var temperature = d.getElementById('temperature');
	var humidity = d.getElementById('humidity');
	var self = this;
	
	this.init = function()
	{
		var xml = new loadXML('/en/jsp/getweather.jsp?source=brandhk' + '&version=' + Math.random());
		//var xml = new loadXML('/en/jsp/weather.xml?source=brandhk' + '&version=' + Math.random());
		xml.action = function(x)
		{
			var xml = x.responseXML;
			if (isIE)
			{
				var parser = new DOMParser();
				xml = parser.parseFromString(x.responseText, "text/xml");
			}
			
			var TemperatureInformation = xml.getElementsByTagName('TemperatureInformation')[0];
			var Reading = TemperatureInformation.getElementsByTagName('Reading')[0];
			var Measure = Reading.getElementsByTagName('Measure')[0].firstChild.data;
			temperature.innerHTML = Measure + '&deg;C';
			
			var RelativeHumidityInformation = xml.getElementsByTagName('RelativeHumidityInformation')[0];
			var Reading = RelativeHumidityInformation.getElementsByTagName('Reading')[0];
			var Measure = Reading.getElementsByTagName('Measure')[0].firstChild.data;
			humidity.innerHTML = Measure + '%';
		}
	};
	
	this.init();
}

function searchControl()
{

	if(!d.getElementById('search')) return;

	var div = d.getElementById('search');
	var searchInput = getElementsByClassName(div, 'searchText')[0];

	searchInput.style.color = "#ccc";
	searchInput.value = 'Search';
	
	searchInput.onclick = function()
	{
		if(searchInput.value == 'Search')
		{
			searchInput.style.color="#333";
			searchInput.value = '';
		}
	}
	
	searchInput.onblur = function()
	{
		if(searchInput.value == '')
		{
			searchInput.style.color="#ccc";
			searchInput.value = 'Search';
		}
	}
}

/*function corpVidTab()
{
	if(!d.getElementById('corpVidItemContainer')) return;
	if(!d.getElementById('corpVidTab')) return;
	
	var corpItem = d.getElementById('corpVidItemContainer');
	var corpItemArray = corpItem.getElementsByTagName('DIV');
	
	var corpTab = d.getElementById('corpVidTab');
	var corpTabArray = corpTab.getElementsByTagName('A');
	
	for(var j=0; j<corpTabArray.length; j++)
	{
		corpTabArray[j].className = corpTabArray[j].className.replace('active', '');
		corpItemArray[j].style.display = 'none';
	}
	corpTabArray[0].className += 'active';
	corpItemArray[0].style.display = 'block';
	
	for(var i=0; i<corpTabArray.length; i++)
	{
		corpTabArray[i].id = i;
		corpTabArray[i].onclick = function()
		{
			for(var j=0; j<corpTabArray.length; j++)
			{
				corpTabArray[j].className = corpTabArray[j].className.replace('active', '');
				corpItemArray[j].style.display = 'none';
			}
			this.className += 'active';
			corpItemArray[this.id].style.display = 'block';
			startFading(corpItem);
		}
	}
}*/

function corpVidTab()
{
	var container = d.getElementById('corpVidItemContainer');
	var nav = d.getElementById('corpVidTab');
	var divs = container.getElementsByTagName('div');
	var total = divs.length;
	var highlightA;
	var highlightImg;
	var index = 1;
	var time = 5000;
	var timeout;
	var curIndex;
	var navList = new Array();
	
	nav.innerHTML = '';
	
	for (var i=0; i<total; i++)
	{
		var a = createA('javascript:;');
		a.img = divs[i];
		a.num = i;
		
		a.onclick = function()
		{
			if (this.className.indexOf('active') >= 0)	return;
			changeImg(this);
			clearInterval(timeout);
			setTimeout(function(){autoChange();}, 50);
		};
		
		nav.appendChild(a);
		navList.push(a);
	}
	
	changeImg(navList[0]);
	autoChange();
	
	function changeImg(btn)
	{	
		if (highlightImg)	highlightImg.style.display = 'none';
		btn.img.style.display = 'block';
		startFading(btn.img);
		highlightImg = btn.img;
		
		btn.className += ' active';
		if (highlightA)	highlightA.className = highlightA.className.replace(/active/, '');
		highlightA = btn;
		
		curIndex = btn.num;
	};
	
	function autoChange()
	{
		clearInterval(timeout);
		
		timeout = setInterval(function()
		{
			curIndex ++;
			if (curIndex >= total)	curIndex = 0;
			
			changeImg(navList[curIndex]);
		}, time);
	};
};

function videoBox(id, flvPath)
{
	var myDiv = d.getElementById(id);
	var div = createDiv('', 'lightboxContainer');
	
	var videoContainer = createDiv('', 'videoContainer');
	var videoSWF = createDiv('videoSWF');
	videoContainer.appendChild(videoSWF);
	var videoScriptContainer = createDiv('', 'videoScriptContainer', myDiv.innerHTML);
	
	div.appendChild(videoContainer);
	div.appendChild(videoScriptContainer);
	
	parent.showLightbox(div, flvPath);
};

function videoSingleBox(id, flvPath)
{
	var myDiv = d.getElementById(id);
	var div = createDiv('', 'lightboxContainer');
	
	var videoContainer = createDiv('', 'videoContainer');
	var videoSWF = createDiv('videoSWF');
	videoContainer.appendChild(videoSWF);
	
	div.appendChild(videoContainer);
	
	parent.showLightbox(div, flvPath, 342, 300);
};
