﻿// JavaScript Document
var isIE = (navigator.appName.indexOf("Microsoft") > -1);
var d = document;
var str;

if (!levelArray)	var levelArray = new Array();


function init()
{
	if (levelArray.length == 0)	getLevel();
	highlightTopNav();
	setPulldown();
	if (d.getElementById('whatsHotBoard')) setTabList.init('whatsHotNav', 'whatsHotPoster');
	if (d.getElementById('sliderNav')) bannerScroll.init('sliderNav', 'sliderArrowR', 'sliderArrowL');
	
	if (d.getElementById('tourGuide')) setTabList.init('toursBtn', 'tourGuide');
	if (d.getElementById('floorplans')) setTabList.init('floorNavBtn', 'floorplans');
	
	if (d.getElementById('busSchedules')) setTabList.init('transportBtn', 'busSchedules');
}

function getLevel()
{
	var url = location.pathname;
	var array = url.split('/');
	
	for (var i=0; i<array.length; i++)
	{
		if (array[i].indexOf('_') >= 0)
		{
			var array1 = array[i].split('_');
			for (var j=0; j<array1.length; j++)
			{
				levelArray.push(array1[j]);
			}
			
		}
		else
		{
			levelArray.push(array[i]);
			
		}
	}
	
	levelArray.shift();
	levelArray.shift();
	
	var obj = levelArray[levelArray.length-1];
	levelArray[levelArray.length-1] = obj.replace('.html', '');
	/*if (obj != 'index.html')
	{
		levelArray[levelArray.length-1] = obj.replace('.html', '');
	}
	else
	{
		levelArray.pop();
	}*/
	//alert(levelArray);
}

function highlightTopNav()
{
	if (levelArray.length == 0)
	{
		var btn = d.getElementById('home');
		btn.className += ' active';
		return;
	}
	
	var obj = levelArray[0];
	if (!d.getElementById(obj))	return;
	
	var btn = d.getElementById(obj);
	btn.className += ' active';
}

var tc = "tc";
var sc = "sc";
var en = "en";
function changeLanguage(target)
{
	var array = new Array("en", "tc", "sc");
	var nowL = checkURL(array);
	var va = [["/", "/"], ["=", ""]];
	var url = window.top.location.href;
	//alert(url);
	for (var item=0; item<va.length; item++)
	{
		if (url.indexOf((va[item][0] + nowL + va[item][1])) >= 0)
		{
			url = url.replace((va[item][0] + nowL + va[item][1]), (va[item][0] + target + va[item][1]));
			break;
		}
	}
	if (url.substring((url.length-1), url.length) == '#') url = url.substring(0, (url.length-1))
	
	window.top.location.href = url;
} 

function checkURL(array)
{
	var url = window.top.location.href;
	var id;
	var va = [["/", "/"], ["=", ""]];
	
	for (var item=0; item<va.length; item++)
	{
		for (var i=0; i<array.length; i++)
		{
			if (url.indexOf((va[item][0] + array[i] + va[item][1])) >= 0)
			{
				id = array[i];
				break;
			}
		}
	}
	
	return id;
}


function startFading(el)
{
  if (el.fadinTimeout)	clearTimeout(el.fadinTimeout);
  el.style.visibility = 'visible';
  el.style.zIndex = 2;
  setOpacity(el, 0);
  fadeImage(el, 0);
}

function fadeImage(el, currentOpacity)
{
  currentOpacity += 10;

  if (currentOpacity > 100)
  {
    setOpacity(el, 100);
    el.style.zIndex = 1;
	if (el.fadinTimeout)	clearTimeout(el.fadinTimeout);
  }
  else
  {
    setOpacity(el, currentOpacity);
    el.fadinTimeout = setTimeout(function() { fadeImage(el, currentOpacity); }, 30);
  }
}

