var imageviewerEngine = function(){		
	/*
	author:Giuseppe
	date: 20/08/2007
	notes: This  function is to fade in and out the images and linkboxes. I'm using script.aculo for the animation and the prototype.js
				 (the function $() is from prototype.js and returns an array of html elements passing an element_id or element itself.)		
	
	*/
	this.name = 'imageviewerEngine';
	this.currentIndex = 0;
	//initializing to new Array so later on the a.length function will not fail if either the images or linkboxes are not available
	this.images 		= new Array();
	this.linkboxes 	= new Array();
	this.pairs			= new Array();
	this.interval  	= null;
	this.linkboxMaxHeight = 0;
	
	this.init 												= function(interval)
	{
		for(var i=1; i<this.images.length; i++){		
			this.initElement(this.images[i]);			
		}	
		for(var i=1; i<this.linkboxes.length; i++){				
			this.initElement(this.linkboxes[i]);
		}	
		this.associateImagesToLinkboxes();		
		this.interval = setInterval("imgEngine.fadeEngine()", interval);					
	};	
	
	this.fadeEngine 									= function()
	{							

		var pairout = this.pairs[this.currentIndex];			
		this.currentIndex =  (this.currentIndex == undefined)		? 	0 		: ( ++(this.currentIndex) >= this.pairs.length ) ? 	0 : this.currentIndex;
		var pairin = this.pairs[this.currentIndex];			
		
		if(pairout.image != pairin.image){			
			this.fadeOut(pairout.image);
		}
		if(pairout.linkbox != pairin.linkbox){
			this.fadeOut(pairout.linkbox);				
		}		
					
		this.fadeIn(pairin.image);	
		this.fadeIn(pairin.linkbox);									
	};	
	this.getLinkboxMaxHeight					= function()
	{
		for( var i=0; i<this.linkboxes.length; i++ ){
			this.linkboxMaxHeight = Math.max( this.linkboxMaxHeight, this.linkboxes[i].offsetHeight );
		}
		return this.linkboxMaxHeight;
	}
	this.associateImagesToLinkboxes 	= function()
	{
		var maxindex = this.images.length > this.linkboxes.length ? this.images.length : this.linkboxes.length;
		
		for(var i = 0; i< maxindex; i++){
			var o = new Object();
			o.image = (this.images[i])? this.images[i] : this.images.length>0? this.images[this.images.length-1] : null;
			o.linkbox = (this.linkboxes[i])? this.linkboxes[i] : this.linkboxes.length>0? this.linkboxes[this.linkboxes.length-1] : null;
			this.pairs.push(o);
		}
	};
	
	this.initElement 									= function(el)
	{
		el.style.display 		= 'none';
		el.style.visibility = 'visible';
	};
	
	this.fadeIn 											= function(el)
	{
		if(el != null)
			Effect.Appear(el, {duration:2.0});
	};
	
	this.fadeOut 											= function(el)
	{
		if(el != null)
			Effect.Fade(el);
	};
}