imagePositionInListOfAllImages = 0;
frequency=5000;
slideshow= true;
prevnext = false;
currImageIndxVal=0;
fromGallery=true;
showcaptions=false;
previndex = 0;

function renderSlideShowImage(){

			for(var i=0;i<listOfImages.length;i++)
			{
				eachImage = new Array();
				eachImage = listOfImages[i];

				if(imagePositionInListOfAllImages == i)
				{
					tnImagePath=eachImage.tnImagePath;
					xmlPath = eachImage.detailedXMLPath;
					htmlPath = eachImage.detailedHTMLPath;
					setCookie("galleryDocId", eachImage.documentId, null, "/", null, null);
				}
			}
				
			var detailAssetURL = xmlPath;
			var retVal = false;
			 /* Inner Ajax */
			 
			new Ajax.Request(detailAssetURL,	
			  {
				 asynchronous:false,
				 method:'get',
				 onSuccess: function(transport,myIndex){		
				   retVal = processDetailedRSS(transport.responseXML);		 	   
				},
				onFailure: function(){ 
					//alert('Error Retrieving Source File ...');
					}
			   
			  });	
            


			this.slideshowIndex1 = $('Slideshow_Image_Index_1');
            this.slideshowIndex1.innerHTML= eval(imagePositionInListOfAllImages+1)+" of "+listOfImages.length+" Images";

			this.slideshowIndex2 = $('Slideshow_Image_Index_2');
            this.slideshowIndex2.innerHTML= eval(imagePositionInListOfAllImages+1)+" of "+listOfImages.length+" Images";
             
			previndex=imagePositionInListOfAllImages;
            imagePositionInListOfAllImages=eval(imagePositionInListOfAllImages + 1);

            if(imagePositionInListOfAllImages == listOfImages.length){
                  imagePositionInListOfAllImages = 0;
			}

            this.imageContainer = $('gallery_image_area');

			/*var previousImageButton = this.imageContainer.appendChild(new Element('div',{'className':'btn_image_prev'}).insert(new Element('div',{'className':'btn_arrow_prev'})));
			var nextImageButton = this.imageContainer.appendChild(new Element('div',{'className':'btn_image_next'}).insert(new Element('div',{'className':'btn_arrow_next'})));*/
			var previousImageButton = this.imageContainer.appendChild(new Element('div',{'className':'btn_image_prev'}).insert(new Element('div',{'className':'btn_arrow_prev'})));
			var nextImageButton = this.imageContainer.appendChild(new Element('div',{'className':'btn_image_next'}).insert(new Element('div',{'className':'btn_arrow_next'})));

			Event.observe(previousImageButton,'click',function(){ 
				//prevnext = true;
				if(previndex > 0){
				   imagePositionInListOfAllImages=previndex-1;
				   renderSlideShowImage(); 
				} else if(previndex == 0){
				   imagePositionInListOfAllImages=listOfImages.length-1;
                   renderSlideShowImage(); 
				}
			}.bind(this));
			Event.observe(nextImageButton,'click',function(){ 
				//prevnext=true;
				if(imagePositionInListOfAllImages < listOfImages.length){
					renderSlideShowImage(); 
				} else {
                    imagePositionInListOfAllImages=0;
					renderSlideShowImage(); 
				}
			}.bind(this));
			
			var hideNav = this.imageContainer;
			var prevNav = this.imageContainer.getElementsBySelector('div.btn_image_prev')[0].setStyle({display:'none'});
			var nextNav = this.imageContainer.getElementsBySelector('div.btn_image_next')[0].setStyle({display:'none'});
			
			Event.observe(hideNav,'mouseout',function(){ 
				prevNav.setStyle({display:'none'});
				nextNav.setStyle({display:'none'});
			}.bind(this));
			
			Event.observe(hideNav,'mouseover',function(){ 
				prevNav.setStyle({display:'block'});
				nextNav.setStyle({display:'block'});
			}.bind(this));
            
			 this.captionContainer = $('image_gallery_fullscreen_caption_1');
			 this.container = $('image_gallery');
             var height=this.captionContainer.getHeight();
             var val=0;
			 if(height > 130){
                val=eval(600-height);
				val=eval(val+130);
			 }else{
                val=600;
			 }
             val=val+'px';
             this.captionContainer.setStyle({
					   	'top':val					
			 });             
			 this.container.makePositioned();
			 
			 
			/* if(height > 150){
				 
					 this.captionContainer.setStyle({
					   	position:'absolute',
						top:'350px',
						left:'44px',
						width:'850px',
						padding-left:'5px',
						opacity: '0.9',
						height:'auto', 
						padding-top:'3px',
						display: 'none',
						filter: 'progid:DXImageTransform.Microsoft.Alpha(opacity=90)'
					});

			 }*/
			// alert(this.captionContainer.getHeight());
			 this.captionContainer.makePositioned();
           //alert("imagePositionInListOfAllImages:"+imagePositionInListOfAllImages);
}

