/**
 * Boson home page JS
 *
 *
 */

var portfolioImages = 9;
var portfolioStopWatch = 1; // the current element
var portfolioPauseLength = 8000;
var portfolioMoveTime = 7.0;
var portfolioMoveDistance = new Array(-170, 0); // top, left

var whatWeDoList = 5
var whatWeDoStopWatch = 1; // the current element
var whatWeDoPauseLength = 5000;

var whatsNewList = 3
var whatsNewStopWatch = 1; // the current element
var whatsNewPauseLength = 5000;

function startPausing(){
  if(portfolioStopWatch<=portfolioImages){
    window.setTimeout("startPausing()",portfolioPauseLength);
    //alert("Loop iteration "+portfolioStopWatch+ " out of 5");
    
  		
		var toShowP = 'portfolio-' + portfolioStopWatch;
		var toHideP = 'portfolio-' + (portfolioStopWatch-1);
		if (portfolioStopWatch == 1) {
			toHideP = 'portfolio-' + portfolioImages;
		}
		//alert ("Hide: "+ toHide + " Reveal: " + toShow);
		showPortfolio(toShowP,toHideP);
		
		
    portfolioStopWatch++;
    // reset the stopwatch if we're at the end of the list
    if (portfolioStopWatch > portfolioImages) {
    	portfolioStopWatch = 1    	
    }
  }
}

function showPortfolio(toShowP,toHideP) {	
	
	var toMove = toShowP+"-image";
	
	// reposition the layer to it's original state	
	thisDiv = document.getElementById(toMove);
	if(thisDiv!=null) {
		thisDiv.style.left=0
		thisDiv.style.top=0
	}
	
	showDiv(toShowP,toHideP);
	
	// fade the layer in
	$(toShowP).appear();	
	
	// start moving the layer
	new Effect.Move(toMove, { x: portfolioMoveDistance[1], y: portfolioMoveDistance[0], duration: portfolioMoveTime, mode: 'relative'});


	/*
	

	new Effect.Move(toMove, {
	  x: portfolioMoveDistance[1], y: portfolioMoveDistance[0], duration: portfolioMoveTime, mode: 'relative', 
	  transition: Effect.Transitions.linear 
	});

	//$(toHideP).fade();
	*/
	
}

function startWhatWeDo(){
  if(whatWeDoStopWatch<=whatWeDoList){
    window.setTimeout("startWhatWeDo()",whatWeDoPauseLength);
  		
		var toShowW = 'what-we-do-' + whatWeDoStopWatch;
		var toHideW = 'what-we-do-' + (whatWeDoStopWatch-1);
		if (whatWeDoStopWatch == 1) {
			toHideW = 'what-we-do-' + whatWeDoList;
		}
		//alert ("Hide: "+ toHide + " Reveal: " + toShow);
		showDiv(toShowW,toHideW);
		
		
    whatWeDoStopWatch++;
    // reset the stopwatch if we're at the end of the list
    if (whatWeDoStopWatch > whatWeDoList) {
    	whatWeDoStopWatch = 1    	
    }
  }
}

function startWhatsNew(){
  if(whatsNewStopWatch<=whatsNewList){
  	//alert("here");
    window.setTimeout("startWhatsNew()",whatsNewPauseLength);
  		
		var toShowWN = 'whats-new-' + whatsNewStopWatch;
		var toHideWN = 'whats-new-' + (whatsNewStopWatch-1);
		if (whatsNewStopWatch == 1) {
			
			toHideWN = 'whats-new-' + whatsNewList;
			//alert(toHideWN);
		}
		
		
		showDiv(toShowWN,toHideWN);
		//alert("Hide: "+ toHideWN + " Reveal: " + toShowWN);
		
    whatsNewStopWatch++;
    // reset the stopwatch if we're at the end of the list
    if (whatsNewStopWatch > whatsNewList) {
    	whatsNewStopWatch = 1    	
    }
  }
}

function showDiv(toShow,toHide) {	
	
	if(toShow!=null) {
		// fade the layer in
		$(toShow).appear();	
	}
	if(toHide!=null) {
		// fade the old layer out
		$(toHide).fade();
	}
}


