// JavaScript Document


/////////////////Safe to Edit Variables are here, at the top///////////////////////

var numberOfPages=6;

var slideSpeed=0.95; 	//Sliding speed of items - in Seconds
var delay=10; 			//Delay between sliding to the next item - in Seconds

var pageImages=new Array(); //Array which stores all slide page images
pageImages[1]="one.jpg";
pageImages[2]="two.jpg";
pageImages[3]="three.jpg";
pageImages[4]="four.jpg";
pageImages[5]="five.jpg";
pageImages[6]="six.jpg";


var pageLinks=new Array(); //Array which stores all slide page links
pageLinks[1]="/content/products/vip/vip.html";
pageLinks[2]="http://oac.okuma.com/lbex";
pageLinks[3]="/content/products/showroom/showroomDetails_g350.html";
pageLinks[4]="/pdf/ge.pdf";
pageLinks[5]="/content/news-and-events/news/news_2009_10_22_okuma.html";
pageLinks[6]="/content/news-and-events/news/news_2009_12_09_emec.html";


/////////////////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
var numberOfPages; //number of pages in ourWork section, including thumbnail page(s)

$(document).ready(function(){

showContent();
showInd();

//--------------------------Build Pages - iFrames [Function]--------------------------------- 

function showContent(){
		for(i=1; i<=numberOfPages; i++){
			if(i==2){
				tempLink = ('<a class="slidingImage" target="_blank" id="slideLink'+i+'" href="'+ pageLinks[i] +'"></a>');
			}
			else{
				tempLink = ('<a class="slidingImage" id="slideLink'+i+'" href="'+ pageLinks[i] +'"></a>');
			}
			tempFrame = ('<div class="slide" style="background-image:url(/images/slides/'+ pageImages[i] +')"></div>');
			$("div#wrapper").append(tempLink);
			$("a.slidingImage#slideLink"+i).append(tempFrame);
		}
}

//--------------------------goto Page [Function]--------------------------------- 

function gotoPage(page,speed){
	  if(page>currentPage)
	  {
		  pagePass=page-currentPage;
		  newPage=pagePass*-980;
		  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*-980;
		  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*-980;
		  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*-980;
		  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=(980-((numberOfPages*10)+((numberOfPages-1)*5)))/2;
		centerInd=10;
		$('div.indicator').css('right',centerInd+'px');
		margin=(numberOfPages-1)*15;
		currentMargin= ((((980-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;		
	});


});