var int = 4500;
var HL = 0;
var NEWSint = 5000;
var NEWSid = 0;
var m_oh = m_ih = m_he = 0;
$(document).ready(function() {
						   
	$(".fancy").fancybox();
	
	if($('#top').length > 0){	
		$('#bg li').slice(1).hide();	
		$('#cars li').slice(1).hide();
		setInterval('ChangeHL();',int);
	}
	m_oh = $('#main').outerHeight(1);
	m_he = $('#main').height();
	c_oh = $('#content').outerHeight(1);
	c_he = $('#content').height();
	setTimeout("Make_it_d_equerre()",1);
	if($('.news').length > 1){
		$('.news').slice(1).hide();
		$('.news').css('position','absolute');
		NEWS = window.setTimeout('RotateNEWS(null)',NEWSint); 
	}
});

function ChangeHL(){
	var nexID = (HL + 1 == $('#cars li').length) ? 0 : HL + 1 ;
	$('#bg li').eq(HL).fadeOut('fast', function(){
		$('#bg li').eq(nexID).fadeIn(1000);
	});
	$('#cars li').eq(HL).animate({
		'margin-left'	:	700
	},200,'easeInOutCirc',function(){
		$('#cars li').eq(HL).hide();
		$('#cars li').eq(nexID).css({
			'margin-left'	:	-700					 
		});
		$('#cars li').eq(nexID).show();
		$('#cars li').eq(nexID).animate({
			'margin-left'	:	0					 
		},'slow','easeInOutCirc',function(){
			HL = nexID;
		});
	});
}

$(window).resize(function() {
    Make_it_d_equerre();
});

/*****************************************************************************************
Réglage hauteur
*****************************************************************************************/

function Make_it_d_equerre(){
	b = $(window).height(); 
	tf = $('#top').outerHeight() + $('#menu').outerHeight() + $('#copyright').outerHeight();
	if((tf + m_oh) > b){
		$('#main').css('height', 'auto');
		$('#content').css('height', 'auto');
	}else{
		nh = b - tf - m_oh + m_he;
		ch = nh - $('#footer').outerHeight(1) - c_oh + c_he;
		$('#main').css('height', nh);			
		$('#content').css('height', ch);
	}
}

/*****************************************************************************************
News
*****************************************************************************************/

function RotateNEWS(id){
    clearTimeout(NEWS);
    if(id != NEWSid){
        $('.news').eq(NEWSid).fadeOut(300);
        if(id != null){
            NEWSid = id;
        }else{
            NEWSid++;
            NEWSid = ($('.news').get(NEWSid)) ? NEWSid : 0 ;   
        }
        $('.news').eq(NEWSid).fadeIn(1000);
    }
    NEWS = window.setTimeout('RotateNEWS(null)',NEWSint);
    return false;
}