function getSlideShowImage(){
  // alert("We are in slide show:"+frequency);
   if(slideshow) {	        
		renderSlideShowImage();
	}
}	

function pauseSlideShow(){
	this.slideshowpause1 = $('btn_pauseSlideshow_1');
	this.slideshowpause1.removeClassName('pauseSlideshow');
   	this.slideshowpause1.addClassName('startSlideshow');
	this.slideshowpause1.href="javascript:startSlideShow();";
    this.slideshowpause1.innerHTML="Start";
	//alert(this.slideshowpause1.innerHTML)

	this.slideshowpause2 = $('btn_pauseSlideshow_2');
	this.slideshowpause2.removeClassName('pauseSlideshow');
   	this.slideshowpause2.addClassName('startSlideshow');
	this.slideshowpause2.href="javascript:startSlideShow();";
    this.slideshowpause2.innerHTML="Start";
	//alert(this.slideshowpause2.innerHTML)

	slideshow=false;
	//alert("we are in pasue slide show:"+slideshow);
}

function increaseSlideShowSpeed(){
	if(frequency < 8000){
	   frequency=frequency+3000;
	   this.slideshow_speed1 = $('slideshow_speed');
       this.slideshow_speed1.innerHTML="seconds: "+eval(frequency/1000);

	   this.slideshow_speed2 = $('slideshow_speed_2');
       this.slideshow_speed2.innerHTML="seconds: "+eval(frequency/1000);
	}
}
function decreaseSlideShowSpeed(){
	if(frequency > 2000){
	   frequency=frequency-3000;
	   this.slideshow_speed1 = $('slideshow_speed');
       this.slideshow_speed1.innerHTML="seconds: "+eval(frequency/1000);

	   this.slideshow_speed2 = $('slideshow_speed_2');
       this.slideshow_speed2.innerHTML="seconds: "+eval(frequency/1000);
	}
}
function startSlideShow(){

	this.slideshowpause1 = $('btn_pauseSlideshow_1');
	this.slideshowpause1.removeClassName('startSlideshow');
   	this.slideshowpause1.addClassName('pauseSlideshow');
	this.slideshowpause1.href="javascript:pauseSlideShow();";
    this.slideshowpause1.innerHTML="Pause";
	//alert(this.slideshowpause1.innerHTML)

	this.slideshowpause2 = $('btn_pauseSlideshow_2');
	this.slideshowpause2.removeClassName('startSlideshow');
   	this.slideshowpause2.addClassName('pauseSlideshow');
	this.slideshowpause2.href="javascript:pauseSlideShow();";
    this.slideshowpause2.innerHTML="Pause";
	//alert(this.slideshowpause2.innerHTML)

	slideshow=true;
	playSlideShow();
	//alert("we are in pasue slide show:"+slideshow);
}
function playSlideShow(){
	slideshowref=window.location.href;
	//alert("slideshowref:"+slideshowref);
	index=slideshowref.indexOf("?currentImageIndex=");
	//alert("index:"+index);
	if(index > 0 && imagePositionInListOfAllImages == 0 && fromGallery){
		  //alert("we are inside");
		  fromGallery = false;
          index= slideshowref.substring(slideshowref.indexOf("?currentImageIndex=")+19,slideshowref.indexOf("&masterXml="));
		//  alert("index:"+index);
          currImageIndxVal = index.valueOf();
		  imagePositionInListOfAllImages=eval(currImageIndxVal);
	}

    //alert(currImageIndxVal);
	/*if(currImageIndxVal == imagePositionInListOfAllImages){
		alert("it is equal");
	}*/

   
	if(slideshow){
	   getSlideShowImage();
	   setTimeout("playSlideShow();",frequency)
	   $('btn_prevSlideshow_image').focus();
	}		
}

function showcaptions_1(){
  // alert("we are in showcaptions");
  this.captions = $('image_gallery_fullscreen_caption_1');
  this.button1 = $('btn_slideshow_captions_1');
  this.button2 = $('btn_slideshow_captions_2');
    if(this.captions.style.display == "block") {
		    this.captions.style.display = "none";
			this.button1.innerHTML="Show Captions";
			this.button2.innerHTML="Show Captions";
	}
	else {
		this.button1.innerHTML="Hide Captions";
		this.button2.innerHTML="Hide Captions";
		this.captions.style.display = "block";		
	}
}

function showNextImage(){
	if(imagePositionInListOfAllImages < listOfImages.length){
		renderSlideShowImage(); 
	} else {
		imagePositionInListOfAllImages=0;
		renderSlideShowImage(); 
	}
}

function showPrevImage(){
	if(previndex > 0){
	   imagePositionInListOfAllImages=previndex-1;
	   renderSlideShowImage(); 
	} else if(previndex == 0){
	   imagePositionInListOfAllImages=listOfImages.length-1;
	   renderSlideShowImage(); 
	}
}