// JavaScript Document slideshow at homepage

var delay = 50; //set fade speed between message change (in miliseconds)
var stay = 3000;//set time of picture's show time
var scounter = 1;
//var sCaption='<?=$first_caption?>';
var whichOne = 0;
var opacity=100; //opacity
var increase=1; //increase opacity indicator
var decrease=0 ;//decrease opacity indicator
var t;

function $(e){
	return document.getElementById(e);
}

function indicate(){
	//$("indicator").innerHTML= scounter + " / " + y.length;
	//$("picCaption").innerHTML= aCaption[scounter-1];
}
		
function changePic(){
	//change text in display area according to changing fcontent's elements; 	
	scounter=scounter+1;
	if(scounter==fcontent.length+1){
		scounter=1;
	}
	$("fscroller").innerHTML="<img src=" + fcontent[scounter-1] + ">";
	$("aMask").href=mLinks[scounter-1];
	resetButton(scounter);
	//$("picCaption").innerHTML=  aCaption[scounter-1];
	//alert(scounter-1 +' ' +aCaption[scounter-1]);
	indicate();
}

function setOpacity(){
	$("aMask").style.MozOpacity=opacity/100;//for FireFox;
	$("aMask").style.KhtmlOpacity=opacity/100;//for previous version Safari;
	$("aMask").style.opacity=opacity/100;//for browser which support opacity style;
	$("aMask").style.filter = "alpha(opacity=" + opacity + ")";// for IE
	
}

function fadeOut(){
	opacity=opacity - 5;
	setOpacity();
	if(opacity<=0){
		//change picture when opacity equals or smaller than 0
		//changePic();
		t=setTimeout(fadeIn,stay);
	}else{
		t=setTimeout(fadeOut,delay);
	}
}


function fadeIn(){
	opacity=opacity + 5;
	setOpacity();
	if(opacity>=100){
		//fade out then opacity larger than 100
		changePic();
		t=setTimeout(fadeOut,delay);
	}else{
		t=setTimeout(fadeIn,delay);
	}
}

function initialPic(){	
	setOpacity();
	$("fscroller").innerHTML="<img src=" + fcontent[scounter-1] + ">";
	resetButton(scounter);
	t=setTimeout(fadeIn,stay);
	playing.href="#photoGallery";
	indicate();
}

function selPic(n){
	clearTimeout(t);
	scounter=n;
	opacity=0;
	setOpacity();
	$("fscroller").innerHTML="<img src=" + fcontent[counter-1] + ">";
	$("aMask").href=mLinks[scounter-1];
	resetButton(scounter);
	initialPic();
	playing.href="#photoGallery";
}

function start(){
	playing.href="";
	initialPic();
}

function stops(){
	clearTimeout(t);
	playing.href="javascript:initialPic();";
	
}
function resetButton(ind){
	for(ii=1; ii<=fcontent.length; ii++){
		if (ii == ind)
				$("featured_"+ii).src = "../pics/generic/featured_"+ii+"a.gif";
		else $("featured_"+ii).src = "../pics/generic/featured_"+ii+".gif";
	}
}

function changeImages(iid, image){
	$(iid).src = "../pics/generic/"+image;
}

/* function swappic(img_name,img_src){
	document[img_name].src=img_src;
     }*/