function Offers()
{
	
	this.offers = $('#offer .special_offers_lnk');
	this.current_offer = null;
	
	this.interval = null;
	this.timeout = 4000;
	
	var _obj = this;
	
	$('#offer .special_offers_lnk').mouseover(function(){
		
		clearInterval(_obj.interval);
	});
	
	$('#offer .special_offers_lnk').mouseout(function(){
		_obj.interval = setInterval(function(){ _obj.next() }, _obj.timeout);
	});
	
	$('#offer_bar .offer_idx_link').click(function(){
		$(this).blur();
		var idx = $('#offer_bar .offer_idx_link').index(this);
		
		clearInterval(_obj.interval);
		
		$(_obj.offers[ _obj.current_offer ])
			.hide();
		
		$(_obj.offers[ idx ])
			.show();
			
		$($('#offer_bar .offer_idx_link')[ _obj.current_offer ]	).removeClass('selected');
		$($('#offer_bar .offer_idx_link')[ idx ]	).addClass('selected');
		
		_obj.current_offer = idx;
		_obj.interval = setInterval(function(){ _obj.next() }, _obj.timeout);
		
	})
	
	$('#offer_bar .offer_idx_link').each(function()
		{
			if($(this).hasClass('selected'))
			{
				_obj.current_offer = $('#offer_bar .offer_idx_link').index(this);
			}
		}
	);
	
	this.next = function()
	{
		var next_pos = this.current_offer == (this.offers.length - 1) ? 0 : (this.current_offer + 1);
		
		$(this.offers[ this.current_offer ])
			.hide();
		
		$(this.offers[ next_pos ])
			.show();
			
		$($('#offer_bar .offer_idx_link')[ this.current_offer ]	).removeClass('selected');
		$($('#offer_bar .offer_idx_link')[ next_pos ]	).addClass('selected');
		
		this.current_offer = next_pos;
	}
	
	this.interval = setInterval(function(){ _obj.next() }, this.timeout);
	
}

$(document).ready(function()
	{
		new Offers();
	}
);
