var thumbs = new Array();
var filedir="fred";
var playstat=1;
var thisslide=1;
var maxi=5;
var thisloc;
var waiting=0;
var she=426;
var swi=640;
var pagetype=0 //0=home/contact, 1=pano, 2=slide
var SlideNo;
var Op;

function fittopage() {
		pagetype=0 //home/contact
		if (document.getElementById("thumbs")) {
			pagetype=1; //pano
			if(document.getElementById("slide")) {
				pagetype=2; //slide
			}
		}
		var he=GetHeight();
		var wi=GetWidth();

		if(pagetype>0){
			h=he-110;
			a=h+"px";
			document.getElementById("thumbs").style.height = a;
		}
		
		if(pagetype>0){
			h=300;
		}else{
			h=0;
		}
		a=h+"px";
		document.getElementById("title").style.left = a;
		document.getElementById("slidecont").style.left = a;

		if(pagetype>0){
			h=wi-300;
		}else{
			h=wi;
		}
		a=h+"px";
		document.getElementById("title").style.width = a;
		document.getElementById("slidecont").style.width = a;
		
		h=he-90;
		a=h+"px";
		document.getElementById("nav").style.top = a;
	
// do slide		
		if (pagetype==2){
			var maxheight = he-170;
			if (maxheight < 100) { maxheight = 100; }
			var maxwidth = wi - 370;
			if (maxwidth < 100) {	maxwidth = 100; }
	
			h=she;
			b=swi;
			var r = h/b;
	
			if (h>maxheight) {
				h = maxheight;
				b = h/r;
			}
	
			if (b>maxwidth) {
				b = maxwidth;
				h = b*r;
			}
	
			document.getElementById("slide").height=h;
			document.getElementById("slide").width=b;
			h=h+50;
		}else if(pagetype==1){
			h=480;
		}else{
			h=300;
		}
		a=h+"px";
		document.getElementById("slidecont").style.height=a;
		var h1=(he-h-30)/2;
		if(h1<60){h1=60};
		a=h1+"px";
		document.getElementById("slidecont").style.top=a;
}

function GetHeight() {
	if( ( typeof( window.innerHeight ) == 'number' ) && (window.innerHeight > 0 ) ) {
		//Non-IE
		height = window.innerHeight;
	} else if( (document.documentElement) && (document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		height = document.documentElement.clientHeight;
	} else if( (document.body) && (document.body.clientHeight ) ) {
		//IE 4 compatible
		height = document.body.clientHeight;
	}
	return height;
}

function GetWidth() {
	if( ( typeof( window.innerWidth ) == 'number' ) && (window.innerWidth > 0 ) ) {
		//Non-IE
		width = window.innerWidth;
	} else if( (document.documentElement) && (document.documentElement.clientWidth ) ) {
		//IE 6+ in 'standards compliant mode'
		width = document.documentElement.clientWidth;
	} else if( (document.body) && (document.body.clientWidth ) ) {
		//IE 4 compatible
		width = document.body.clientWidth;
	}
	return width;
}

function ThumbsOnload(thispage) {
	filedir=thispage;
	maxi=thumbs.length -1;
	for(i=1;i<=maxi;i=i+1) {
		if(thumbs[i][2]=="$comment"){thumbs[i][2]="&nbsp;"}
	}
	thumbshtml = "<table align='center'>";
	for(i=1;i<=maxi;i=i+2) {
		j=i+1;
		if (i==maxi) {
			thumbshtml +="<tr height='95'><td width='95' align='center' colspan='2'><img id='th" + i +"' class='thumbimg' src='#' /></td></tr>";
		}
		else {
			thumbshtml +="<tr height='95'><td width='95' align='center'><img id='th" + i +"' class='thumbimg' src='#' /></td>";
			thumbshtml +="<td width='95' align='center'><img id='th" + j +"' class='thumbimg' src='#' /></td></tr>";
		}
	}
	thumbshtml +="</table>";
	document.getElementById("thumbs").innerHTML = thumbshtml;
	
	for(i=1;i<=maxi;i++) {
		document.getElementById("th"+i).src = thispage+thumbs[i][3];
		document.getElementById("th"+i).title = thumbs[i][2];
		document.getElementById("th"+i).width = thumbs[i][4];
		document.getElementById("th"+i).height = thumbs[i][5];
		onmover = "changeBorder1(this)";
		document.getElementById("th"+i).onmouseover = new Function(onmover); 
		onmout = "changeBorder2(this)";
		document.getElementById("th"+i).onmouseout = new Function(onmout); 
		onc="FadeSlide(" + i + ");pstop()";
		document.getElementById("th"+i).onclick = new Function(onc); 

	}
}

function SetSlide(i){

	thisslide=i;
	if(document.getElementById("slide")) {
		document.getElementById("slide").src=filedir+thumbs[i][1];
		if(thumbs[i][0] == 0){thumbs[i][0]=1};
	}
	else{
		var a='<object width="640" height="480" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">';
		a=a+'<param name="movie" value='
		a=a+filedir+thumbs[i][1];
		a=a+'><embed src=';
		a=a+filedir+thumbs[i][1];
		a=a+' width="640" height="480" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" ></embed></object>'
		document.getElementById("pano").innerHTML=a;
	}
	swi=thumbs[i][6]*1;
	she=thumbs[i][7]*1;
	fittopage();
	var a=thumbs[i][2];
	document.getElementById("info").innerHTML=a;
}

function FadeSlide(i) {
	if(document.getElementById("slide")) {
		preloadImages(i);
		SlideNo=i;
		Op=90;
		setTimeout("FadeOut()",30);
	}else{
		SetSlide(i)
	}
}

function FadeOut() {
	SetFadeOpacity(Op);
	if (Op > 0) {
		Op -= 10;
		setTimeout("FadeOut()",30);
	}
	else {
		i=SlideNo;
		document.getElementById("slide").src="res/pixel.gif";
		SetSlide(i);
		Op = 10;
		setTimeout("FadeIn()",100);
	}
}

function FadeIn() {
	SetFadeOpacity(Op);
	if (Op < 100) {
		Op += 10;
		setTimeout("FadeIn()",30);
	}
	else {				//end of fade - preload probable next image
		i=SlideNo+1;
		if (i>maxi) {i=1;};
		preloadImages(i);
	}
}

function SetFadeOpacity(O) {

	browserVer=parseInt(navigator.appVersion);
	browserName=navigator.appName;
	if (browserName == "Microsoft Internet Explorer"){
		document.getElementById("slidecont").style.filter = 'alpha(opacity='+O+')';
	} else {
		document.getElementById("slidecont").style.opacity = O/100;
	}
}


function preloadImages(i) {     //borrowed from Photoshop
	if(thumbs[i][0] == 0)
	{
		thumbs[i][0]=1;
		var fil=filedir+thumbs[i][1];
		dnext_01_over = newImage(fil);
	}
}
function newImage(arg) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
}

	
function changeBorder1(item) {
	item.style.borderColor="#FFFFFF";
}
function changeBorder2(item) {
	item.style.borderColor="#000000";
}

