	/*
	=:project
	  RenaissanceCMS

	=:class
	  RenSlideShow

	=:since
	  0.3.1a

	=:last update
	  18/07/09

	=:status
	  in progress

	=:principle author
	  Rob chant

	=:notes
      JavaScript part of renaissance's slideshow functionality

	=:contains methods

		=:public
		  
		
		=:private


	=:contains properties

		=:public
		
		=:private


 	=:contains methods

		=:public
		  RenSlideShow(id,target,view,initial_image,use_activation,activated)

		=:private
		  activate()
		  deActivate()
		  initialize()
		  showImage(image)

	*/

function RenSlideShow(id,target,view,initial_image,use_activation,activated){

	this.initialize(id,target,view,initial_image,use_activation,activated);
}

RenSlideShow.prototype={
	
	id: null,
	target: null,
	view: null,
	use_activation: null,
	
	current: null,
	activated: null,

	initialize: function(id,target,view,initial_image,use_activation,activated){
		
		this.id=id;
		this.target=target;
		this.view=view;
		this.use_activation=use_activation;

		this.current=initial_image;
		this.activated=activated;

	},

	activate: function(){
	
		if(this.use_activation)
			{
			if(!this.activated)
				{
				$(this.target).style.display='block';
				this.activated=true;
				}
			}
	},

	customShowBehaviour: function(image){
		$('image-target').innerHTML='';
		fader('image-target',0.75,100,0,'display');
		scroller();		
	},

	deActivate: function(){
		
		if(this.use_activation)
			{
			if(this.activated)
				{
				$(this.target).style.display='none';
				this.activated=false;
			
				if(typeof this.current=='number')
					{	
					LNWebLib.Dom.removeClassName('slide-show-'+this.id+'-activation-'+this.current,'on');
					this.current=false;
					
					$(this.target).innerHTML='';
					}
				}
			}
		
	},

	showImage: function(image){

		if(true)//this.current!=image)
			{
			var previous=0;
			var next=0;
			var thumbs=[];
			
			fader('galleries',-1.5,0,100,'visibility');
			fader('loading',0.7,100,0,'display');
			
			var children=LNWebLib.Dom.getChildren('slide-show-'+this.id);
			
			for(var i=0;i<children.length;i++)
				if(children[i].id.indexOf('slide-show-'+this.id+'-activation')==0)
					thumbs.push(children[i]);
			
			for(var i=0;i<thumbs.length;i++)
				{
				var id=thumbs[i].id.parseInts()[1];

				if(id==image)
					{
					var n=i+1;
					var p=i-1;

					if(n>thumbs.length-1)
						n=0;
					
					if(p<0)
						p=thumbs.length-1;
					
					previous=thumbs[p].id.parseInts()[1];
					next=thumbs[n].id.parseInts()[1];
					}				
				}

			RenFront.Content.fetch(image,'image',this.view,this.target,false,'close image',this.id,previous,next);

			this.activate();

			if(typeof this.current=='number')
				LNWebLib.Dom.removeClassName('slide-show-'+this.id+'-activation-'+this.current,'on');

			LNWebLib.Dom.addClassName('slide-show-'+this.id+'-activation-'+image,'on');
		
			this.current=image;
			
			this.customShowBehaviour(image);
			}
		else
			this.deActivate();
	}	

}
