$(document).ready(function(){
	$(document).pngFix(); 
    $('#list-models li a').click(function(){
	loadscoot($(this).attr("class"), 'left');
	return false;
    });

    $('#left-arrow').click(function(){
	var prev = $('#list-models .current').prev();
	if($(prev).html()==null)
	{
	    prev = $('.last');
	}
	loadscoot($(prev).find("a").attr("class"), 'right');
	return false;
    });

    $('#right-arrow').click(function(){
	var next = $('#list-models .current').next();
	if($(next).html()==null)
	{
	    next = $('.first');
	}
	loadscoot($(next).find("a").attr("class"), 'left');
	return false;
    });

    $('#little-left').hover(function(){
	$('#list-models').animate({marginLeft: '0px'}, 3000);
    }, function(){
	$('#list-models').stop();
    });

    $('#little-right').hover(function(){
	//alert($('#list-models li.last').get(0).offsetLeft);
	var maxmove = 400 - $('#list-models li.last').get(0).offsetLeft;
	$('#list-models').animate({marginLeft: maxmove + 'px'}, 3000);
    }, function(){
	$('#list-models').stop();
    });
});

function loadscoot(id, direction)
{
    var first;
    var second;
    if(direction=='left')
    {
	first = '-1000px';
	second = '1000px';
    }
    else
    {
	first = '1000px';
	second = '-1000px';
    }
    //obj = jQuery('.' + id + ' a').get(0);
    var leftmove = 250 - $('#list-models li a.' + id).parent('li').get(0).offsetLeft;
    //alert(leftmove);
    if(leftmove > 20 ) leftmove = 0;

    $('#list-models').animate({marginLeft: leftmove + 'px'}, 500);
    
    $('#fiche-inside').animate({marginLeft: first}, 500, function(){
	$.getJSON("/scooters/json/" + id, function(data){
	    $('#list-models .current').removeClass('current');
	    $('.' + id).parent('li').addClass("current");
	    $('#right-content h1').html('<a href="' + data.lien + '">' + data.modele + '</a>');
	    $('#description').html(data.description);
	    $('#reserver').html(data.reserver);
	    $('#left-image').html(data.image);
            var tarifs = '';
            if(data.tarifs.length>0)
            {
                tarifs = '<table><tr><th width="150" class="duree">Dur&eacute;e</th><th width="40" class="prix">Prix</th><th width="40" class="kms">kms</th></tr>';
                for(var i =0; i < data.tarifs.length; i++)
                {
                    tarifs += '<tr><td>' + data.tarifs[i].duree + '</td><td>' + data.tarifs[i].prix + '</td><td>' + data.tarifs[i].kms + '</td></tr>'
                }
                tarifs += '</table>';
            }
	   $('#tarifs').html(tarifs);
	   pageTracker._trackPageview(data.modele);
	   $('#fiche-inside').css("margin-left", second);
	   $('#fiche-inside').animate({marginLeft: "0px"}, 500);
        });
    });
    
}


