/*
	This Javascript file is for shift the photos one by one.
	Author: Calvin Liu
*/
var divId = 0;
var tempElement = null;
var currentElement = null;
var tempSubElement = null;
var currentSubElement = null;
var changeStateElement = null;
var opacity =0;

function moveNext(){
	currentElement = document.getElementById(changeId(divId));
	currentSubElement = document.getElementById(changeSubId(divId));
	tempElement = document.getElementById(changeId(++divId));
	tempSubElement = document.getElementById(changeSubId(divId));
	divId+=2;
	changeStateElement=document.getElementById(changeSubId(divId));
	divId-=2;
	if(!(tempElement||tempSubElement)){
		divId--;
		//onclickFunction.disabled = true;
		return false;
	}
	else if(!changeStateElement){
		currentElement.className = "photoNoDisplay taongaLargePhotoBlock";
		tempElement.className = "photoDisplay taongaLargePhotoBlock";
		tempSubElement.className = "taongaPhoto-left photoSelected photoDisplay";
		currentSubElement.className = "taongaPhoto-left photoDisplay";
	}
	else{
		currentElement.className = "photoNoDisplay taongaLargePhotoBlock";
		tempElement.className = "photoDisplay taongaLargePhotoBlock";
		tempSubElement.className = "taongaPhoto-left photoSelected photoDisplay";
		currentSubElement.className = "taongaPhoto-left photoNoDisplay";
		changeStateElement.className = "taongaPhoto-left photoDisplay";	
	}
	startOpacityUp(changeId(divId));	
}

function movePrev(){
	currentElement = document.getElementById(changeId(divId));
	currentSubElement = document.getElementById(changeSubId(divId));
	tempElement = document.getElementById(changeId(--divId));
	tempSubElement = document.getElementById(changeSubId(divId));
	divId+=3;
	changeStateElement=document.getElementById(changeSubId(divId));
	divId-=3;	
	if(!(tempElement||tempSubElement)){
		divId++;
		//onclickFunction.disabled = true;
		return false
	}
	else if(!changeStateElement){
		currentElement.className = "photoNoDisplay taongaLargePhotoBlock";
		tempElement.className = "photoDisplay taongaLargePhotoBlock";
		tempSubElement.className = "taongaPhoto-left photoSelected photoDisplay";
		currentSubElement.className = "taongaPhoto-left photoDisplay";	
	}
	else{
		currentElement.className = "photoNoDisplay taongaLargePhotoBlock";
		tempElement.className = "photoDisplay taongaLargePhotoBlock";
		tempSubElement.className = "taongaPhoto-left photoSelected photoDisplay";
		divId+=3;
		changeStateElement.className = "taongaPhoto-left photoNoDisplay";
		divId-=3;
		currentSubElement.className = "taongaPhoto-left photoDisplay";		
	}
	startOpacityUp(changeId(divId));	
}

function changeId(id){
	return "taongaPhoto"+id;
}

function changeSubId(id){
	return "smallTaongaPhoto"+id;
}

function setOpacity(id, opacity) {
	opacity = (opacity == 100)?99.999:opacity; 
  	// IE/Win
  	document.getElementById(id).style.filter = "alpha(opacity:"+opacity+")";
  	// Safari<1.2, Konqueror
  	document.getElementById(id).style.KHTMLOpacity = opacity/100; 
  	// Older Mozilla and Firefox
 	document.getElementById(id).style.MozOpacity = opacity/100;
  	// Safari 1.2, newer Firefox and Mozilla, CSS3
  	document.getElementById(id).style.opacity = opacity/100;
}

function opacityup(id, opacity) {
   
   	if (document.getElementById(id).style.visibility !="visible") {
   		document.getElementById(id).style.visibility ="visible";
   	}
   	opacity +=5;
    setOpacity(id, opacity);
    if (opacity < 100) {
       setTimeout("opacityup('"+id+"',"+opacity+");", 20);
    }
    
}

function startOpacityUp(id){
	opacityup(id,0);
}

function doNothing(){	
}

function changeRandomId(id){
	return "taonga_randomImage"+id;
}

var randomId = 0;

function countImages(){
	var count = 0;
	while(document.getElementById(changeRandomId(count))){
		count++;
	}
	return count;
}

function randomToNext(){
	try
	{
		document.getElementById(changeRandomId(randomId)).className="photoNoDisplay";
		randomId++;
		if(randomId == countImages()){
			randomId = 0;
		}
		document.getElementById(changeRandomId(randomId)).className="photoDisplay";
		startOpacityUp(changeRandomId(randomId));
		setTimeout("randomToNext()",10000);
	}
	catch(e){
			
	}
	
}

window.onload = randomToNext;