var GM2 = window.GM2 || {};
GM2.main = function(){
	return {
		
		slideshow2: {
			properties:{
				speed:5000,
				animSpeed:3,
				isAnimating:false,
				container:""
			},
			init:function(slideshowProperties){
				// set properties
				this.properties.speed = slideshowProperties.speed;
				this.properties.animSpeed = slideshowProperties.animSpeed;
				this.properties.container = slideshowProperties.container;
				// set currslide
				this.currSlide = 0;
				// get the rotating image divs
				this.slides2 = YAHOO.util.Dom.getElementsByClassName('slide2', 'div', 'slides2');
				this.slideshow2 = YAHOO.util.Dom.get('slideshow2');
				YAHOO.util.Dom.setStyle(this.slideshow2, 'position', 'relative');
				for (var i=0; i < this.slides2.length; i++) {
					YAHOO.util.Dom.setStyle(this.slides2[i], 'opacity', '0');					
					YAHOO.util.Dom.setStyle(this.slides2[i], 'position', 'absolute');					
					YAHOO.util.Dom.setStyle(this.slides2[i], 'top', '0');					
				//	YAHOO.util.Dom.setStyle(this.slides2[i], 'display', 'none');	

				};
				this.setSlide(this.currSlide);				
			},
			setSlide:function(slideIndex){
				//alert('setslide called');
				this.slideshow2.appendChild(this.slides2[slideIndex]);
				var that=this;
				var myAnim = new YAHOO.util.Anim(this.slides2[slideIndex], {opacity:{from:0, to:.95}}, this.properties.animSpeed, YAHOO.util.Easing.easeOut);
				myAnim.onComplete.subscribe(function(){
					 //alert(slideIndex);
					setTimeout(function(){
					//	alert('timeout set');
						that.fadeOut(slideIndex);
					}, that.properties.speed);
				});
					myAnim.animate();
		},
			fadeOut:function(slideIndex){
				//alert('doh');
				var that = this;
				var myAnim = new YAHOO.util.Anim(this.slides2[slideIndex], {opacity:{from:.95, to:0}}, this.properties.animSpeed, YAHOO.util.Easing.easeOut);
				var nextSlide = (slideIndex<this.slides2.length-1)?slideIndex+1:0;
				if(YAHOO.util.Dom.getStyle(this.slides2[slideIndex], 'opacity')>.5){
					that.setSlide(nextSlide);
				}
				myAnim.onComplete.subscribe(function(){
					that.slideshow2.removeChild(that.slides2[slideIndex]);
				});
			myAnim.animate();
			}
		}
	}
}();
// YAHOO.util.Event.onContentReady("page", GM2.main.init);
YAHOO.util.Event.on(window, 'load', GM2.main.init);
YAHOO.util.Event.onContentReady('slides2', function(){
	GM2.main.slideshow2.init({animSpeed:1.5, speed:3500});
});