function setOpacity(el, opacity)
{
	opacity /= 100;
	el.style.opacity = opacity;
	el.style.MozOpacity = opacity;
	el.style.filter = "alpha(opacity=" + (opacity*100) + ")";
}

function setChildNodes(obj, tagName)
{
	var array = new Array();
	
	for (var i=0; i<obj.childNodes.length; i++)
	{
		if (tagName)
		{
			//alert(obj.childNodes[i].tagName)
			if (obj.childNodes[i].tagName != tagName)	continue;
		}
		if (obj.childNodes[i].toString().toLowerCase().indexOf('text') >= 0)	continue;
		array.push(obj.childNodes[i]);
	}
	
	return array;
}

var setTabList = 
{
	init:	function (nav, obj)
	{
		this.nav = d.getElementById(nav);
		this.obj = d.getElementById(obj);
		
		this.setA(this.nav);
	},
	
	setA:	function (nav)
	{
		var a = nav.getElementsByTagName('a');
		
		for (var i=0; i<a.length; i++)
		{
			a[i].num = i;
			a[i].parent = this;
			a[i].className = a[i].className.replace('active', '');
			
			a[i].onclick = function()
			{
				if (this.className.indexOf('active') >= 0)	return;
				this.parent.changeA(this, true);
			}
		}
		
		this.highlightA = a[0];
		this.changeA(a[0], false);
	},
	
	changeA:	function (obj, fadeIn)
	{
		var highlightA = this.highlightA;
		highlightA.className = highlightA.className.replace('active', '');
		obj.className += ' active';
		
		var img = setChildNodes(this.obj, 'DIV');
		img[this.highlightA.num].style.display = 'none';
		img[obj.num].style.display = 'block';
		
		this.highlightA = obj;
		if (fadeIn)	startFading(this.obj);
		
		if (!d.getElementById('shopInfoDetails')) return;
		if (d.getElementById('shopInfoDetails').style.display == 'block')	setTimeout(function(){genLeasePulldown();}, 100);
	}
}



function genLeasePulldown()
{
	var scrollArray = [d.getElementById('shopInfoDetails')];
	var scroller;
	var scrollbar;
	
	for(var i=0; i<scrollArray.length; i++)
	{
		var scrollContainer  = getElementsByClassName(scrollArray[i], 'leftScrollTable')[0];
		var scroll = getElementsByClassName(scrollArray[i],'Scrollbar-Container')[0];
		
		try
		{
			if (!scroller)
			{
				scroller  = new Scrolling.Scroller(scrollContainer, scroll.offsetWidth, scroll.offsetHeight);
				scrollbar = new Scrolling.Scrollbar(scroll, scroller, new Scrolling.ScrollTween());
			}
			else
			{
				scroller.swapContent(scrollContainer, scroll.offsetWidth, scroll.offsetHeight);
				scrollbar.swapContent(scroll, scroll.offsetWidth, scroll.offsetHeight);
			}
		}
		catch(e){}
	}
}

/*
function busScrolldown()
{
	var scrollArray = [d.getElementById('busSchedule_2')];
	for(var i=0; i<scrollArray.length; i++)
	{
		var scrollContainer  = getElementsByClassName(scrollArray[i], 'busScrollContent')[0];
		var scroll = getElementsByClassName(scrollArray[i],'busScrollbar-Container')[0];
		
		try{
			var scroller  = new Scrolling.Scroller(scrollContainer, scroll.offsetWidth, scroll.offsetHeight);
			var scrollbar = new Scrolling.Scrollbar(scroll, scroller, new Scrolling.ScrollTween());
		}catch(e){}
	}
}
*/

function getElementsByClassName(p, c)
{
	var array = new Array();
	var tags = p.getElementsByTagName('*');
	
	for (var i=0; i<tags.length; i++)
	{
		if (!tags[i].className)	continue;
		if (tags[i].className.indexOf(c) >= 0)	array.push(tags[i]);
	}
	
	return array;
}

