//Default values, these can be changed in the code of the page calling this script
var Pic = new Array();
var Width = new Array();
var Height= new Array();
var PicText = new Array();
var preLoad = new Array();

var slideShowSpeed = 6000;
var crossFadeDuration = 3;
var t;
var p;
var j = 0;
var direction = 1;

function checkMSIE(ver){		var useragent = navigator.userAgent;
	var pos = useragent.indexOf('MSIE');
	var bVer = 0
	if (pos > -1) {
		bVer = useragent.substring(pos + 5);
		var pos = bVer.indexOf(';');
		bVer = bVer.substring(0,pos);
	}
	if ((pos > -1) && (bVer >= ver))		return true	else		return false}


function initSlideShow() {
	p = Pic.length;									
	for (i = 0; i < p; i++) {
		preLoad[i] = new Image();
		preLoad[i].src = Pic[i];
	}
	if (checkMSIE(5)){								
			j=0
			SlideControl.style.visibility="visible";
			t = setTimeout('runSlideShow()', 3000);
		}
		else 
			showstatic()	
}

function setspeed(change){
	if(change<1){
		slideShowSpeed = slideShowSpeed + (1000 * (-1 * change))
		crossFadeDuration = crossFadeDuration + (-1 * (change/2))
		clearTimeout(t)
		if(slideShowSpeed>=2000)
			t = setTimeout('runSlideShow()', slideShowSpeed-2000);	
		else													
			runSlideShow()
	}
	if(change>=1 && slideShowSpeed > 1000){
		slideShowSpeed = slideShowSpeed - (1000 * change)
		crossFadeDuration = crossFadeDuration - (change/2)
		clearTimeout(t)
		if(slideShowSpeed>=2000)
			t = setTimeout('runSlideShow()', slideShowSpeed-2000);	
		else
			runSlideShow()
	}
}

function setdirection(val){
	direction=val
}
function checkdirection(){
	if (direction==1){
		j = j + 1;
		if (j > (p - 1)) j = 0;
		runshow=true
	}
	else{
		if (direction==-1){
			j = j - 1;
			if (j < 0) j = p - 1;
			runshow=true
		}
		else{
			runshow=false
			clearTimeout(t)
			}
	}																								
return runshow
}								

function runSlideShow() {
	var eventnumber;

	eventnumber=Math.round(Math.random()*24)
	if (checkdirection()){
		if (eventnumber==24)
			FadeTransition()
		else
			PlayTransition(eventnumber)
	}									
													
	t = setTimeout('runSlideShow()', slideShowSpeed);
	
		
}

function showstatic(){
	//errortext.style.visibility="visible"
}


function FadeTransition(){
var s;
	if (document.all) {
		document.images.SlideShow.style.filter="blendTrans(duration=2)";
		document.images.SlideShow.filters.blendTrans.duration=crossFadeDuration;
		document.images.SlideShow.filters.blendTrans.Apply();
	}											

	document.images.SlideShow.src = preLoad[j].src;
	document.images.SlideShow.width=preLoad[j].width;
	document.images.SlideShow.height=preLoad[j].height;

	document.images.SlideShow.hspace=(showsize-Width[j])/2;
	document.images.SlideShow.vspace=(showsize-Height[j])/2;												

	if (document.all) {
		document.images.SlideShow.filters.blendTrans.Play();
	}
	
}
										
function PlayTransition(tnum){
	C1.filters[0].Apply();


	C1.style.visibility = "hidden";
	C1.filters.revealTrans.transition=tnum;
	C1.filters[0].Play();    

	document.images.SlideShow.src = preLoad[j].src;
	document.images.SlideShow.width = Width[j];
	document.images.SlideShow.height = Height[j]; 
	Description.innerHTML=PicText[j];


	document.images.SlideShow.hspace=(showsize-Width[j])/2
	document.images.SlideShow.vspace=(showsize-Height[j])/2
	
	C1.style.visibility = "visible";
	C1.filters.transition=tnum;
	C1.filters[0].duration=crossFadeDuration
	C1.filters[0].Play();        
}

function showprevious(){
	if (j==0)
		j=Pic.length-1
	else
		j=j-1

	document.images.SlideShow.src = preLoad[j].src;
	document.images.SlideShow.width = Width[j];
	document.images.SlideShow.height =Height[j]; 
	Description.innerHTML=PicText[j];


	document.images.SlideShow.hspace=(showsize-Width[j])/2
	document.images.SlideShow.vspace=(showsize-Height[j])/2

}

function shownext() {							
	if (j==Pic.length-1)
		j=0
	else
		j=j+1
	
	document.images.SlideShow.src = preLoad[j].src;
	document.images.SlideShow.width = Width[j];
	document.images.SlideShow.height = Height[j]; 
	Description.innerHTML=PicText[j];


	document.images.SlideShow.hspace=(showsize-Width[j])/2
	document.images.SlideShow.vspace=(showsize-Height[j])/2
	
}
