//var oldImg, oldSrc
var oldid, myID;
var first = 0;

$(document).ready(function(){
	
	// On charge l'image dans la fiche article
	//$('#bigimg').html("<img id='bigimg' src='" + $('#' + this.id).attr("src") + "' />");

    function addMega(){  
	oldid = this.id;

	//$("#sous_divs div").each(function (index) {$('#' + this.id).fadeOut('fast');});
	$("#sous_divs div.onglet").each(function (index) {
	      //if(oldid!=this.id){
		  $('#' + this.id).hide();
	      //}
	});

	$('#onglet' + this.id).attr("src","./img/fr/onglet-" + this.id + "+.png");
	$('#div' + this.id).slideDown("slow");

// 	$("#slider" + this.id).easySlider({
// 		auto: true, 
// 		continuous: true
// 	});

	$('#paging_container' + this.id).pajinate({
		items_per_page : 1,
		nav_label_first : '',
		nav_label_prev : '<<',
		nav_label_next : '>>',
		nav_label_last : ''
		
	});

      }  

   function removeMega(){  

 	if(first==0){
 	    $('#onglet' + this.id).attr("src","./img/fr/onglet-" + this.id + ".png");
// 	    $('#div' + this.id).fadeOut('normal');
 	    first=1;
 	}
	
	$("img.onglet").mouseout(function(){
	    //$('#div' + oldid).hide();
	    //$('#div' + oldid).fadeOut('normal');
	    $('#onglet' + oldid).attr("src","./img/fr/onglet-" + oldid + ".png");
	});

	$("div.onglet").mouseover(function() {
	    myID = this.id.substring(3);
	    $('#onglet' + myID).attr("src","./img/fr/onglet-" + myID + "+.png");
	    $(this).show().delay(20000).fadeOut('normal');
	}).mouseleave(function(){
	    myID = this.id.substring(3);
	    $(this).hide().clearQueue();
	    $('#onglet' + myID).attr("src","./img/fr/onglet-" + myID + ".png");
	});

	// Reste delay 10 sec et fadeout
	//$("#sous_divs div").each(function (index) {$('#' + this.id).fadeOut('fast');});

      }  

    var megaConfig = {
         interval: 300,
         sensitivity: 5,
         over: addMega,
         timeout: 200,
         out: removeMega
    };

    $("li.mega").hoverIntent(megaConfig)


// Sur clic onglet 22/04/2011

$("img.onglet").click(
function()
{
	//var catID = "resultat.php?catsup=" + this.id.substring(6);
        var catID = "tuning-" + this.id.substring(6) + "-0-" + $(this).attr("alt") + ".htm";
	if ($('div.mysites').length > 0) {
	      $('div.mysites').slideUp("slow", function(){window.location.replace(catID);});
	} else {
	      window.location.replace(catID);
	}
}
);


// Sur clic onglet
// $("img.scat").click(
// function()
// {
// 
//   if($.cookie("havecar")==1){
// 
// // 	var catID = "resultat.php?catsup=" + this.id.substring(6);
// // 	if ($('div.mysites').length > 0) {
// // 	      $('div.mysites').slideUp("slow", function(){window.location.replace(catID);});
// // 	} else {
// // 	      window.location.replace(catID);
// // 	}
// 
// 	oldid = this.id;
// 
// 	//$("#sous_divs div").each(function (index) {$('#' + this.id).fadeOut('fast');});
// 	$("#sous_divs div.onglet").each(function (index) {
// 	      //if(oldid!=this.id){
// 		  $('#' + this.id).hide();
// 	      //}
// 	});
// 
// 	$('#onglet' + this.id).attr("src","./img/fr/onglet-" + this.id + "+.png");
// 	$('#div' + this.id).slideDown("slow");
// 
// // 	$("#slider" + this.id).easySlider({
// // 		auto: true, 
// // 		continuous: true
// // 	});
// 
// 	$('#paging_container' + this.id).pajinate({
// 		items_per_page : 1,
// 		nav_label_first : '',
// 		nav_label_prev : '<<',
// 		nav_label_next : '>>',
// 		nav_label_last : ''
// 		
// 	});
// 
//   }else{
// 
// 	$("#modalvoiture").modal({
// 		containerCss:{
// 			height:312,
// 			padding:0,
// 			width:707
// 		}
// 	});
// 
// 	//$.cookie("havecar", 1)
//   }
// }
// );

$("a.simplemodal-close").click(function()
{
	$.cookie("havecar", 1)
});

// Animation vignette fiche article
$("img.vignette").mouseover(
function()
{
	//var myID = this.id.substring(3);
	//$('#bigimg').attr("src", $('#' + this.id).attr("src"));

	$('#bigimg').show();
	$('#bigflash').hide();
	$('#bigimg').html("<img id='bigimg' src='" + $('#' + this.id).attr("src") + "' />");
}
);

$("img.flashvid").mouseover(
function()
{
	//var myID = this.id.substring(3);
	$('#bigimg').hide();
	$('#bigflash').show();
}
);





//$('div.corner').corner("bottom tr 10px").parent().css('padding', '2px').css('background', '#f91d1f').corner("bottom tr round 10px");
$("img.corner").imgr({size:"0px",color:"blue",radius:"0px 10px 10px 10px"});



});


