var rotate_delay = 4000; // delay in milliseconds (5000 = 5 secs)
var no_images_display_per_slide = 4;
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/previous_disable.gif" />';
	document.getElementById('nextScrollButton').innerHTML='<img src="/system/layout/images/next_disable.gif" />';
	
	//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/previous.gif" alt="Vorherige" title="Vorherige" /></a>';
	document.getElementById('nextScrollButton').innerHTML='<a href="javascript:void(0)" onclick="return scrollNext()"><img src="/system/layout/images/next.gif" 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*445))+"px";
		if(!isSlideShowing())
			putBigImg((ThumbScrollPosition*no_images_display_per_slide));
	}
	
		
	return false;
}

function scrollPrev(){
	
	if(ThumbScrollPosition >0 ){ 
		ThumbScrollPosition--;
		document.getElementById("scroller").style.marginLeft=(-1*(ThumbScrollPosition*445))+"px";
		if(!isSlideShowing())
		putBigImg((ThumbScrollPosition*no_images_display_per_slide));
	}
	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*445))+"px";
	}
	
}

//enable lighbox effect
jQuery(document).ready(function() {
	if(jsLang == 'en'){
				x= { image: 'Image ' , of : ' of ' , prevLinkText: '&laquo;  Previous' , nextLinkText : 'Next &raquo;',
							closeTitle : 'Image Gallery', prevLinkTitle : 'Prev Image', nextLinkTitle : 'Next Image',printThis: 'Print',
							sendAFriend: 'E-Mail to a friend'

							}
				}else{
				x= { image: 'Bild ' , of : ' von ' , prevLinkText: '&laquo;  Zur&uuml;ck' , nextLinkText : 'Weiter &raquo;',
							closeTitle : 'Schließen Bildergalerie', prevLinkTitle : 'vorheriges Bild', nextLinkTitle : 'nächstes Bild'
							,printThis: 'Druckansicht',
							sendAFriend: 'E-Mail einem Freund'

							}
				}



jQuery(".lightbox-2").lightbox({
			    fitToScreen: true,
				fileLoadingImage: '/system/layout/images/ajax_loader.gif',
				fileBottomNavCloseImage: '/system/layout/images/close.gif',
				strings: x
				});
});