/* main page video box (domestic & intl)
===================================================================== */
var CurPage = 0;
var PrvPage = 3;
var Lock = false;
var intPage=1;
function Blur( lnk ) {
	try {
		lnk.blur();
	} catch(e) {};
}
/*
 * Next() and Prev()
 * are called from previous and next buttons
 */
function Next(lnk,pause) {
	Blur( lnk );
			stop = false;
		 StopStartRotate(pause)
	
	if(!Lock) {
		SlideLeft();
	}
}

function Prev(lnk,pause) {
	Blur( lnk );
			stop = false;
		StopStartRotate(pause)
	
	if(!Lock) {
		SlideRight();
	}
}

/*
 * Page( intPage )
 * called from clicking on gray dot icon
 */

function Page(intt,lnk,pause) {
	
	Blur( lnk );
	if (pause != null)
	{	stop = false;
		StopStartRotate(pause)
	}
	if((CurPage != intt)&&(!Lock)) {
		//alert(CurPage);
		//alert(intt);
		if(CurPage < intt) {
				//alert('less');		
			if((intt - CurPage) == 2) {
				
				
				SlideDoubleLeft(intt);
				
			}
			else if((intt - CurPage) == 3){
			
				
				SlideTrippleLeft(intt);
				
				var intPageObj = document.getElementById('mainGraphic'+intPage);
				intPageObj.style.left = '970px';
			}
			else if((intt - CurPage) == 1){

				intPage = intt;
				SlideLeft();
			}

			
		}
		else {
				
			if((CurPage - intt) == 3) {
	
				intPage = intt;
				SlideLeft();
			}
			else if((CurPage - intt) == 2){
				
				
				SlideDoubleRight();
			}
			else if((CurPage - intt) == 1){
							
				intPage = PrvPage;			
				SlideRight();
			}
			
		}
		
	}
	
}



function MouseOver( id ) {
	for(i=0;i<4;i++) {
	$(id).src = '/bluelinks-for-employers/images/index/toggle/New Folder/toggle-btn-'+i+'-over.png';
	}
}

function Locker( intDur ) {
	var LockerTime = intDur * 100;
	Lock = true;
	setTimeout(function() { Lock = false; },LockerTime);
}


function SlideLeft() {
	Locker(3);
	new Effect.MoveBy( 'mainGraphic'+CurPage, 0, -970 , {duration: 0.5} );
	new Effect.MoveBy( 'mainGraphic'+intPage, 0, -970 , {duration: 0.5} );
	
	
	var intPlus = parseInt(intPage)+1;
	
	PrvPage = CurPage;
	CurPage = intPage;
	intPage = intPlus;
	
	if (CurPage == 3)
	{
		intPage = 0;
	}
	
	var intPageObj = document.getElementById('mainGraphic'+intPage);
	intPageObj.style.left = '970px';
	
	MoveDot();
	UpdateBtns();
}

function SlideDoubleLeft(intt) {
	Locker(6);
	
	var intPlusPageObj = document.getElementById('mainGraphic'+intt);
	intPlusPageObj.style.left = '970px';
	
	new Effect.MoveBy( 'mainGraphic'+CurPage, 0, -970 , {duration: 0.5} );
	new Effect.MoveBy( 'mainGraphic'+intPage, 0, -1940 , {duration: 0.5} );
	new Effect.MoveBy( 'mainGraphic'+intt, 0, -970 , {duration: 0.5} );
	
	var intPlus = parseInt(intt)+1;
	
	PrvPage = intPage;
	CurPage = intt;
	intPage = intPlus;
	
	if (intPage == 4)
	{
		intPage = 0;
	}
	
	var intPageObj = document.getElementById('mainGraphic'+intPage);
	intPageObj.style.left = '970px';
	
	
	MoveDot();
	UpdateBtns();
	
}

function SlideTrippleLeft(intt) {
	Locker(3);
	var intPlus = parseInt(intPage)+1;
	
	var intPlusPageObj = document.getElementById('mainGraphic'+intPlus);
	intPlusPageObj.style.left = '970px';
	
	var inttPageObj = document.getElementById('mainGraphic'+intt);
	inttPageObj.style.left = '970px';
	
	//new Effect.MoveBy( 'mainGraphic'+CurPage, 0, -970 , {duration: 0.5} );
	new Effect.MoveBy( 'mainGraphic'+intPage, 0, -1940 , {duration: 0.5} );
	new Effect.MoveBy( 'mainGraphic'+intPlus, 0, -1940 , {duration: 0.5} );
	new Effect.MoveBy( 'mainGraphic'+intt, 0, -970 , {duration: 0.5} );
	
	
	
	PrvPage = intPlus;
	CurPage = intt;
	var newIntPlus = parseInt(intt)+1;
	intPage = newIntPlus;
	
	if (newIntPlus == 4)
	{
		intPage = 0;
	}
	
	
	
	
	MoveDot();
	UpdateBtns();
	
	
}

