var imagesAry=['images/stocks/1.jpg','images/stocks/2.jpg','images/stocks/3.jpg','images/stocks/4.jpg','images/stocks/5.jpg','images/stocks/1.jpg','images/stocks/2.jpg','images/stocks/3.jpg','images/stocks/4.jpg','images/stocks/5.jpg'];
var globalLivePage = 'mainPage';
var obj;
var testimonialsArray = ['1','2','3','4','5','6','7','8','9','10'];
var testimonialsPosition = 0;

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 + '.png';
}

function validateContactForm()
{
	var namefield = document.getElementById('name');
	var emailfield = document.getElementById('email');
	var phonefield = document.getElementById('phone');
	var messagefield = document.getElementById('message');
	if(namefield.value == '' || emailfield.value == '')
	{
		alert('Your name and email address are required. Please fill these field in.');
	}
	else
	{
		document.forms.contactForm.submit();
	}
}




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.png')
	{
		document.getElementById(imageId).src = 'images/menuArrow.png';
	}
	else
	{
		document.getElementById(imageId).src = 'images/menuArrowUp.png';
	}
}

checkScreenSize = function()
{
	if(typeof screen.width != 'undefined')
	{
		if(screen.width < 1200)
		{
			document.getElementById('rightBodyDivFaq').style.display = 'none';
			document.getElementById('menuFaq').style.display = '';
		}
	}
}

function handleTestimonials()
{
	if(testimonialsPosition == 10) testimonialsPosition = 0;
	Effect.Appear('t' + testimonialsArray[testimonialsPosition],{duration: 3.0});
	setTimeout('disAppearTestimonial()',10000);
}

function disAppearTestimonial()
{
	Effect.Fade('t' + testimonialsArray[testimonialsPosition],{duration: 3.0});
	testimonialsPosition++;
	setTimeout('handleTestimonials()',2500);
}
