//the counters for each photo block
indexes = {"block1" : 0, "block2": 0, "block3": 0, "block4": 0, "block5": 0, "block6": 0, "block7" : 0, "block8": 0,
           "block9": 0, "block10": 0, "block11": 0, "block12": 0};

addLoadEvent(function(){
	// declare each photo block to fade with specific times
	setTimeout("fadeInOut('block2', 8000, 'in')", 12000);
	setTimeout("fadeInOut('block4', 5000, 'in')", 1500);
	setTimeout("fadeInOut('block5', 4000, 'in')", 18000);
	setTimeout("fadeInOut('block7', 10000, 'in')", 5000);
	setTimeout("fadeInOut('block10', 5000, 'in')", 3000);
	setTimeout("fadeInOut('block12', 7000, 'in')", 0);
}
)

function fadeInOut(containerId, waitTime, direction){
    if (!document.getElementById(containerId)) return;
	var container = document.getElementById(containerId);
	if (!container.getElementsByTagName('img')) return;
	var images = container.getElementsByTagName('img');	
	var i = indexes[containerId];
	
	if (direction == 'in'){
		opacity(images[i], 0, 100, 3, 120, 1);	
		setTimeout("fadeInOut('"+containerId+"','"+waitTime+"','out')", 4600);
	}
	else if (direction == 'out'){
		opacity(images[i], 100, 0, 8, 140, 1);	
		indexes[containerId] = (i + 1) % images.length;
		setTimeout("fadeInOut('"+containerId+"','"+waitTime+"','in')", waitTime);
	}
}
function opacity(image, opacStart, opacEnd, steps, intervals, powr){
    if (image.fading) window.clearInterval(image.fading);
    var thisStep = 0;
    image.fading = setInterval(fade, intervals);
     function fade(){
            image.currentOpacity =  easeInOut( opacStart, opacEnd, steps, thisStep, powr);
            image.style.opacity = (image.currentOpacity / 100);
            image.style.MozOpacity = (image.currentOpacity / 100);
            image.style.KhtmlOpacity = (image.currentOpacity / 100);
            image.style.filter = "alpha(opacity=" + image.currentOpacity + ")";
            thisStep++;
            if (thisStep > steps) window.clearInterval(image.fading);
     }
     
}
//generic value churner by Hesido (wwww.hesido.com)
function easeInOut( opacStart, opacEnd, steps, thisStep, powr ){
     var NumDifference = opacEnd - opacStart;
     var increaseStepAmt = opacStart + (Math.pow((( 1 / steps ) * thisStep), powr ) * NumDifference );
     return Math.ceil(increaseStepAmt);
}

/*
// moving text function

function prepareMovingText(){
    if(!document.getElementById('yesImg')){ return;}
    var yesText = document.getElementById('yesImg');
    yesText.style.left = "-200px";
    yesText.style.top = "0px";
    moveElement(yesText.getAttribute('id'), 310, 0, 60);    
    
    if(!document.getElementById('optionImgBot')){ return;}
    var optionText = document.getElementById('optionImgBot');
    optionText.style.left = "646px";
    optionText.style.top = "754px";
    moveElement(optionText.getAttribute('id'), 136, 754, 60);
}

var movement;
function moveElement(elementID, final_x, final_y, interval) {
  var elem = document.getElementById(elementID);
  

//  if (elem.movement){
//      clearTimeout(elem.movement);
 // }

  var xpos = parseInt( elem.style.left );
  var ypos = parseInt( elem.style.top );
  if ( xpos == final_x && ypos == final_y ) {
    return true;
  }
  if (xpos < final_x) { xpos += 5; }
  if (xpos > final_x) { xpos -=5; }
  if (ypos < final_y) { ypos += 5; }
  if (ypos > final_y) { ypos -=5; }

  elem.style.left = xpos + "px";
  elem.style.top = ypos + "px";

  var repeat = "moveElement('"+elementID+"',"+final_x+","+final_y+","+interval+")";
  movement = setTimeout(repeat, interval);
}
*/
