
function Picture(id,url,title,legend)
{
	this.id = id;
	this.url = url;
	this.title = title;
	this.legend = legend;
}

var ImageSwitcher = 
{
	/* constructor */
  initialize : function() {
		this.arr = new Array();
		this.aktindex = 0;
		this.imageId = "bigimage";
		this.legendId = "divComment";
		this.titleId = "divTitle";
		this.statusId = "divStatus";
		
   },
   
	/* add new picture */	
   add : function(id,url,title,legend){
		
		var pic = new Picture(id,url,title,legend);
		this.arr[this.arr.length] = pic;
   },
   
   remove : function(index){
		
   },
   
   first : function(){
		this.aktindex = 0;
		 this.setImage();
   },
   
   previous : function(){
	
	this.aktindex--;
	
	if(this.aktindex < 0)
		this.aktindex =  this.arr.length - 1;
	 this.setImage();
   },
   
   next : function(){
	
	this.aktindex++;
	
	if(this.aktindex >= this.arr.length)
		this.aktindex = 0;
		
	 this.setImage();
   },
   
   last : function(){
	  this.aktindex = this.arr.length - 1;
	  this.setImage();
   },
   
   setImage : function()
   {
	 var img = $(this.imageId);
	 var legend = $(this.legendId);
	 var title = $(this.titleId);
	 var status = $(this.statusId);
	 
	 var pic = this.arr[this.aktindex];
	 
	 if(img != null) img.src = pic.url;
	 if(legend != null) legend.innerHTML = pic.legend;
	 if(title != null) title.innerHTML = pic.title;
	 if(status != null) status.innerHTML = (this.aktindex + 1) + " / " + this.arr.length;
	 
	 for(var i=0;i<this.arr.length;i++)
	 {
		if(i == (this.aktindex))
		{
			$('listenelement'+this.arr[i].id).style.color="darkred";   	
		}else
		{
		    try{
		        $('listenelement'+this.arr[i].id).style.color="#585858";   	
		    }
		    catch(e)
		    {}
	    }
			
	 }
	
	
   }, 
   
   setImageByIndex : function(index)
   {
	 this.aktindex = index;
	 this.setImage();
   },
   
   setImageById : function(picid)
   {
        
	 for(var i=0;i<this.arr.length;i++)
	 {
	   	if(this.arr[i].id == picid)
		{
			this.aktindex = i;
			    $('listenelement'+this.arr[i].id).style.color="darkred";   	
			
		}else
		{
		   // if (this.arr[i]!=null)
		        $('listenelement'+this.arr[i].id).style.color="#585858"; 
		        
		   
	    }
	    
			
	 }
	 this.setImage();
   }
}
