var galleryId = 'slideshow';
var	gallery;
var	started=0;
var galleryImages;
var currentImage;
var previousImage;
var preInitTimer;
var issetbtn=0;
var rTime2 = 4000;
var fadeEffect = 99;
var fadeIntensity = 5;

function pause(newtime){
	rTime2=newtime;
	hide('pausebtn');
	window.clearTimeout(timer);
	shplaybtn=window.setTimeout("show('playbtn')",6000);
}
function play(newtime){
	fadeIntensity = 5;
	hide('playbtn');
	setTimeout("show('pausebtn')",7000);
	rTime2=newtime;
	currentImage=currentImage;
	galleryImages[previousImage].style.zIndex = 0;
	galleryImages[currentImage].style.zIndex = 5;
	timer=window.setTimeout("crossfade(5)", rTime2);
}
function preInit(){
	if((document.getElementById)&&(gallery=document.getElementById(galleryId))){
		gallery.style.visibility = "hidden";
		if(typeof preInitTimer != 'undefined')clearTimeout(preInitTimer); 
	}else{
		preInitTimer = setTimeout("preInit()",2);
	}
}
function fader(imageNumber,opacity){
	var obj=galleryImages[imageNumber];
	if(obj.style){
		if(obj.style.MozOpacity!=null){
			obj.style.MozOpacity = (opacity/100) - .001;
		}else if(obj.style.opacity!=null){
			obj.style.opacity = (opacity/100) - .001;
		}else if(obj.style.filter!=null){
			obj.style.filter = "alpha(opacity="+opacity+")";
		}
	}
}
function fadeInit(){
	if(document.getElementById(galleryId)){
			galleryImages = new Array;
			var node=gallery.firstChild;
			while(node){
				if(node.nodeType==1)galleryImages.push(node);
				node=node.nextSibling;
			}
			for(i=0;i<galleryImages.length;i++){
				galleryImages[i].style.position='absolute';
				fader(i,0);
			}
			gallery.style.visibility = 'visible';
			currentImage=0;
			previousImage=galleryImages.length-1;
			opacity=100;
			fader(currentImage,100);
			//hide('firstimage');
			if(started==0){
				timer=window.setTimeout("crossfade(100)", 5000);
			}else{
				timer=window.setTimeout("crossfade(100)", rTime2);
			}
	}
}
function crossfade(opacity){
		if(opacity < 100){
			fader(currentImage,opacity);
			opacity += fadeIntensity;
			window.setTimeout("crossfade("+opacity+")", fadeEffect);
		}else{
			fader(previousImage,0);
			previousImage=currentImage;
			currentImage+=1;
			if(currentImage>=galleryImages.length)currentImage=0;
			version=0
			if (navigator.appVersion.indexOf("MSIE")!=-1){
				temp=navigator.appVersion.split("MSIE")
				version=parseFloat(temp[1])
			}
			browserName=navigator.appName;
			browserVer=parseFloat(navigator.appVersion);
			
			if(browserName=="Netscape" && browserVer>=3 && browserVer < 5){
				if(navigator.userAgent.indexOf("Firefox")!=-1){
					galleryImages[previousImage].style.zIndex = 0;
					galleryImages[currentImage].style.zIndex = 5;
				}else if(navigator.userAgent.indexOf("Netscape")!=-1){
					
				}else{
					gallery.style.zIndex=0;
					galleryImages[previousImage].style.zIndex = 0;
					galleryImages[currentImage].style.zIndex = 1;
				}
			}else if(browserName=="Microsoft Internet Explorer"){
				galleryImages[previousImage].style.zIndex = 0;
				galleryImages[currentImage].style.zIndex = 5;
			}else{
				gallery.style.zIndex=0;
				galleryImages[previousImage].style.zIndex = 0;
				galleryImages[currentImage].style.zIndex = 1;
			}
			
			opacity=0;
			if(started==0){
				timer=window.setTimeout("crossfade("+opacity+")",1000);
				started=1;
			}else{
				timer=window.setTimeout("crossfade("+opacity+")", rTime2);
			}
			for(p=1;p<=pages;p++){
				if($('setpic_'+p))$('setpic_'+p).style.color="#000000";
			}
			setim=currentImage;
			if(currentImage==0)setim=pages;
			try{
				if($('setpic_'+setim))$('setpic_'+setim).style.color="#EC008C";
			}catch(e){
				
			}
		}
}
function crossfade2(opacity){
	var obj=$('firstimage');
	if(opacity > 1){
		fader2(opacity);
		opacity -= 5;
		window.setTimeout("crossfade2("+opacity+")",200);
	}else{
		obj.style.display="none";
	}
}
function fader2(opacity){
	var obj=$('firstimage');
	if(obj.style){
		if(obj.style.MozOpacity!=null){
			obj.style.MozOpacity = (opacity/100) - .001;
		}else if(obj.style.opacity!=null){
			obj.style.opacity = (opacity/100) - .001;
		}else if(obj.style.filter!=null){
			obj.style.filter = "alpha(opacity="+opacity+")";
		}
	}
}

function sci(num){
	if(issetbtn==1){
		window.clearTimeout(shplaybtn);
	}else{
		if(num > 2){
			num=num-1;
		}else{
			num=num
		}
	}
	
	rTime2=1000000;
	hide('pausebtn');
	window.clearTimeout(timer);
	shplaybtn=window.setTimeout("show('playbtn')",6000);
	issetbtn=1;
	
	if(num>1){
		currentImage=(num-1);
	}else{
		currentImage=0;
	}
	
	galleryImages = new Array;
	var node=gallery.firstChild;
	while(node){
		if(node.nodeType==1)galleryImages.push(node);
		node=node.nextSibling;
	}
	
	for(p=0;p<pages;p++){
		galleryImages[p].style.zIndex = 0;
		$('setpic_'+(p+1)).style.color="#000000";
	}
	
	$('setpic_'+num).style.color="#EC008C";

	fadeIntensity = 10;
	crossfade(1);
}
