var slideshow = Class.create();

slideshow.prototype = {
	timer:null,
	activeview:null,
	hiddenview:null,
	slidername:'',
	slideshowIndex:0,
	imageArray:null,
	key:0,
	slideshow: function() {
		
	},
	init: function() {
		this.activeview=$(this.slidername+'newsimage1');
		this.hiddenview=$(this.slidername+'newsimage2');
		if(!this.imageArray.length) {
			$(this.slidername+'slideshow').style.display='none';
		} else {
			this.slide(0);
			if(this.imageArray.length==1) {
				$(this.slidername+'slideshowcontrols').style.display='none';
			} else {
				this.play();
			}
		}
	},
	initialize: function() {
	},
	
	showFirst: function() {
		$(this.slidername+'newsimage1holder').style.display='none';
		Effect.toggle($(this.slidername+'newsimage1holder'),'appear', {duration: 0.3});
		$(this.slidername+'newsimage1holder').style.zIndex=2;
		$(this.slidername+'newsimage2holder').style.zIndex=1;
	},
	showSecond: function() {
		$(this.slidername+'newsimage2holder').style.display='none';
		Effect.toggle($(this.slidername+'newsimage2holder'),'appear', {duration: 0.3});
		$(this.slidername+'newsimage1holder').style.zIndex=1;
		$(this.slidername+'newsimage2holder').style.zIndex=2;
	},
	play: function(){
		clearInterval(this.timer);
		this.timer=setInterval('globalSlide(null, '+this.key+')',this.interval);
	},
	
	pause: function(){
		clearInterval(this.timer);
	},
	
	restart: function(){
	
	},
	
	slide: function(n){
		temp=this.activeview;
		this.activeview=this.hiddenview;
		this.hiddenview=temp;
		if (n==null) {
			this.slideshowIndex=(this.slideshowIndex+1)%this.imageArray.length;
		} else {
			this.slideshowIndex=(this.slideshowIndex+n)%this.imageArray.length;
		}
		this.activeview.src=this.imageArray[this.slideshowIndex].src;
		$(this.slidername+'previous').setStyle( {visibility:this.slideshowIndex ? 'visible':'hidden'});
		$(this.slidername+'next').setStyle({visibility:this.slideshowIndex==this.imageArray.length-1?'hidden':'visible'});
		$(this.slidername+'popup_link').href = this.imageArray[this.slideshowIndex].src;
	}
};

function globalSlide(n, key) {
	//alert('sliding to next for ' + key);
	obj = sliderArray[key];
	temp=obj.activeview;
	obj.activeview=obj.hiddenview;
	obj.hiddenview=temp;
	if (n==null) {
		obj.slideshowIndex=(obj.slideshowIndex+1)%obj.imageArray.length;
	} else {
		obj.slideshowIndex=(obj.slideshowIndex+n)%obj.imageArray.length;
	}
	obj.activeview.src=obj.imageArray[obj.slideshowIndex].src;
	$(obj.slidername+'previous').setStyle( {visibility:obj.slideshowIndex ? 'visible':'hidden'});
	$(obj.slidername+'next').setStyle({visibility:obj.slideshowIndex==obj.imageArray.length-1?'hidden':'visible'});
	$(obj.slidername+'popup_link').href = obj.imageArray[obj.slideshowIndex].src;
}