   


// Begin new JavaScript 
var ContentlightboxGallery = Class.create({
  
  // This starts as class is initialized/activated 
  initialize: function() {
   	  	
		// Default Settings
		this.lightboxGalleryOuter = "lightboxGallery-outer"; // Outside lightboxGallery Div Id
		this.lightboxGalleryInner = "lightboxGallery-inner"; // Inside lightboxGallery Div Id
		this.lightboxGalleryPannel = "lightboxGallery-pannel"; // lightboxGallery Pannels Class Name 
		this.lightboxGalleryPannelActive = "lightboxGallery-pannel-active"; // Current Active lightboxGallery Class 
		
		this.Speed = 3000;
		this.ActivePannel = ""; // First/Current Active lightboxGallery Id, if blank, the first div in the lightboxGalleryInner  
		
		this.AutoPlay = false; // automatically Start Playing 
		this.AutoPlaying = false; // Must start as false!!
		
		this.show_menu = true; // Show Menu 
		this.menu_id = "lightboxGallery-menu"; // Menu id
		
		this.lightboxGalleryPlayButton = "lightboxGallery_play_button"; // Id of lightboxGallery Play Button 
		this.lightboxGalleryStopButton = "lightboxGallery_stop_button"; // Id of lightboxGallery Stop Button
		
		this.show_title_box = false; // show title box 
		this.lightboxGallerytitleBox = "lightboxGallery-titleBox"; // optional title box id 
		
		this.show_top_close = false; // show top close button
		this.closeLightboxGallery = "closeLightboxGallery"; // "close" button id 
		
		this.show_on_image_links = false; // show the next and previous links surrounding the image. (does not include menu bar) 
		this.nextLightboxGallery = "nextLightboxGallery"; // "next" button id 
		this.preLightboxGallery = "preLightboxGallery"; // "previous" button id 
		
		this.activatedAlready = false; // must start as false, holds true if button clicked or event in place 
  },
  
  // Load lightboxGallery ( Begin ) 
  LoadlightboxGallery: function() {
  
  		// show menu? 
		if(this.show_menu != true) $(this.menu_id).style.display = "none";

  		// show menu? 
		if(this.show_title_box != true) $(this.lightboxGallerytitleBox).style.display = "none";

  		// show menu? 
		if(this.show_top_close != true) {
			$(this.closeLightboxGallery).style.display = "none";
		}

  		// show menu? 
		if(this.show_on_image_links != true) {
			$(this.nextLightboxGallery).style.display = "none";
			$(this.preLightboxGallery).style.display = "none";
		}
  
		if( this.ActivePannel == '' ) {
			this.ActivePannel = this.FirstBox();
		} 
		this.MakeDivVisible(this.ActivePannel);	
		
		// Begin lightboxGallery App 
		
		// If autoplaying set to true, then auto play
		if(this.AutoPlay == true) {
			this.AutoRun();
		}
  },
  
  // Show Next Slide 
  NextSlide: function() {
  
  		if(this.NextBox()) {
			
			// hide current box
			this.MakeDivHidden(this.ActivePannel);
			// set new  current box
			this.ActivePannel = this.NextBox(); 
			// make new current slide active  
			this.MakeDivVisible(this.ActivePannel);  
		
		} else {
			// Last Slide 
			this.GoTolightboxGalleryPannel(this.FirstBox()); // Go To First
		}
  },
  
  // Show Previous Slide 
  PreviousSlide: function() {
  
  		if(this.PreviousBox()) {
			
			// hide current box
			this.MakeDivHidden(this.ActivePannel);
			// set new  current box
			this.ActivePannel = this.PreviousBox(); 
			// make new current slide active  
			this.MakeDivVisible(this.ActivePannel);   
		
		} else {
			// First Slide
			this.GoTolightboxGalleryPannel(this.LastBox()); // Go To Last
		}
  },
  
  //  
  AutoRun: function() {
  
	  if(this.AutoPlaying == false) {
	  
	 	 //this.lightboxGallerysAutoPlayTimer = setInterval('my_content_lightboxGallery.NextSlide()', this.Speed);
		 this.lightboxGallerysAutoPlayTimer = setInterval(this.NextSlide.bind(this), this.Speed);
	  	 this.AutoPlaying = true;
		 
		 $(this.lightboxGalleryPlayButton).style.display = "none";
		 $(this.lightboxGalleryStopButton).style.display = "inline";
	  }
  },
  
  //  
  EndAutoRun: function() {
  
	   if(this.AutoPlaying == true) {
	   
	   	  clearTimeout(this.lightboxGallerysAutoPlayTimer);
	   	  this.AutoPlaying = false;
		  
		 $(this.lightboxGalleryPlayButton).style.display = "inline";
		 $(this.lightboxGalleryStopButton).style.display = "none";
	   }
  },
  
  //  
  FirstSlide: function() {
  
  		if(this.ActivePannel != this.FirstBox()) {
  			if(this.FirstBox() != undefined) {
				this.GoTolightboxGalleryPannel(this.FirstBox()); // Go To First
			}
		}
  },
  
  //  
  LastSlide: function() {
  
  		if(this.ActivePannel != this.LastBox()) {
  			if(this.LastBox() != undefined) {
				this.GoTolightboxGalleryPannel(this.LastBox()); // Go To Last
			}
		}
  },
  
  //  
  GoTolightboxGalleryPannel: function(NewSlide) {
  
  		if(this.ActivePannel != NewSlide) {
			// hide current box
			this.MakeDivHidden(this.ActivePannel);
			// set new  current box
			this.ActivePannel = NewSlide; 		
			// show new current box
			this.MakeDivVisible(this.ActivePannel);  
		}
  },
  
  stripHTML: function(contentInput){
		return contentInput.replace(/(<([^>]+)>)/ig,""); 
	},
  
  // make box visible
  MakeDivVisible: function(el) {
		
		if(this.activatedAlready == true) {
			setTimeout(this.MakeDivVisible.bind(this,el), 100);
		}
		else {
			
			this.activatedAlready = true; // begin the app active var 
	 
		  	Effect.Fade(el, { duration: 0.8, from: 0, to: 1.0 });
	  		Effect.SlideDown(el, { duration: 0.4 });
			setTimeout(function() { $(el).style.display = "block"; }, 40);
			//$(el).className = this.lightboxGalleryPannelActive;
			
			// set title box
			//$(this.lightboxGallerytitleBox).innerHTML = this.stripHTML($(el).title) + ' &nbsp;&nbsp;';
			$(this.lightboxGallerytitleBox).innerHTML = this.stripHTML($(el).title) + ' &nbsp;&nbsp;';
			
			/*
			var elementIdofit = $$("#"+this.ActivePannel+" img")[0];
			var pos_y = elementIdofit.offsetX ? (elementIdofit.offsetX) : (elementIdofit.offsetLeft);
			alert( pos_y );
			*/
				
			setTimeout(this.setNotActive.bind(this), 100);
			
		}
  },
  
  setNotActive: function() {
	  this.activatedAlready = false;
  },
  
  // make box invisible
  MakeDivHidden: function(el) {
		
	  //$(el).style.display = "none";
	  $(el).fade(el, { duration: 0.4, from: 1.0, to: 0 });
	  Effect.SlideUp(el, { duration: 0.4 });
							
		setTimeout(this.setDivBack.bind(this, el), 100);
	
  },
  
  setDivBack: function(el) {
  
  		$(el).className = this.lightboxGalleryPannel;
							
  },
  
  // get next box id
  NextBox: function() {
  
	 if($(this.ActivePannel).next('.' + this.lightboxGalleryPannel)) {
	  	return $(this.ActivePannel).next('.' + this.lightboxGalleryPannel).id;
	 } else {
	 	return false;
	 }
  },
  
  // get previous box id
  PreviousBox: function() {
  
	 if($(this.ActivePannel).previous('.' + this.lightboxGalleryPannel)) {
	    return $(this.ActivePannel).previous('.' + this.lightboxGalleryPannel).id;
	 } else {
	 	return false;
	 }
  },
  
  // get first box id
  FirstBox: function() {
  		
	  return $(this.lightboxGalleryInner).down('div.'+this.lightboxGalleryPannel).id;
		//if($$("#"+this.lightboxGalleryInner+" div."+this.lightboxGalleryPannel+":first-child")[0] != undefined) 
  			//return $$("#"+this.lightboxGalleryInner+" div."+this.lightboxGalleryPannel+":first-child")[0]; 
  },
  
  // get first box id
  LastBox: function() {
  		
		if($$("#"+this.lightboxGalleryInner+" div."+this.lightboxGalleryPannel+":last-child")[0] != undefined) 
  		return $$("#"+this.lightboxGalleryInner+" div."+this.lightboxGalleryPannel+":last-child")[0]; 
		
	   // return $(this.lightboxGalleryInner).select(":last-child div")[0];
  },
  
  // USER AVAILABLE FUNCTIONS
  // get first box id
  runFirst: function() {
  
  		if(this.AutoPlaying == true) {
			this.EndAutoRun();
		}
		setTimeout(this.FirstSlide.bind(this), 200);
  },
  // get last box id
  runLast: function() {
  
  		if(this.AutoPlaying == true) {
			this.EndAutoRun();
		}
		setTimeout(this.LastSlide.bind(this), 200);
  },
  // get last box id
  runNext: function() {
  
  		if(this.AutoPlaying == true) {
			this.EndAutoRun();
		}
		setTimeout(this.NextSlide.bind(this), 200);
  },
  // get last box id
  runPrevious: function() {
  
  		if(this.AutoPlaying == true) {
			this.EndAutoRun();
		}
		setTimeout(this.PreviousSlide.bind(this), 200);
  },
  // get last box id
  runSlide: function(slideId) {
  
  		// if the lightbox is not already open
		if(lightboxImageGalOn == false) openLightboxImageGal();
		
  		if(this.AutoPlaying == true) {
			this.EndAutoRun();
		}
		setTimeout(this.GoTolightboxGalleryPannel.bind(this,slideId), 200);
  }

});

var lightboxImageGalOn = false;

function openLightboxImageGal() {

	$('modal_image_window_outer').style.display = "block";
	$('modal_image_window_box').style.display = "block";
	
	// and fade in the background
	new Effect.Opacity('modal_image_window_outer', { from: 0, to: 0.7, duration: 0.5, queue: 'end' });
	
	// fade in the main box
	new Effect.Opacity('lightboxGallery-outer', { from: 0, to: 1.1, duration: 0.6, queue: 'end' });
	new Effect.SlideDown('lightboxGallery-outer');
	
	lightboxImageGalOn = true;
	
}

function closeLightboxImageGal() { // removing the modal window
		
	Effect.Queues.get('modal_image_window_outer').interval = 200;
		
	// slide up the	main box
	new Effect.SlideUp('lightboxGallery-outer', { queue: 'front' });
	Effect.Fade('lightboxGallery-outer');
	
	// finaly hide the window
	Effect.Fade('modal_image_window_outer');
	
	lightboxImageGalOn = false;
}	