function SlideRight() {
	Locker(3);

	new Effect.MoveBy( 'mainGraphic'+CurPage, 0, 970 , {duration: 0.5} );
	new Effect.MoveBy( 'mainGraphic'+PrvPage, 0, 970 , {duration: 0.5} );
	
	
	intPage = CurPage;
	CurPage = PrvPage;
	
	var prvMinusPage = parseInt(PrvPage)-1;
	PrvPage = prvMinusPage;
	if (prvMinusPage == -1)
	{
		PrvPage = 3;
	}
	
	var PrvPageObj = document.getElementById('mainGraphic'+PrvPage);
	PrvPageObj.style.left = '-970px';
		
	MoveDot();
	UpdateBtns();
}

function SlideDoubleRight() {
	Locker(6);
	
	var prvMinusPage = parseInt(PrvPage)-1;
	var prvMinusPageObj = document.getElementById('mainGraphic'+prvMinusPage);
	prvMinusPageObj.style.left = '-970px';
	
	new Effect.MoveBy( 'mainGraphic'+CurPage, 0, 970 , {duration: 0.5} );
	new Effect.MoveBy( 'mainGraphic'+PrvPage, 0, 1940 , {duration: 0.5} );
	new Effect.MoveBy( 'mainGraphic'+prvMinusPage, 0, 970 , {duration: 0.5} );
	
	CurPage = prvMinusPage;
	intPage = PrvPage;
	PrvPage = parseInt(CurPage)-1;
	
	if (PrvPage == -1)
	{
		PrvPage = 3;
	}
	
	MoveDot();
	UpdateBtns();
}

// image change functions
function MoveDot() {
	for(i=0;i<4;i++) {
		$('Btn'+i).src = '/bluelinks-for-employers/images/index/toggle/New Folder/toggle-btn-'+i+'.png';
		
	}
	$('Btn'+CurPage).src = '/bluelinks-for-employers/images/index/toggle/New Folder/toggle-btn-'+CurPage+'-over.png';
	$('Btn'+CurPage).onmouseover = function() {}
	$('Btn'+CurPage).onmouseout = function() {}
}
function UpdateBtns() {
	if(CurPage > 0) {
		$('BtnL').style.cursor ='auto';
		$('BtnL').src = '/bluelinks-for-employers/images/index/toggle/rewind.png';
		$('BtnL').onmouseover = function() { this.src='/bluelinks-for-employers/images/index/toggle/rewind.png'; }
		$('BtnL').onmouseout = function() { this.src='/bluelinks-for-employers/images/index/toggle/rewind.png'; }
	}
	else {
		$('BtnL').style.cursor ='default';
		$('BtnL').src = '/bluelinks-for-employers/images/index/toggle/rewind.png';
		$('BtnL').onmouseover = function() {}
		$('BtnL').onmouseout = function() {}
	}

	if(CurPage < 3) {
		$('BtnR').style.cursor ='auto';
		$('BtnR').src = '/bluelinks-for-employers/images/index/toggle/forward.png';
		$('BtnR').onmouseover = function() {this.src = '/bluelinks-for-employers/images/index/toggle/forward.png';}
		$('BtnR').onmouseout = function() {this.src = '/bluelinks-for-employers/images/index/toggle/forward.png';}
	}
	else {
		$('BtnR').style.cursor ='default';
		$('BtnR').src = '/bluelinks-for-employers/images/index/toggle/forward.png';
		$('BtnR').onmouseover = function() {}
		$('BtnR').onmouseout = function() {}
	}
}
/* end main page video box
===================================================================== */


var secs
var timerID = null
var timerRunning = false
var delay = 1000
var imgId = 1
var stop = false 

function InitializeTimer()
{
    // Set the length of the timer, in seconds
    secs = 8
    StopTheClock()
    StartTheTimer()
}

function StopTheClock()
{
    if(timerRunning)
        clearTimeout(timerID)
    timerRunning = false
}

function StartTheTimer()
{
	if (secs==0)
	{
		StopTheClock()
		// Here's where you put something useful that's
		// supposed to happen after the allotted time.
		// For example, you could display a message:

		var aId = 'toggleBtn-a-id-'+imgId;
		var aObj = document.getElementById(aId);
		Pager(imgId,aObj);
		imgId = imgId + 1;

		if(imgId == 4){
		imgId = 0;
		}

		if (stop == false)
		{
		InitializeTimer()
		}

	}
	else
	{
		//self.status = secs
		secs = secs - 1
		timerRunning = true
		timerID = self.setTimeout("StartTheTimer()", delay)
	}
}

function Pager(intt,lnk,pause) {
	intPage = intt;
	Blur( lnk );
	if (pause != null)
	{	stop = false;
		StopStartRotate(pause)
	}
	if((CurPage != intPage)&&(!Lock)) {
		SlideLeft();
	}
	
}

function StopStartRotate(id) {
	var Obj = document.getElementById(id);
	if (stop == false)
	{
		stop = true;
		Obj.src = '/bluelinks-for-employers/images/index/toggle/play.png';
		secs = 999;
	}else {
		stop = false;
		Obj.src = '/bluelinks-for-employers/images/index/toggle/pause.png';
		secs = 0;
		imgId=intPage;
		StartTheTimer()
	}
}
