BestOffersNav =
{
	IDContainer : 'best-offers-inner',
	Viewport : 0,
	Params : '' ,
	Range : '',
	Step : 0,
	Width : '' ,
	
	Init : function(StartRange,MyStep,ExtraParams)
	{
		this.Range	= StartRange ;
		this.Step	= MyStep ;
		this.Params	= ExtraParams ;
	},
	
	InitViewport : function()
	{
		this.Viewport = $('.viewport') ;
		this.Width	= $('div:first',this.Viewport).width() ; 
		$('div:first',this.Viewport).css('width','4000px') ;
	},
	
	HandleResponse : function(data,NRange,Toggle)
	{
		if(data=='' || this.Range==NRange ) return ;
		
		this.Range = NRange ;
		
		if(!this.Viewport) this.InitViewport() ;
		
		switch(Toggle)
		{
			case 'prev' :
				var nbElt = $('.viewport-content').length ;
				if(nbElt<2)
				{
					var first = $('.viewport-content:first') ;
					$('#'+this.IDContainer+' > div').prepend( data ) ;
					
					
					$('.viewport-content').css('float','left') ;
					$('.viewport-content').width(this.Width) ;
					
					
					$('.viewport-content:first').css('marginLeft','-'+this.Width+'px') ;
					
					$('.viewport-content:first').animate(
						{ marginLeft: "0" }, 1500 ,'', function(){ first.remove() }
					);
				}
				else
				{
					$('.viewport-content').each(function(){ $(this).remove() });
					$('#'+this.IDContainer+' > div').prepend( data ) ;
				}
			break ;
			case 'next':
				var nbElt = $('.viewport-content').length ;
				if(nbElt<2)
				{
					$('#'+this.IDContainer+' > div').append( data ) ;
					
					$('.viewport-content').css('float','left') ;
					$('.viewport-content').width(this.Width) ;
					
					$('.viewport-content:first').animate(
						{ marginLeft: "-"+this.Width+"px" }, 1500 ,'', function(){ $(this).remove() }
					);
				}
				else
				{
					$('.viewport-content').each( function(){ $(this).remove() } );
					$('#'+this.IDContainer+' > div').prepend( data ) ;
				}
			break ;
		}
	},
	
	ShowBestOffers : function(toggle)
	{
		var TRange	= this.Range.split(',') ;
		var Beg		= parseInt(TRange[0]) ;
		var End		= parseInt(TRange[1]) ;
		
		if(toggle=='prev')
			Beg = parseInt(Beg)-parseInt(this.Step);
		else
			Beg = parseInt(Beg)+parseInt(this.Step) ;
			
		if(Beg<0) Beg=0 ;
		
		var NewRange = Beg+','+End ;
		
		var data = 'range='+NewRange+'&q=best-offers&'+this.Params ;
		
		var file = '/ajax-response.php'
		
		var _this = this ;
		
		 $.post(file, data,
    		function(data){
    			_this.HandleResponse(data,NewRange,toggle) ;
      		}) ;
	},
	
	ShowPrevBestOffers : function()
	{
		this.ShowBestOffers('prev') ;
	},
	
	ShowNextBestOffers : function()
	{
		this.ShowBestOffers('next') ;
	}
} ;

$(function()
{
  $('#bo-prev').click(
  	function() { BestOffersNav.ShowPrevBestOffers() ; }) ;
  $('#bo-next').click(
  	function() { BestOffersNav.ShowNextBestOffers() ; }) ;
  
}) ;
