// JavaScript Document

var cslide= 0;
var current_opacity= 0;
var continue_slideshow= 'no';

function setShowHeight(high) {
	show_obj= document.getElementById('slide_block');
	new_height= (high + 100) + 'px';
	show_obj.style.height= new_height;
} //end of function

function moveSlide(index) {
	photo_obj= document.getElementById('slide_image');
	caption_obj= document.getElementById('slide_caption');
	
	//If slideshow not active, check if buttons need disabling
	if (continue_slideshow != 'yes')
		{
			disableButtonCheck(index);
		}
		
	if (photo_obj.getAttribute('src')== '')
		{
			//Nothing to fade-out/erase
			photo_info= slideData(index);
			placeSlide(photo_info,photo_obj,caption_obj);
			//Update cslide
			cslide= index;
			//Update current slide number
			jsChangeNodeText('slide_count',(cslide+1));
			//Start fade-in
			current_opacity= 10;
			photoFadeIn(photo_obj,caption_obj);
		}
	else
		{
			if (current_opacity > 0)
				{
					photoFadeOut(photo_obj,caption_obj,index);
				}
			else
				{
					photo_info= slideData(index);
					placeSlide(photo_info,photo_obj,caption_obj);
					//Update cslide
					cslide= index;
					//Update current slide number
					jsChangeNodeText('slide_count',(cslide+1));
					//Start fade-in
					current_opacity= 10;
					photoFadeIn(photo_obj,caption_obj);
				}
		}
} //end of function


function disableButtonCheck(index) {
	
	first_obj= document.getElementById('btn_first');
	previous_obj= document.getElementById('btn_previous');
	next_obj= document.getElementById('btn_next');
	last_obj= document.getElementById('btn_last');
	
	if (index== 0)
		{
			first_obj.setAttribute("disabled","disabled");
			previous_obj.setAttribute("disabled","disabled");
			next_obj.removeAttribute("disabled");
			last_obj.removeAttribute("disabled");
		}
	else if (index== (pArray.length-1))
		{
			next_obj.setAttribute("disabled","disabled");
			last_obj.setAttribute("disabled","disabled");
			first_obj.removeAttribute("disabled");
			previous_obj.removeAttribute("disabled");
		}
	else
		{
			first_obj.removeAttribute("disabled");
			previous_obj.removeAttribute("disabled");
			next_obj.removeAttribute("disabled");
			last_obj.removeAttribute("disabled");
		}
	
} //end of function

function slideData(index) {
	photodata= pArray[index].split("|");
	return photodata;
} //end of function

function placeSlide(photo_info,photo_obj,caption_obj) {
	setOpacity(photo_obj,0);
	//Firefox applies opacity to text, but IE does not.
	//setOpacity(caption_obj,0);
	setTextFade(caption_obj,0);
	photo_obj.setAttribute("src",photo_info[0]);
	photo_obj.setAttribute("alt",photo_info[1]);
	jsChangeNodeText("slide_caption",photo_info[1]);
} //end of function


function setOpacity(obj, opacity) {
	//alert("obj.id is " + obj.id);
  	//alert("opacity is " + opacity);
	opacity = (opacity == 100)?99.999:opacity;
  
 	 // IE/Win
  	obj.style.filter = "alpha(opacity:"+opacity+")";
  
  	// Safari<1.2, Konqueror
  	obj.style.KHTMLOpacity = opacity/100;
  
  	// Older Mozilla and Firefox
  	obj.style.MozOpacity = opacity/100;
  
  	// Safari 1.2, newer Firefox and Mozilla, CSS3
  	obj.style.opacity = opacity/100;
} //end of function

function photoFadeIn(photo_obj,caption_obj) {
	setOpacity(photo_obj,current_opacity);
	//Firefox applies opacity to text, but IE does not.
	//setOpacity(caption_obj,current_opacity);
	setTextFade(caption_obj,current_opacity);
	if (current_opacity < 100)
		{
			current_opacity= current_opacity+10;
			setTimeout("photoFadeIn(photo_obj,caption_obj)",25);
		}
} //end of function


function photoFadeOut(photo_obj,caption_obj,index) {
	setOpacity(photo_obj,current_opacity);
	//Firefox applies opacity to text, but IE does not.
	//setOpacity(caption_obj,current_opacity);
	setTextFade(caption_obj,current_opacity);
	if (current_opacity > 0)
		{
			current_opacity= current_opacity-10;
			setTimeout("moveSlide(" + index + ")",25);
		}
} //end of function


function setTextFade(caption_obj,opacity) {
	
	if (opacity== 100)
		{
			caption_obj.style.color= "rgb("+visible_r+","+visible_g+","+visible_b+")";		
		}
	else if (opacity== 0)
		{
			caption_obj.style.color= "rgb("+invisible_r+","+invisible_g+","+invisible_b+")";
		}
	else
		{
			new_r= (153-(parseInt(opacity)+5) + visible_r);
			new_g= (153-(parseInt(opacity)+5) + visible_g);
			new_b= (102-(parseInt(opacity)) + visible_b);
			caption_obj.style.color= "rgb("+new_r+","+new_g+","+new_b+")";
		}
	
} //end of function

function initializeStartShow(index) {
	continue_slideshow='yes';
	
	first_obj= document.getElementById('btn_first');
	previous_obj= document.getElementById('btn_previous');
	next_obj= document.getElementById('btn_next');
	last_obj= document.getElementById('btn_last');
	endshow_obj= document.getElementById('btn_endshow');
	startshow_obj= document.getElementById('btn_startshow');
	
	startshow_obj.setAttribute("disabled","disabled");
	first_obj.setAttribute("disabled","disabled");
	previous_obj.setAttribute("disabled","disabled");
	next_obj.setAttribute("disabled","disabled");
	last_obj.setAttribute("disabled","disabled");
	
	endshow_obj.removeAttribute("disabled");
	
	startShow(index);
	
} //end of function


function startShow(index) {
	
	if (continue_slideshow== 'yes')
		{
			if (index > (pArray.length-1))
				{
					goto_slide= 0;
				}
			else
				{
					goto_slide= index;
				}
				
			moveSlide(goto_slide);
			next_slide= goto_slide+1;
			setTimeout("startShow(next_slide)",5000);
		}
	
} //end of function


function endShow(index) {
	continue_slideshow= 'no';
	//moveSlide(index);
	
	photo_obj= document.getElementById('slide_image');
	caption_obj= document.getElementById('slide_caption');
	
	first_obj= document.getElementById('btn_first');
	previous_obj= document.getElementById('btn_previous');
	next_obj= document.getElementById('btn_next');
	last_obj= document.getElementById('btn_last');
	endshow_obj= document.getElementById('btn_endshow');
	startshow_obj= document.getElementById('btn_startshow');
	
	startshow_obj.removeAttribute("disabled");
	first_obj.removeAttribute("disabled");
	previous_obj.removeAttribute("disabled");
	next_obj.removeAttribute("disabled");
	last_obj.removeAttribute("disabled");
	
	endshow_obj.setAttribute("disabled","disabled");
	
	current_opacity= 100;
	photoFadeIn(photo_obj,caption_obj);
	
	
} //end of function