function setSlider()
{
	var nav = d.getElementById('sliderLinks');
	var navContent = nav.getElementsByTagName('a');
	if (d.getElementById('sliderSubLinks'))
	{
		var subNav = d.getElementById('sliderSubLinks');
		var subContent = setChildNodes(subNav, 'TABLE');
	}
	
	var self = this;
	var highlightNav = null;
	var slide = null;
	
	this.init = function()
	{
		this.setA();
		var motion = new slider('sliderNav', 'sliderLinks', 'sliderArrowR', 'sliderArrowL');
		this.goAnchor(motion);
	};
	
	this.setA = function(id)
	{
		for (var i=0; i<navContent.length; i++)
		{
			navContent[i].num = i;
			/*navContent[i].onclick = function()
			{
				self.changeA(this.num);
			};*/
		}
		//this.changeA(0);
		if (subNav)
		{
			if (slide)	slide.reset();
			slide = new slider('sliderSubNav', 'sliderSubLinks', 'sliderArrowR', 'sliderArrowL');
		}
	};
	
	this.changeA = function(id)
	{
		if (highlightNav)
		{
			if (subNav)	subContent[highlightNav.num].style.display = 'none';
			highlightNav.className = highlightNav.className.replace(/Active/, '');
		}
		
		if (subNav)	subContent[id].style.display = 'block';
		if (navContent[id].className.indexOf('Active') < 0)	navContent[id].className += 'Active';
		
		highlightNav = navContent[id];
		
		if (slide)	slide.reset();
		slide = new slider('sliderSubNav', 'sliderSubLinks', 'sliderArrowR', 'sliderArrowL');
	};
	
	this.goAnchor = function(motion)
	{
		var a;
		for (var i=0; i<navContent.length; i++)
		{
			if (navContent[i].className.indexOf('Active') >= 0)
			{
				a = navContent[i];
				break;
			}
		}
		if (!a)	return;
		
		motion.goAnchor(a.parentNode);
	};
	
	this.init();
}

