//=========================================
//slice object
//==========================================	

//Descsription: Creates an object called slide that contains text 
// and hyper link.

function slide(link, text)
{
	this.link = link;
	this.text = text;
	
//==========================================
//Description: This funcion add a link to 
//to the slice object.

  this.hotlink = function()
  {
	if (!this.link ) return;
		 location.href = this.link;
  }

//===========================================

//Description: Display content of the page
//to the slice object.
  this.display_slidecontent = function()
  {
	document.write('This is the link: ');
	document.write(this.link);
	document.write('<br /><br />');
	
	document.write('This is the text: ');
	document.write(this.text);
	document.write('<br /><br />');
	
  }
}
//=========================================
//slice object
//==========================================	
//Description: This object contains a set of slide
//in order to use this object you need slice object.

function slideshow(slideshowname)
{
	this.name = slideshowname;   //name of the slice show
	this.repeat = true;			 //setting repeate to true	
	this.textid = "feature_home" 	 //name of the div where the slice show is going to display
	
	this.slides = new Array();	 //array to insert the slides
	this.current = 0;			 //initializing the current slide
	this.timeoutid =0;			 
	this.timeout = 10000;         // setting the time between on slide and the other (3 seconds)

//===================================================		
	this.add_slide = function(slide)    //add slide to slideshow object.
	{
		var i = this.slides.length;	    //get the length
		this.slides[i] = slide;			//assign the slide to the last page
	}  
	
//===================================================	
	this.display_allslides = function()   // display all slides
	{
	  for( i = 0; i < this.slides.length; i++)
	  	this.slides[i].display_slidecontent();
	}
	
//===================================================	
	this.play = function(timeout)   //play the slide show
	{
		this.pause();				
		if (timeout)				
			{
				this.timeout = timeout;	
			}
		timeout = this.timeout;
		this.timeoutid = setTimeout(this.name+ ".loop()", timeout);	

	}
	
//===================================================
	this.pause = function()    //pause the slide show
	{
		if (this.timeoutid != 0)
		{
			clearTimeout(this.timeoutid);
			this.timeoutid = 0;
		}	
	}

//===================================================
	this.update = function()  
	{
		var slide = this.slides[this.current];
		this.display_text();	
	
	}

//===================================================	
	this.next = function()
	{
	
		
		if (this.current < this.slides.length - 1)
		{	
			this.current++;
		}
		else if (this.repeat)
		{
			this.current = 0;
		}
		
		this.update();
	}

//===================================================
	this.display_text = function(text)
	{		 
		 if (!text) 
		 {
      		text = this.slides[ this.current ].text;
    	 }
		 
		 if (this.textid) 
			{
				r = this.getElementById(this.textid);
				if (!r) { return false; }
				if (typeof r.innerHTML == 'undefined') { return false; }
				  r.innerHTML = text ;
			}	
	}
	
//===================================================	
	this.previous = function()
	{
		if (this.current > 0)
		{	
			this.previous--;
		}
		else if (this.repeat)
		{
			this.current = this.slides.length - 1;
		}
		
		this.update();	
	}
	
//=====================================================
	this.get_text = function()
	{
		return(this.slides[this.current].text);
	
	}
		
//=====================================================
	this.get_all_text = function(before_slide, after_slide)
	{
		 all_text = "";
		 for(i=0; i < this.slides.length; i++)
		 {
			slide = this.slides[i]
			if (slide.text)
			{
				all_text += before_slide + slide.text + after_slide;
			}
		 }
		 return (all_text);
	
	}
	
//=====================================================	
	this.hotlink = function()
	{
		this.slides[this.current].hotlink();
	}

//=====================================================	
	this.loop = function()
	{
		
		this.next();
		this.play();
	}
	
//=====================================================

	this.getElementById = function(element_id)
	{
		if (document.getElementById)
		{
			return document.getElementById(element_id);
		
		}
		else if (document.all)
		{
			return document.all[element_id];
		}
		else if (document.layers)
			{
			   return document.layers[element_id];
			}
			else
			{
			   return undefined;
			}
	}
}
