// JavaScript Document
function enter_gallery(){
	setTimeout("begin_play()",3000);
}
function begin_play(){
	if(document.play_status!="play") {   //disable play button if already playing
	document.play_status="play";
	document.getElementById('play_but').src="common/play_but_over.jpg";
	document.getElementById('pause_but').src="common/pause_but.jpg";
	play();
	}
	
}

function play(){
	
	if (document.play_status=="stop") 	document.play_status="reset";		
	else {
		document.play_status="play";
		
		var next_thumb=document.thumb_on;
		var gallery=document.getElementById("gallery_cont");
		var aImg=gallery.getElementsByTagName("IMG");
		if (!document.thumb_on) document.thumb_on=aImg[0];
		for (var i=0;aImg[i]!=document.thumb_on;i++) {}
		if (aImg[i+1]) switch_main(aImg[i+1]);
		else switch_main(aImg[0]);
		
		
		setTimeout("play()",5000);
	}
}

function pause(){
	if (document.play_status=="play") {
		document.play_status="stop";
		document.getElementById('pause_but').src="common/pause_but_over.jpg";
		document.getElementById('play_but').src="common/play_but.jpg";
	}
}
function back(){
	pause();
	var gallery=document.getElementById("gallery_cont");
	var aImg=gallery.getElementsByTagName("IMG");
	if (!document.thumb_on) document.thumb_on=aImg[0];
	for (var i=0;aImg[i]!=document.thumb_on;i++) {}
	if (i>>0) switch_main(aImg[i-1]);
	else switch_main(aImg[aImg.length-1]);
}
function forward(){
	pause();	
	var gallery=document.getElementById("gallery_cont");
	var aImg=gallery.getElementsByTagName("IMG");
	if (!document.thumb_on) document.thumb_on=aImg[0];
		
	for (var i=0;aImg[i]!=document.thumb_on;i++) {}
	if (aImg[i+1]) switch_main(aImg[i+1]);
	else switch_main(aImg[0]);
}

function switch_main(thumb){
			
			var src=thumb.src;
			var main=document.getElementById("main_photo");
			if(main.filters[0]!=null)main.filters[0].apply();
			main.src=src;
			if(main.filters[0]!=null)main.filters[0].play();
			var title_and_disclaimer = thumb.getAttribute('alt');
			var atitle_and_disclaimer= title_and_disclaimer.split("||");
			var title=atitle_and_disclaimer[0];
			var disclaimer=atitle_and_disclaimer[1];
			
			var text=document.getElementById("text");
			if(!text.firstChild) {/*child won't exist if there is no title for first pic */
					var new_node= document.createTextNode(""); 
					text.appendChild(new_node);
			}
			text.firstChild.nodeValue=title; 
			
			var disclaimer_text=document.getElementById("disclaimer");
			if(!disclaimer_text.firstChild) {/*child won't exist if there is no disclaimer for first pic */
					var new_node= document.createTextNode(""); 
					disclaimer_text.appendChild(new_node);
			}
			disclaimer_text.firstChild.nodeValue=disclaimer; 
			
			thumb_on(thumb);
}
function thumb_on(thumb){
			if (document.thumb_on) {
				var old_thumb=document.thumb_on;
				old_thumb.style.borderColor="#F7E2B5";
			}
			thumb.style.borderColor="#785A34";
			document.thumb_on=thumb;
			}
			