function slider(container, obj, R, L)
{
	this.container = d.getElementById(container);
	this.obj = d.getElementById(obj);
	this.arrowR = d.getElementById(R);
	this.arrowL = d.getElementById(L);
	this.ratio = 3;
	this.timeOutSpeed = 10;
	this.curIndex = 0;
	this.containerW = this.container.offsetWidth;
	this.objW = this.obj.offsetWidth;
	this.total = Math.ceil(this.objW/this.containerW);
	//alert(this.containerW + '  :  ' + this.objW);
	
	var self = this;
	
	this.init = function()
	{
		//Duplicate Content for loop
		//var str = this.container.innerHTML;
		//this.container.innerHTML += str;
		
		if (this.total == 1)
		{
			this.arrowR.style.display = 'none';
			this.arrowL.style.display = 'none';
		}
		else
		{
			this.arrowR.style.display = '';
			this.arrowL.style.display = '';
		}
		
		this.arrowR.onclick = function()	{self.goScroll(1)};
		this.arrowL.onclick = function()	{self.goScroll(-1)};
		
		if (this.total > 1)	this.goScroll(0, true);
	};
	
	this.reset = function()
	{
		this.obj.style.left = 0;
	};
	
	this.goAnchor = function(target)
	{
		//alert(target.offsetLeft + '  :  ' + this.containerW);
		var id = Math.ceil((target.offsetLeft + 1)/this.containerW) - 1;
		this.goScroll(id, true);
	};
	
	this.goScroll = function(num, start)
	{
		this.curIndex += num;
		if (this.curIndex >= this.total)	this.curIndex = this.total - 1;/*this.curIndex = 0;*/
		if (this.curIndex < 0)				this.curIndex = 0;/*this.curIndex = this.total-1;*/
		
		var opacity = (this.curIndex == 0)				?	40	:	100;
		this.setAlpha(this.arrowL.getElementsByTagName('img')[0], opacity);
		var opacity = (this.curIndex == this.total - 1)	?	40	:	100;
		this.setAlpha(this.arrowR.getElementsByTagName('img')[0], opacity);
		
		this.obj.L = - this.containerW*this.curIndex;
		//alert(this.obj.L + ' : ' + this.curIndex);
		
		clearTimeout(this.obj.timeOut);
		this.motion(this.obj, start);
	};
	
	this.motion = function(obj, start)
	{
		if (start)
		{
			obj.style.left = obj.L + 'px';
			return;
		}
		
		obj.objL = obj.offsetLeft;

		obj.goStep = (obj.L - obj.objL)/this.ratio;
		if (obj.goStep > 0)	obj.goStep = Math.ceil(obj.goStep);
		if (obj.goStep < 0)	obj.goStep = Math.floor(obj.goStep);

		if (!(Math.abs(obj.objL - obj.L) < 1))
		{
			obj.objL += obj.goStep;
			obj.timeOut = setTimeout(function(){self.motion(obj);}, this.timeOutSpeed);
		}
		else
		{
			obj.objL = obj.L;
			clearTimeout(obj.timeOut);
			//alert(obj.objL + ' : ' +  obj.L);
		}

		obj.style.left = obj.objL + 'px';
		//window.status = obj.scrollLeft + '  :  ' + obj.L;
		//window.status = obj.goStep;
	};
	
	this.setAlpha = function(obj, opacity)
	{
		obj.style.opacity = opacity/100;
		obj.style.MozOpacity = opacity/100;
		obj.style.filter = 'alpha(opacity=' + opacity + ')';
	};
	
	this.init();
}
function setPulldown(btn, id)
{
	var nav = d.getElementById('topNavMain');
	//alert(nav);
	var a = nav.getElementsByTagName('a');
	//var navList = new Array();
	var obj = levelArray[0];
	
	for (var i=0; i<a.length; i++)
	{
		a[i].onmouseover = function()
		{
			showPulldown(this, this.id);
			//alert(this.id);
			
		};
		//var menu = d.getElementById(obj + 'Dropdown');
		//menu.style.display = 'block';
		
		//navList.push(a);
		//if (levelArray[0] == a[i].id)	showPulldown(a[i], a[i].id);
	}
}

function showPulldown(btn, id)
{
	//if (btn.className.indexOf('active') >= 0)	return;
	if (!d.getElementById(id + 'Dropdown'))	return;
	
	var menu = d.getElementById(id + 'Dropdown');
	showLayer(1);
	btn.onmouseover		= function() {menu.hit = true;	showLayer(1);};
	menu.onmouseover	= function() {menu.hit = true;	showLayer(1);};
	btn.onmouseout		= function() {menu.hit = false;	showLayer(0);};
	menu.onmouseout		= function() {menu.hit = false;	showLayer(0);};
	
	function showLayer(over)
	{
		if (over == 1)
		{
			if (btn.className.indexOf('active') < 0)	btn.className += ' active';
			menu.style.display = 'block';
		}
		else
		{	
			setTimeout(function()
			{
				if (!menu.hit)
				{
					if (levelArray[0] != id)	btn.className = btn.className.replace('active', '');
					menu.style.display = '';
				}
			}, 100);
		}
	}
}

