var imagesAry=['resources/images/homepage/guangzhou.jpg','resources/images/homepage/sanFrancisco.jpg','resources/images/homepage/sanJose.jpg','resources/images/homepage/shanghai.jpg','resources/images/homepage/beijing.jpg','resources/images/homepage/hongKong.jpg'];
	
var obj;

function Start(w,h,setTimer)
{
	var ctl=document.getElementById('idDiv')
	ResizeWindow();
	
	ctl.cnt=0;
	ctl.ary=[];
	var limit = Math.max(imagesAry.length,Math.ceil(ctl.offsetWidth/w)+1);
	
	for (var i=0;i<limit;i++)
	{
		ctl.ary[i]=document.createElement('IMG');
		ctl.ary[i].src=imagesAry[ctl.cnt];
		ctl.cnt=++ctl.cnt%imagesAry.length;                    
		Style(ctl.ary[i],{position:'absolute',left:(w*i)+'px',top:'1px',width:w+'px',height:h+'px'});
				  
		ctl.appendChild(ctl.ary[i]); 
	}
	ctl.cnt=0;
	ctl.first=ctl.ary[ctl.cnt];
	ctl.last=ctl.ary[ctl.ary.length-1];
				 
	obj=ctl;
	
	if (setTimer)
	{
		setTimeout('Rotate()',500);
	}
	
}

function ResizeWindow()
{
	var ctl=document.getElementById('idDiv');
	var RightDiv=document.getElementById('RightDiv');
	var MainDiv=document.getElementById('MainDiv');
	var LeftDiv=document.getElementById('LeftDiv');
	  
	//resize based on browser width 
	var offSetWidth = document.body.offsetWidth;
	
	var browserWidth = offSetWidth;
	var RightDivLeft = browserWidth - 30;

	Style(ctl,{width:browserWidth + 'px'});
	Style(RightDiv,{left:RightDivLeft + 'px'});
	Style(MainDiv,{width:browserWidth + 'px'});
	 
	//modify absolute positioning for IE
	if (navigator.appName == "Microsoft Internet Explorer")
	{
		Style(RightDiv,{top:'-4px'});
		Style(LeftDiv,{top:'-4px'});         
	}
}


function Rotate()
{

	for (var i=0;i<obj.ary.length;i++)
	{
		obj.ary[i].style.left=(parseInt(obj.ary[i].style.left)-1)+'px';
		
		if (parseInt(obj.first.style.left)+parseInt(obj.first.style.width)<0)
		{
			var start = (parseInt(obj.last.style.left)+parseInt(obj.last.style.width)) -5;
			obj.first.style.left= start +'px';
			obj.last=obj.first;
			obj.cnt=++obj.cnt%obj.ary.length;
			obj.first=obj.ary[obj.cnt];
		}
			
	}
	setTimeout('Rotate()',50);
}


function Style(control,style)
{
	for (key in style)
	{ 
		control.style[key]=style[key]; 
	}
}

function switchImage(elId,dir)
{
	document.getElementById(elId).src = 'images/menuArrow' + dir + '.gif';
}

function handleMenuEffects(el)
{
	switch (el)
	{
		case 'services':
			animeEl = document.getElementById('moreServices');
			animeElId = 'moreServices';
			imageId = 'servicesArrow';
			domEl = document.getElementById('servicesLink');
			break;
	}
	if(animeEl.style.display == 'none')
	{
		Effect.SlideDown(animeElId);
	}
	else
	{
		Effect.SlideUp(animeElId);
	}

	if(document.getElementById(imageId).src.substring(document.getElementById(imageId).src.length-6) == 'Up.gif')
	{
		document.getElementById(imageId).src = 'images/menuArrow.gif';
	}
	else
	{
		document.getElementById(imageId).src = 'images/menuArrowUp.gif';
	}
}
