


var textarr = new Array();

var Text = new Class({
    // standardeinstellungen
    options: {
        image: null,
        nextButton: null,
        prevButton: null,
        legend: null
    },
    // konstruktor
    initialize: function(id,options)
    {
        
        this.setOptions(options);           // optionen
        this.id = id;
        this.aktindex = 0;
        this.imgarr = new Array();
        
        if(this.options.nextButton == null)
            this.options.nextButton = $("next" + this.id);
      
        if(this.options.prevButton == null)
            this.options.prevButton = $("prev" + this.id);
            
         if(this.options.image == null)
            this.options.image = $('img' + this.id);
            
         if(this.options.legend == null)
            this.options.legend = $('legend' + this.id);
          
         this.check();
    }
});


Text.implement({
    next: function(){
		 
		this.aktindex++;
		 
		this.showImage();
		    
    }
});

Text.implement({
    previous: function(){
        this.aktindex--;
        
		if(this.aktindex < 0)
		    this.aktindex = 0;
		    
		this.showImage();
    }
});

Text.implement({
    check: function(){
        if(this.options.image == null)
            this.options.image = $('img' + this.id);
            
        if(this.options.nextButton == null)
            this.options.nextButton = $("next" + this.id);
      
        if(this.options.prevButton == null)
            this.options.prevButton = $("prev" + this.id);
    }
});

Text.implement({
    showImage: function()
    {
        if(this.options.nextButton != null)
		    if(this.aktindex >= this.imgarr.length-1)
		        this.options.nextButton.style.visibility = 'hidden';
		    else
		       this.options.nextButton.style.visibility = 'visible'; 
		     
	    if(this.options.prevButton != null)
	        if(this.aktindex == 0)
		        this.options.prevButton.style.visibility = 'hidden';
		    else
		         this.options.prevButton.style.visibility = 'visible';
		         
		         
		         
	    if(this.aktindex >= 0 && this.aktindex < this.imgarr.length)
	    {
	     
	        if(this.options.image != null)
	        {
	            this.options.image.src = this.imgarr[this.aktindex].url;
	            this.options.image.alt = this.imgarr[this.aktindex].legend;
	            
	             if($('legend' + this.id) != null)
	               $('legend' + this.id).innerHTML = this.imgarr[this.aktindex].legend;
	                
	             
	        }
	        
	       
	       
	    }
	    
		
    }
});

Text.implement({
    setButtons: function(){
        
       
           
		if(this.imgarr.length <= 1){
		
		
		   if(this.options.nextButton != null)
                this.options.nextButton.style.visibility = 'hidden';
           if(this.options.prevButton != null)
                this.options.prevButton.style.visibility = 'hidden';
                
		}
		 else 
		{ 
		     if(this.options.nextButton != null)
                this.options.nextButton.style.visibility = 'visible';
            if(this.options.prevButton != null)
                this.options.prevButton.style.visibility = 'visible';
		}
    }
});

Text.implement(new Options); 

function getTextById(id)
{
    for(var i=0;i<textarr.length;i++)
    {
        if(textarr[i].id == id)
            return textarr[i];
    }
    
    return null;
}