var bannerScroll = 
{
	init:	function (obj, R, L)
	{	
		this.container  = d.getElementById(obj);
		this.arrowR  = d.getElementById(R);
		this.arrowL  = d.getElementById(L);
		this.timeOutSpeed = 10;
		
		this.curIndex = 0;
		
		this.containerW = this.container.offsetWidth;
		this.objW = this.container.scrollWidth;
		this.total = Math.round(this.objW/this.containerW);
		
		//Duplicate Content for loop
		//var str = this.container.innerHTML;
		//this.container.innerHTML += str;
		
		//window.status = this.container.offsetWidth + '  :  ' + this.container.scrollWidth;
		
		this.arrowR.onclick = function()	{bannerScroll.goScroll(1)};
		this.arrowL.onclick = function()	{bannerScroll.goScroll(-1)};
	},
	
	goScroll:	function(num)
	{
		this.curIndex += num;
		if (this.curIndex > this.total-1)	this.curIndex = 0;
		if (this.curIndex < 0)	this.curIndex = this.total-1;
		
		//window.status = this.curIndex + '  :  ' + this.total;
		
		//this.container.L = this.containerW*this.curIndex;
		this.container.L = Math.ceil(this.objW/this.total)*this.curIndex;
		this.container.speed = 10;
		
		clearTimeout(this.container.timeOut);
		this.motion(this.container);
	},
	
	motion:	function(container)
	{
		//container.objL = Number(container.scrollLeft.substring(0, (container.scrollLeft.toString().length-2)));
		container.objL = container.scrollLeft;

		container.goStep = (container.L - container.objL)/container.speed;
		if (container.goStep > 0)	container.goStep = Math.ceil(container.goStep);
		if (container.goStep < 0)	container.goStep = Math.floor(container.goStep);

		if (!(Math.abs(container.objL - container.L) < 1))
		{
			container.objL += container.goStep;
			container.timeOut = setTimeout(function(){bannerScroll.motion(container);}, this.timeOutSpeed);
		}
		else
		{
			container.objL = container.L;
			clearTimeout(container.timeOut);
			//alert(container.objL + ' : ' +  container.L);
		}

		container.scrollLeft = container.objL;
		//window.status = container.scrollLeft + '  :  ' + container.L;
		//window.status = container.goStep;
	}
}

function genFlash(file, width, height, id, vars) {
	var tempHtml = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+width+'" height="'+height+'" id="'+id+'" name="'+id+'">';
	tempHtml += '<param name="movie" value="'+file+'">';
	tempHtml += '<param name="quality" value="high">';
	tempHtml += '<param name="menu" value="false">';
	tempHtml += '<param name="wmode" value="opaque">';
	tempHtml += '<param name="scale" value="noscale">';
	tempHtml += '<param name="salign" value="TL">';
	
	if (vars != null) {
		tempHtml += '<param name="flashVars" value="'+vars+'">';
		tempHtml += '<embed src="'+file+'" flashVars="'+vars+'" salign="TL" quality="high" scale="noscale" wmode="opaque" menu="false" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'" id="'+id+'" name="'+id+'"></embed>';
	} else {
		tempHtml += '<embed src="'+file+'" salign="TL" quality="high" scale="noscale" wmode="opaque" menu="false" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'" id="'+id+'" name="'+id+'"></embed>';
	}
	
	tempHtml += '</object>';
	
	document.write(tempHtml);
}


function GetParam(name)
{
	var start=location.search.indexOf("?"+name+"=");
	if (start<0) start=location.search.indexOf("&"+name+"=");
 	if (start<0) return '';
 	start += name.length+2;
 	var end=location.search.indexOf("&",start)-1;
 	if (end<0) end=location.search.length;
 	var result=location.search.substring(start,end);
 	var result='';
 	for(var i=start;i<=end;i++)
 	{
 		var c=location.search.charAt(i);
 		result=result+(c=='+'?' ':c);
 	}
 	//alert(unescape(result));
 	return unescape(result);
}
/*
function genSwf(path)
{
	if (!d.getElementById('flashContainer'))	return;
	
	var flashContainer = d.getElementById("flashContainer");
	
	var flashvars = {};
	if (GetParam('page'))	flashvars.page = GetParam('page');
	else
	if (GetParam('id'))	flashvars.page = GetParam('id');

	var params = {};
	params.allowscriptaccess = "sameDomain";
	params.wmode = "transparent";
	
	var attributes = {};
	//attributes.id = "topSwf";
	
	swfobject.embedSWF(path, "flashContainer", "819", "438", "9.0.45", false, flashvars, params, attributes);
}*/
