		
var JWP = window.JWP || {};

JWP.widget = function(){

	function Slideshow (container,holder,slides,configs){

	// PRIVATE
		var that = this;
		var currentSlide = 0; 	//Current Slide
		var timer = null; 		//Timer Holder
		var count = 0; 			//Revolution Counter
		

		
	// PUBLIC 
		// Argument element references
		this.parent_el = container;
		this.holder_el = holder;
		this.slides = slides;
		// Config defaults
		this.config = {
				timeOut: 10,  // time between slide transitions
				z_index: 1, // zIndex of slides
				effects: { // transition effects and easing (must match YUI Animation API params)
					show : { opacity: { from: 0, to: 1 } },
					hide : { opacity: { from: 1, to: 0 } },
					showEasing : YAHOO.util.Easing.easeOut,
					hideEasing : YAHOO.util.Easing.easeIn
				}
		}
		// parse through Configs argument and replace default values
		if(configs && typeof(configs) == 'object'){
			for( var n in configs ){
				if( configs[n] == 'effects' ){
					for( var o in configs[n] ){
						this.config.effects[0] = configs[n][o]
					}
				}else{ this.config[n] = configs[n] }
			}
		}
		// Methods
		this.setupSlideshow = function () {
			// setup events
			//YAHOO.util.Event.addListener(that.parent_el,"mouseover",that.pause)
			//YAHOO.util.Event.addListener(that.parent_el,"mouseout",that.resume)
			// setup slide holder
			YAHOO.util.Dom.addClass([that.parent_el,that.holder_el],'jwp_slideshow');
			YAHOO.util.Dom.setStyle(that.holder_el, 'position', "absolute");
			YAHOO.util.Dom.setStyle(that.holder_el, 'overflow', "hidden");
			// setup slide elements
		    for (var i = that.slides.length; i > -1; i-- ) {
		            if (that.slides[i]) {
		                YAHOO.util.Dom.setStyle(that.slides[i], 'position', "absolute");
		                YAHOO.util.Dom.setStyle(that.slides[i], 'overflow', "hidden");
				        YAHOO.util.Dom.setStyle(that.slides[i], 'z-index', that.config.z_index);
		                YAHOO.util.Dom.setStyle(that.slides[i], 'opacity', 0);
		            }
		    }
		    that.loadSlide(0);
		}
		this.loadSlide = function (slideID) {
		    if (that.slides[slideID]) {
		        that.config.z_index++;
		        var newSlide = that.slides[slideID];
		        YAHOO.util.Dom.setStyle(newSlide, 'z-index', that.config.z_index);
		        var animSlideIn  = new YAHOO.util.Anim(newSlide, that.config.effects.show, 1, that.config.effects.showEasing);
		        animSlideIn.animate();		
				count++;
		        timer = setTimeout(that.loadNextSlide,(that.config.timeOut * 1000));
		    }
		}
		this.loadNextSlide = function () {
			var curSlide = that.slides[currentSlide];
		    var nextSlide = (currentSlide + 1);
		    if (!that.slides[nextSlide]) {
		        nextSlide = 0;
		    }
		    var animSlideOut  = new YAHOO.util.Anim(curSlide, that.config.effects.hide, 1, that.config.effects.hideEasing);
		    animSlideOut.animate();
			currentSlide = nextSlide;
			var testPauseCount = 0;
		    that.loadSlide(nextSlide);
		}
		this.pause = function(e){
		}
		this.resume = function(e){
		}
		this.render = function (){
			if (that.slides.length > 1) {
			    that.setupSlideshow();
			};
		}
	}
	// return Constructor
	return {
		Slideshow:Slideshow
	}

}();

