$(document).ready(function(){
    
    /*******************************************************************/    
    //Hide All the .help layer at starting
    $('.help').hide();
    
    // Add click Behavior on Open / Close Help Button
    $('.openHelp').click(function(e){
        e.preventDefault();
        $('.help').hide();
        idHelp = $(this).attr('href').replace('#','');
        $('#' + idHelp).show();
    });
    
    $('.closeHelp').click(function(e){
        e.preventDefault();
        $(this).closest('.help').fadeOut()
    });
    
    $('.plusMoinsProduitFamille, #plusMoinsProduit').show();
    
    $('.qtyMore').click(function(e){
       inputField = $(this).closest('div.qtyContainer').find('input.qty');
       newVal = parseInt(inputField.val()) +1 < 1000 ? parseInt(inputField.val()) +1 : 999;
       inputField.val(newVal);      
    });
    
    $('.qtyLess').click(function(e){
       inputField = $(this).closest('div.qtyContainer').find('input.qty');
       newVal = parseInt(inputField.val()) - 1 > 1 ? parseInt(inputField.val()) - 1 : 1;
       inputField.val(newVal);
       
    });
    
    $('.updateCart').click(function(e){
        e.preventDefault();
        $('#panier').load($(this).closest('form').attr('action') , $(this).closest('form').serialize( ), function(){
            ajaxifyCart();} 
        );
    });
    
   ajaxifyCart();
   
   
   /********************************
    * Methodo et FAQ
    *******************************/
    $('.FaqLev').hide();
    $('.opener').toggle(
        function(){$(this).siblings('.FaqLev').slideDown('normal');},
        function(){$(this).siblings('.FaqLev').slideUp('normal');}
    );
    
    
    /*****************************
     * Comparateur Flash
     ****************************/
     if ($('#charteGraphique').size() > 0){
        var flashvars = {'xmlUrl': '/swf/xmlComp.xml'};
        var params = {'wmode ': '#transparent','quality':'high'};
        var attributes = {};
        swfobject.embedSWF("/swf/chart.swf", "charteGraphique", "528", "420", "8.0.0","expressInstall.swf", flashvars, params, attributes);
    }
    
    
    

/*var so = new SWFObject("compare.swf?linkURL=home.asp&amp;titleDate=du+1er+septembre+au+28+septembre+2009&amp;basketDate=entre+le+1er+sepembre+et+le+28+septembre+2009&amp;trackingURL1=<%=url4date%>&amp;trackingURL2=<%=url4post%>", "exampleJSON", "733", "504", "8", "#FFFFFF");
so.addParam("wmode","transparent");
so.write("flashDiv");
// For test sake, we wait a while before sending JSON string to Flash.
setTimeout (function () { document.getElementById("exampleJSON").SetVariable("jsonString", tabPanier.toJSONString()); }, 5000);
*/
     
     
     
 

    
    
});

//uniquement pour le flash
function showHelpComparaison(id){
    $('#' + id).show();
}

function ajaxifyCart(){
    $('.cartAjaxify').click(function(e){
        e.preventDefault();
        $('#panier').load( $(this).attr('href') ,'', function(){ajaxifyCart()} );
    });
    $('#lienComparateur').attr('href', $('#lienComparateur').attr('href') + '?withFlash=1' );
}