/****************************************************************/
/***  PUFF OBJECT FUNCTIONS									  ***/
/****************************************************************/

function Puff()
{
	var speed = 5000;
	
	// Init
	this.count = 0;
	this.current = 0;
	this.image = [];
	this.text = [];
	this.link = []
	this.target = [];
	this.aclass = [];
	this.divContent = '';
	this.divButtons = '';
	this.playID = '';
	
	// Add puff
	this.add = function(img, txt, link, target, aclass)
	{
		this.count = this.count + 1;
		this.image[this.count] = img;
		this.text[this.count] = txt;
		this.link[this.count] = link;
		this.target[this.count] = target;
		this.aclass[this.count] = aclass;
	};
	
	// Set DIV Content
	this.setDivContent = function(divID)
	{
		// Set Content div id
		this.divContent = divID;
	}
	
	// Set DIV Buttons
	this.setDivButtons = function(divID)
	{
		// Set Buttons div id
		this.divButtons = divID
		
		// Set Play/Pause button to visible
		$("#" + this.divButtons + " #divPausePlay").removeClass("hide");
	}
	
	// Display puff
	this.show = function(itemNum)
	{	
		// Show NEXT item
		if (itemNum == 0)
		{
			this.current = this.current + 1;
		}
		else
		{
			if (this.current == 0)
			{
				this.current = 1;
			}
			this.current = itemNum;
		}
		
		// Check if current item > count
		if (this.current > this.count)
		{
			this.current = 1;
		}
		
		// Construct HTML
		var sHTML;
		if (this.link[this.current].length > 0)
		{
			sHTML = "<a href='" + this.link[this.current] + "' title='read more' target='" + this.target[this.current] + "'><img src='" + this.image[this.current] + "' height='95' width='128' alt='' border='0' /></a>" + this.text[this.current] + "<a href='" + this.link[this.current] + "' title='read more' target='" + this.target[this.current] + "'>read more &gt;&gt;</a>"
		}
		else
		{
			sHTML = "<img src='" + this.image[this.current] + "' height='95' width='128' alt='' border='0' />" + this.text[this.current];
		}
		
		// Display item
		$("#" + this.divContent).fadeOut("slow", function()
		{
			$(this).html(sHTML).fadeIn("slow");
			
		});
		
		// Clear buttons
		$("#" + this.divButtons + " a div").removeClass("selected");
		
		// Set selected button
		$("#" + this.divButtons + " a." + this.aclass[this.current] + " div").addClass("selected");
	};
	
	// PLAY function
	this.play = function()
	{
		// Set PLAY timer
		this.playID = setInterval(function() {puff.show(0)}, speed);
		
		// Set Play button
		$("#" + this.divButtons + " #divPausePlay").removeClass("button_play");
		$("#" + this.divButtons + " #divPausePlay").addClass("button_pause");
		
		// Set OnClick on Play button
		$("#divPausePlay").unbind("click");
		$("#divPausePlay").click(
			function()
			{
				puff.pause();
				return false;
			}
		);
	}
	
	// PAUSE function
	this.pause = function()
	{
		// If PLAYING, STOP
		if (this.playID != '')
		{
			clearTimeout(this.playID);
		}
		
		// Set Pause button
		$("#" + this.divButtons + " #divPausePlay").removeClass("button_pause");
		$("#" + this.divButtons + " #divPausePlay").addClass("button_play");
		
		// Set OnClick on Play button
		$("#divPausePlay").unbind("click");
		$("#" + this.divButtons + " #divPausePlay").click(
			function()
			{
				puff.play();
				return false;
			}
		);
	}
}