var vid=0;

function init() {
	// laisser à l'internaute le choix d'ouvrir dans un nouvel onglet ou non
// 	$("#contenu a").click(function() {
// 		window.open(this.href);
// 		return false;
// 	});

	$("a").live("mousedown",function() {
		return false;
	});

	$("#funnymenu > .activemenu").css({paddingBottom: 10, paddingTop: 10});

	$("#funnymenu > .funnyitem").click(function() {
		resizeFunnyTab($("#funnymenu > .activemenu"),0);
		$("#funnymenu > .activemenu").removeClass("activemenu");
		$("#funnycontent > .activecontent").removeClass("activecontent");
		$("#c"+$(this).attr("id")).addClass("activecontent");
		$(this).addClass("activemenu");
	});

	$("#funnymenu > .funnyitem").
		mouseover(expandFunnyTab).
		mouseout(contractFunnyTab);

	if ($("#funnymenu").size()>0) {
		charge_video(0);
		$("#next_video").click(function() {charge_video(vid+1);});
		$("#prev_video").click(function() {charge_video(vid-1);});
	}

    draw_quote('DTC','0');

    $("#prev_DTC").click(function() {
        draw_quote('DTC','-1');
    });
    $("#next_DTC").click(function() {
        draw_quote('DTC','1');
    });
    $("#prev_CNF").click(function() {
        draw_quote('CNF','-1');
    });
    $("#next_CNF").click(function() {
        draw_quote('CNF','1');
    });

    $(".button").mousedown(function(event) {return false;});

	$("#JDM img").mouseover(shakeJDM);

}

function shakeJDM() {
	for (var i=3; i>0; i--) {
		$(this).
			animate({marginLeft:-5*i, width: 300+i*10, height:58}, 100).
			animate({marginLeft:0, width: 300, height:58}, 100);
	}
}

function expandFunnyTab() {
	if (!$(this).hasClass("activemenu")) resizeFunnyTab(this,10);
}

function contractFunnyTab() {
	if (!$(this).hasClass("activemenu")) resizeFunnyTab(this,0);
}

function resizeFunnyTab(obj,val) {
	$(obj).animate({paddingBottom: val, paddingTop: val}, {queue:false, duration:200});
}

function charge_video(n) {
    $(".video:eq("+vid+")").css("display","none");
    if (n==$(".video").length) n=0;
    else if (n<0) n=$(".video").length-1;
    $(".video:eq("+n+")").css("display","block");
    vid=n;
}

function draw_quote(nom,val) {
    $.post("script/get_quote.php", {quote: nom, inc: val}, function(quote) {
        $("#quote").html(quote);
    });
}