function pprev() {
	if (playstat==1) {
		thisslide=thisslide-1;
		if (thisslide<1) {thisslide=maxi;}
		FadeSlide(thisslide);
	}
}

function pnext() {
	if (playstat==1) {
		thisslide=thisslide+1;
		if (thisslide>maxi) {thisslide=1;}
		FadeSlide(thisslide);
	}
}

function pplay() {
	if (playstat==1) {
		setstat(2);
		ppplay();
	}
}

function ppplay() {
	if (playstat==2) {
		thisslide=thisslide+1;
		if (thisslide>maxi) {thisslide=1;}
		FadeSlide(thisslide);
    setTimeout("pppplay()",4000); //4 seconds
		waiting=waiting+1;
	}
}

function pppplay() {
	waiting=waiting-1;
	if(waiting==0){ppplay();}
}
	
function pstop() {
	if (playstat==2) {
		setstat(1);
	}
}

function setstat(i) {
	try
  	{
  //Run some code here

	switch(i){

	case 0:
		playstat=0;
		document.getElementById("cprev").src="res/pixel.gif";
		document.getElementById("cplay").src="res/pixel.gif";
		document.getElementById("cstop").src="res/pixel.gif";
		document.getElementById("cnext").src="res/pixel.gif";
		document.getElementById("cprev").style.cursor="default";
		document.getElementById("cplay").style.cursor="default";
		document.getElementById("cstop").style.cursor="default";
		document.getElementById("cnext").style.cursor="default";
		document.getElementById("cprev").title="";
		document.getElementById("cplay").title="";
		document.getElementById("cstop").title="";
		document.getElementById("cnext").title="";
  	break;
	case 1:
		playstat=1;
		document.getElementById("cprev").src="res/cprev.gif";
		document.getElementById("cplay").src="res/cplay.gif";
		document.getElementById("cstop").src="res/dstop.gif";
		document.getElementById("cnext").src="res/cnext.gif";
		document.getElementById("cprev").style.cursor="pointer";
		document.getElementById("cplay").style.cursor="pointer";
		document.getElementById("cstop").style.cursor="default";
		document.getElementById("cnext").style.cursor="pointer";
		document.getElementById("cprev").title="previous";
		document.getElementById("cplay").title="play slideshow";
		document.getElementById("cstop").title="";
		document.getElementById("cnext").title="next";
  	break;
	case 2:
		playstat=2;
		document.getElementById("cprev").src="res/dprev.gif";
		document.getElementById("cplay").src="res/dplay.gif";
		document.getElementById("cstop").src="res/cstop.gif";
		document.getElementById("cnext").src="res/dnext.gif";
		document.getElementById("cprev").style.cursor="default";
		document.getElementById("cplay").style.cursor="default";
		document.getElementById("cstop").style.cursor="pointer";
		document.getElementById("cnext").style.cursor="default";
		document.getElementById("cprev").title="";
		document.getElementById("cplay").title="";
		document.getElementById("cstop").title="stop";
		document.getElementById("cnext").title="";
		break;
  }
	}
catch(err)
  {
  //Handle errors here
	}
}

function setinfo(a) {
try
 	{
if(a==null){a="&nbsp;";}
	document.getElementById("info").innerHTML=a;
	}
catch(err)
  {
  //Handle errors here
	}
	
}

