/**
 Copyright (c) 2010, Bomimed Inc. All rights reserved.
 Slider script to move overlay
 Justin Olivier
 
 SlideContainer = Container Div
 SlidePane = Containing Pane That Moves with the Slide
 SlideOverlay = The overlay div
*/

/**
 OverlaySliderSetup
*/ 
function OverlaySlider(){

	this.overlay = YAHOO.util.Dom.get('SlideOverlay');
	this.anim = null;

	var UIDisable = false;
	var slideCount = YAHOO.util.Dom.getChildren('SlidePane').length;
	var slideIndex = -1;
	var slideWidth = parseInt(YAHOO.util.Dom.getStyle(this.overlay, "width"));
	

	/**
 	slideTo
	*/ 
	this.slideTo = function(target){
		
		var attributes, anim, adjust;
		if((UIDisable == false)&&(target!=slideIndex)){

			UIDisable = true;
			adjust = target*slideWidth;
			slideIndex=target;

 			attributes = { left: { to: adjust } }; 
			this.anim = new YAHOO.util.Anim(this.overlay,attributes,0.5, YAHOO.util.Easing.easeOut);
			this.anim.onComplete.subscribe(this.imageSelect,this,true); 
			this.anim.animate();
		

		}
	
	}

	/**
  	slideRestore
	*/ 
	this.slideRestore = function(){

		//Make sure all other images are faded

		var index = 0;
		var node = YAHOO.util.Dom.get("SlideImage"+index);	
		while(node != undefined){
			if(index != slideIndex)
				YAHOO.util.Dom.setStyle( "SlideImage"+index , "opacity", 0);
			index++;
			node = YAHOO.util.Dom.get("SlideImage"+index);
		}	
		UIDisable = false;
		this.anim.onComplete.unsubscribe();
	}

	this.imageSelect = function(){

		//Make sure all the other images are in the background
		var index = 0;
		var node = YAHOO.util.Dom.get("SlideImage"+index);	
		while(node != undefined){
			YAHOO.util.Dom.setStyle( "SlideImage"+index , "z-index", 3);
			index++;
			node = YAHOO.util.Dom.get("SlideImage"+index);
		}	
	
		//Bring up the new image
		this.anim.onComplete.unsubscribe();
		YAHOO.util.Dom.setStyle( "SlideImage"+slideIndex , "z-index", 4);
		this.anim = new YAHOO.util.Anim( "SlideImage"+slideIndex ,  { opacity: {from: 0, to: 1 } },   1,YAHOO.util.Easing.easeOut);  
		this.anim.onComplete.subscribe(this.slideRestore,this,true); 
		this.anim.animate();
			
	}


}

