var moduleContentSwap = new Class({
	Implements: [Events, Options],
	options:{
		btnLeft:'RA-left',
		btnRight:'RA-right',
		maxArticles:20,
		contentTarget:'RecentArticles',
		contentURL:'/include/inc_module_getrecentarticles.asp'
		
	},
		
	initialize:function(options){
		this.setOptions(options);
		this.options.maxArticles++;
	
									
		//determine number of images
		this.currentImageIndex = 1;
		
		//if(this.imageCount == 1){
		//    function(){
		//		this.updateGetRecentArticle()
		//}
		//}
		
		if(this.options.maxArticles > 1){
			//hide all images, then show the first
			//$$(this.options.imgClass).setStyle('opacity',0);
			//$$(this.options.imgClass)[0].tween('opacity',[0,1]);
			
			//assign navigation behaviour
			$(this.options.btnLeft).addEvent('click',function(){
				this.prevImage();
			}.bind(this));
			$(this.options.btnRight).addEvent('click',function(){
				this.nextImage();
			}.bind(this));			
		}
	},
	
	prevImage:function(){
		//$$(this.options.imgClass)[this.currentImageIndex].tween('opacity',[1,0]);
		if(this.currentImageIndex - 1 < 1){
			this.currentImageIndex = this.options.maxArticles - 1;
		} else {
			this.currentImageIndex = this.currentImageIndex - 1;
		}
		this.updateGetRecentArticle()
		//$$(this.options.imgClass)[this.currentImageIndex].tween('opacity',[0,1]);	
		
		//alert(this.currentImageIndex)
	},
	
	nextImage:function(){	
		//$$(this.options.imgClass)[this.currentImageIndex].tween('opacity',[1,0]);
		if(this.currentImageIndex + 1 >= this.options.maxArticles){
			this.currentImageIndex = 1;
		} else {
			this.currentImageIndex = this.currentImageIndex + 1;
		}				
		this.updateGetRecentArticle()			
		//$$(this.options.imgClass)[this.currentImageIndex].tween('opacity',[0,1]);		
		
		//alert(this.currentImageIndex)		
	},
	
	updateGetRecentArticle:function(){
	getcontentTarget = this.options.contentTarget;
	getcurrentpos = this.currentImageIndex;
	    var time = $random(0,100) - $time();
		var myHTMLRequest = new Request.HTML({url:this.options.contentURL
		,onRequest:function(){
			$(getcontentTarget).set('html','<div style="text-align:center"><img src="/images/ajax-loader.gif" alt=""/></div>');
		},
		update:this.options.contentTarget})
		
		.get({'pos': getcurrentpos,'time':time});
    }

	
});


		

		