var rotate_delay = 4000; // delay in milliseconds (5000 = 5 secs)
var no_images_display_per_slide = 5;
var current = 0;
function isSlideShowing(){
	return document.slideform.slidebutton.value=='Stop'
}

function AutoStart(text) {

document.slideform.slidebutton.value = (text == "Stop") ? "Start" : "Stop";
rotate();

}


function rotate() {

       if (isSlideShowing()) {
          current = (current == document.slideform.slide.length-1) ? 0 : parseInt(current)+1;          
	  putBigImg(current);	         
          window.setTimeout("rotate()", rotate_delay);

       }

}

function startSlideShow(text){
         AutoStart(text);
	if(document.getElementById('play-button'))
		document.getElementById('play-button').style.display="none";
	if(document.getElementById('pause-button'))
		document.getElementById('pause-button').style.display="inline";
	if(document.getElementById('stop-button'))
		document.getElementById('stop-button').style.display="inline";

	//disable next & preview scroll button
	document.getElementById('previousScrollButton').innerHTML='<img src="/system/layout/images/prev-disable.png" />';
	document.getElementById('nextScrollButton').innerHTML='<img src="/system/layout/images/next-disable.png" />';
	
	//change heading  label events
	if(document.getElementById('slideShowHeading'))
		document.getElementById('slideShowHeading').innerHTML = '<a href="#" onClick="return stopSlideShow(\'Stop\');" >Slide Show:</a>';
        return false;
}

function pauseSlideShow(text){
         AutoStart(text);
	if(document.getElementById('play-button'))
		document.getElementById('play-button').style.display="inline";
	if(document.getElementById('pause-button'))
		document.getElementById('pause-button').style.display="none";
        return false;
}

function stopSlideShow(text){
     AutoStart(text);
	 //disable previous image
	 document.getElementById("show_lightbox_"+current).style.display='none';
     current = 0;	
	 //show first image & it's caption
	 document.getElementById("show_lightbox_"+current).style.display='block';
	if(document.getElementById("image_caption"))
	 	document.getElementById("image_caption").innerHTML = document.slideform.slide[current].text;
    //document.images.show.src = document.slideform.slide[current].value;
       // makeSelectedImg(current);
	//scroll automatically
		//autoScroll();
	if(document.getElementById('play-button'))
		document.getElementById('play-button').style.display="inline";
	/* if(document.getElementById('pause_button'))
		document.getElementById('pause_button').style.display="none"; */
	if(document.getElementById('stop-button'))
		document.getElementById('stop-button').style.display="none";
	//enable next & preview scroll button
	document.getElementById('previousScrollButton').innerHTML='<a href="javascript:void(0)" onclick="return scrollPrev()" ><img src="/system/layout/images/prev.png" alt="Vorherige" title="Vorherige" /></a>';
	document.getElementById('nextScrollButton').innerHTML='<a href="javascript:void(0)" onclick="return scrollNext()"><img src="/system/layout/images/next.png" alt="Vorwärts" title="Vorwärts" /></a>';

	//change heading  label events
	if(document.getElementById('slideShowHeading'))
		document.getElementById('slideShowHeading').innerHTML = '<a href="javascript:void(0)" onClick="return startSlideShow(\'Start\');" >Slide Show:</a>';
        
        return false;
}

//scrolling
var ThumbScrollPosition=0;

function putBigImg(thumb_id){
	
	if(thumb_id >= document.slideform.slide.length){
		thumb_id = document.slideform.slide.length-1;
		
	}
	/*
		//old fashion
	//change image src path
	//document.getElementById("show").src= ''+document.slideform.slide[thumb_id].value+'';
	
	//change href & tile for lighbox
	//document.getElementById('show_lightbox').href=''+document.slideform.bigslide[thumb_id].value+'';
	//document.getElementById('show_lightbox').title=''+document.slideform.bigslide[thumb_id].text+'';
	*/
	//new fashion
	//hide all
	for(i=0; i<document.slideform.slide.length; i++)
		document.getElementById("show_lightbox_"+i).style.display='none';
	//show one selected
	document.getElementById("show_lightbox_"+thumb_id).style.display='block';
	
	//change image caption
	if(document.getElementById("image_caption"))
		document.getElementById("image_caption").innerHTML = document.slideform.slide[thumb_id].text;
	current = thumb_id;
	
	//find selected class & change it to opacity        
      /*  makeSelectedImg(thumb_id); */

	
	return false;
}
function scrollNext(){
	if((Math.ceil(document.slideform.slide.length/no_images_display_per_slide)-1) > (ThumbScrollPosition)){ 
		ThumbScrollPosition++;
		document.getElementById("scroller").style.marginLeft=(-1*(ThumbScrollPosition*600))+"px";
		jQuery('#nextScrollButton img').attr('src','/system/layout/images/next.png');
		jQuery('#previousScrollButton img').attr('src','/system/layout/images/prev.png');

		if(!isSlideShowing())
			putBigImg((ThumbScrollPosition*5));
	}
	
	 if((Math.ceil(document.slideform.slide.length/no_images_display_per_slide)-1) <= (ThumbScrollPosition)){ 
		jQuery('#nextScrollButton img').attr('src','/system/layout/images/next-disable.png');
	}
	
	return false;
}

function scrollPrev(){	
	if(ThumbScrollPosition >0 ){ 
		ThumbScrollPosition--;
		document.getElementById("scroller").style.marginLeft=(-1*(ThumbScrollPosition*600))+"px";
		jQuery('#nextScrollButton img').attr('src','/system/layout/images/next.png');
		jQuery('#previousScrollButton img').attr('src','/system/layout/images/prev.png');
		if(!isSlideShowing())
		putBigImg((ThumbScrollPosition*5));
	}
	if(!ThumbScrollPosition >0 ){ 
		jQuery('#previousScrollButton img').attr('src','/system/layout/images/prev-disable.png');
	}

	return false;
}

/* function makeSelectedImg(thumb_id){
	//store the pointer for selected image
	document.slideform.slide.selectedIndex = thumb_id;
	
	//make all of the images to not selected (class opacity) 
	for(i=0; i<document.slideform.slide.length; i++){
		document.getElementById('thumb_img_'+i).className="scrolling_img opacity";
	}
	
	//change the class for selected image
	document.getElementById('thumb_img_'+thumb_id).className="scrolling_img selected";

	if (isSlideShowing()) {
		//scroll automatically
		autoScroll();
	}
}


Scroll automatically to show the selected thumbnail image if it is in the overflow hidden window
*/
function autoScroll(){
	//if it is not the starting image
	if(current >0){
		if((current % no_images_display_per_slide) == 0){
			scrollNext();
		}
	}
	else{
		//make start image selected
		ThumbScrollPosition =0;
		document.getElementById("scroller").style.marginLeft=(-1*(ThumbScrollPosition*590))+"px";
	}
	
}




