// JavaScript Document


/////////////////Safe to Edit Variables are here, at the top///////////////////////


var slideSpeed=0.95; 	//Sliding speed of items - in Seconds
var delay=7; 			//Delay between sliding to the next item - in Seconds


/////////////////Please Do Not Alter Content Below This Line///////////////////////
/////////////////Please Do Not Alter Content Below This Line///////////////////////
/////////////////Please Do Not Alter Content Below This Line///////////////////////
/////////////////Please Do Not Alter Content Below This Line///////////////////////
/////////////////Please Do Not Alter Content Below This Line///////////////////////
/////////////////Please Do Not Alter Content Below This Line///////////////////////
/////////////////Please Do Not Alter Content Below This Line///////////////////////
var timer;
var originalSpeed=slideSpeed;
var originalDelay=delay;
var tempDelay = delay/2;
var firstOn=true;
var loopPage=2; //First page to go to after initial delay
var currentPage=1;  //the currnet page the wrapper is displaying
var timer; //Delay Timer

//--------------------------Build Pages - iFrames [Function]--------------------------------- 

function showContent(){
		for(i=1; i<=numberOfPages; i++){
			tempLink = ('<a class="slidingImage" id="slideLink'+i+'" target=_blank href="'+ pageLinks[i] +'"></a>');
			tempFrame = ('<div class="slide" style="background-image:url('+ pageImages[i] +')"></div>');
			$("div.wrapper").append(tempLink);
			$("a.slidingImage#slideLink"+i).append(tempFrame);
		}
}
$(document).ready(function(){

showInd();



//--------------------------goto Page [Function]--------------------------------- 

function gotoPage(page,speed){
	  if(page>currentPage)
	  {
		  pagePass=page-currentPage;
		  newPage=pagePass*-902;
		  newIndTemp=pagePass*-15;
		  
		  $("div.wrapper").animate({"left":"+=" + newPage + "px"},speed);
		  $("div.indCurrent").animate({"left":"-=" + newIndTemp + "px"},speed);
		  currentPage=page;
	  }
	  
	  else if(page<currentPage)
	  {
		  pagePass=currentPage-page;
		  newPage=pagePass*-902;
		  newIndTemp=pagePass*-15;
		
		  $("div.wrapper").animate({"left":"-=" + newPage + "px"},speed);
		  $("div.indCurrent").animate({"left":"+=" + newIndTemp + "px"},speed);
		  currentPage=page;
	  }
}

function gotoPageLoop(page,speed){
	  if(loopPage<=numberOfPages){
		  slideSpeed=originalSpeed;
	  }
	  if(firstOn==false){
		  firstOn=true;
		  delay=originalDelay;
	  }
	  if(page>currentPage)
	  {
		  pagePass=page-currentPage;
		  newPage=pagePass*-902;
		  newIndTemp=pagePass*-15;
		  
		  $("div.wrapper").animate({"left":"+=" + newPage + "px"},speed);
		  $("div.indCurrent").animate({"left":"-=" + newIndTemp + "px"},speed);
		  currentPage=page;
	  }
	  
	  else if(page<currentPage)
	  {
		  pagePass=currentPage-page;
		  newPage=pagePass*-902;
		  newIndTemp=pagePass*-15;
		
		  $("div.wrapper").animate({"left":"-=" + newPage + "px"},speed);
		  $("div.indCurrent").animate({"left":"+=" + newIndTemp + "px"},speed);
		  currentPage=page;
	  }
	  loopPage++;
	  if(loopPage>numberOfPages){
	  	loopPage=1;
		slideSpeed=0.0001;
	  }
	  $('div.test').html(delay);
	  mainLoop();
}

//--------------------------Build Page Indicator [Function]--------------------------------- 
function showInd(){
	if(numberOfPages==1){
		$('div.indicator').hide();
	}
	else{
		centerInd=(902-((numberOfPages*10)+((numberOfPages-1)*5)))/2;
		$('div.indicator').css('right',centerInd+'px');
		margin=(numberOfPages-1)*15;
		currentMargin= ((((902-20)/15)-(numberOfPages-1))*15)+10;
		$("div.indCurrent").css("left",currentMargin);
		tb=numberOfPages;
		ti=1;
		
		for (i=1; i <= numberOfPages; i++){
			temp = ('<div class="indicatorSingle" id=digi' + i + '></div>');
			$("div.indicator#digiInd").append(temp);
			$("div.indicatorSingle#digi" + i).css("right",margin);
			$("div.indicatorSingle#digi" + i).html("<!-- -->");
			
			tb=numberOfPages;
			ti=i;
			
			$("div.indicatorSingle#digi" + i).unbind('click');
			$("div.indicatorSingle#digi" + i).click(function(){
				for(i=1; i <= tb; i++){
					if(this.id == "digi"+i)
					{
						temp=i;
					}
				}
				gotoPage(temp,slideSpeed*1000);
				loopPage=temp;
				currentPage=(temp);
			});
			margin=margin-15;
		}
	
	}
	mainLoop();
}

//--------------------------Main Loop [Function]---------------------------------
	
	function mainLoop(){
		timer = setTimeout(function() { 
			gotoPageLoop(loopPage,slideSpeed*1000); 
		}, delay*1000);
	}

	$('div.wrapper').mouseout(function(){
		mainLoop();
	});

	$('div.wrapper').mouseover(function(){
		clearTimeout(timer);
		timer = null;
		delay=tempDelay;
		firstOn=false;		
	});
	
	$('div.indicator').mouseover(function(){
		clearTimeout(timer);
		timer = null;
		delay=tempDelay;
		firstOn=false;		
	});


});