$(document).ready(function() {
    $('#popupAssurance').hide();
    $('.activationAss').mouseover(
		    function(e) {
		        if (!$('#popupAssurance').is(':visible')) {
		            $('#popupAssurance').show();
		        }
		    });
    $('.activationAss').mouseout(
		    function(e) {
		        $('#popupAssurance').hide();
		    });

    $("img").easyTooltip();
    $("img.help").easyTooltip({
        tooltipId: "tooltip",
        content: 'Avec le code sourire Banque Casino, acc\351dez directement \340 l\'offre personnelle qui vous a \351t\351 r\351serv\351e.'
    });

    $("img.help2").easyTooltip({
        tooltipId: "tooltip2",
        content: 'Je veux emprunter<br/><strong>MOINS</strong><br/>et rembourser<br/><strong>X XXX &euro; par mois</strong>'
    });

    $("img.help2Plus").easyTooltip({
        tooltipId: "tooltip2",
        content: 'Je veux emprunter<br/><strong>PLUS</strong><br/>et rembourser<br/><strong>X XXX &euro; par mois</strong>'
    });

    $("img.help3").easyTooltip({
        tooltipId: "tooltip3",
        content: 'Je veux emprunter<br /><strong>XX XXX &euro;</strong><br />et rembourser<br/><strong>MOINS chaque mois</strong>'
    });

    $("img.help3Plus").easyTooltip({
        tooltipId: "tooltip3",
        content: 'Je veux emprunter<br /><strong>XX XXX &euro;</strong><br />et rembourser<br/><strong>PLUS chaque mois</strong>'
    });

    $("#container").pngFix();
    layerPack();

    /*********** MENU************/
    var timeout = 500;
    var closetimer = 0;
    var ddmenuitem = 0;

    function nav_open() {
        nav_canceltimer();
        nav_close();
        ddmenuitem = $(this).find('ul').css('visibility', 'visible');
        $(this).find('a:first').addClass('selected');
    }

    function nav_close()
    { if (ddmenuitem) ddmenuitem.css('visibility', 'hidden'); }

    function nav_timer() {
        closetimer = window.setTimeout(nav_close, timeout);
        $(this).find('a:first').removeClass('selected');
    }

    function nav_canceltimer() {
        if (closetimer) {
            window.clearTimeout(closetimer);
            closetimer = null;
        }
    }

    $(document).ready(function() {
        $('#mainNav > li').bind('mouseover', nav_open)
        $('#mainNav > li').bind('mouseout', nav_timer)
    });

    /*********** ESPACE PERSO FORMULAIRE *********/
    $('.Open').click(

		function(e) {
		    e.preventDefault();
		    if ($(this).children().attr('src') == '../img/illus_arrow-close.gif') {
		        $(this).children().attr('src', '../img/illus_arrow-open.gif');
		    } else {
		        $(this).children().attr('src', '../img/illus_arrow-close.gif');
		    }
		    $(this).parent().parent().toggleClass("open");
		    $(this).closest('.espaceFormulaireMast').next().toggle('Fade');
		}
	);
    /*********** GESTION LAYER CLIENT ************/
    document.onclick = nav_close;

    $('#espace_client .detail').hide();
    $('#espace_client .seeMore').click(
		function(e) {
		    e.preventDefault();
		    $(this).toggleClass('open');
		    $('#espace_client .detail').toggle();
		});

    $('.plusMinus').click(

		function(e) {
		    e.preventDefault();
		    if ($(this).children().attr('src') == '../img/ico_plus.gif') {
		        $(this).children().attr('src', '../img/ico_minus.gif');
		    } else {
		        $(this).children().attr('src', '../img/ico_plus.gif');
		    }
		    $(this).parent().parent().toggleClass("open");
		    $(this).closest('.itemContract ').next().toggle('Fade');
		}
	);

    $('.openClose').click(

		function(e) {
		    e.preventDefault();
		    if ($(this).children().attr('src') == '../img/btn_plus.gif') {
		        $(this).children().attr('src', '../img/btn_minus.gif');
		    } else {
		        $(this).children().attr('src', '../img/btn_plus.gif');
		    }
		    $(this).parent().parent().toggleClass("open");
		    $(this).closest('.amalineFormFoot').prev().toggle('Fade');
		}
	);

    /*********** GESTION LAYER FORMULE ************/
    $('.detailEconomique').hide();
    $('.seeMoreEco').click(
		function(e) {
		    e.preventDefault();
		    $(this).toggleClass('open');
		    $('.detailEconomique').toggle();
		});

    $('.detailBasique').hide();
    $('.seeMoreBasic').click(
		function(e) {
		    e.preventDefault();
		    $(this).toggleClass('open');
		    $('.detailBasique').toggle();
		});

    $('.detailMedium').hide();
    $('.seeMoreMedium').click(
		function(e) {
		    e.preventDefault();
		    $(this).toggleClass('open');
		    $('.detailMedium').toggle();
		});

    $('.detailComplete').hide();
    $('.seeMoreComplete').click(
		function(e) {
		    e.preventDefault();
		    $(this).toggleClass('open');
		    $('.detailComplete').toggle();
		});

    $('.detailOptimale').hide();
    $('.seeMoreOptimale').click(
		function(e) {
		    e.preventDefault();
		    $(this).toggleClass('open');
		    $('.detailOptimale').toggle();
		});

    /*********** FAQ QUITTER LAYER QUESTIONS ************/
    $('.faqOpen').hide();
    $('.readMore').click(
		function(e) {
		    e.preventDefault();
		    $(this).toggleClass('open');
		    $('.faqOpen').toggle();
		});

    $('.faqOpenFinancement').hide();
    $('.readMoreFinancement').click(
		function(e) {
		    e.preventDefault();
		    $(this).toggleClass('open');
		    $('.faqOpenFinancement').toggle();
		});

    $('.faqOpenFonds').hide();
    $('.readMoreFonds').click(
		function(e) {
		    e.preventDefault();
		    $(this).toggleClass('open');
		    $('.faqOpenFonds').toggle();
		})

    $('.faqOpenDemander').hide();
    $('.readMoreDemander').click(
		function(e) {
		    e.preventDefault();
		    $(this).toggleClass('open');
		    $('.faqOpenDemander').toggle();
		})

    $('.faqOpenDeplafonnement').hide();
    $('.readMoreDeplafonnement').click(
		function(e) {
		    e.preventDefault();
		    $(this).toggleClass('open');
		    $('.faqOpenDeplafonnement').toggle();
		})

    $('.faqOpenMensualites').hide();
    $('.readMoreMensualites').click(
		function(e) {
		    e.preventDefault();
		    $(this).toggleClass('open');
		    $('.faqOpenMensualites').toggle();
		})

    $('.faqOpenRefusee').hide();
    $('.readMoreRefusee').click(
		function(e) {
		    e.preventDefault();
		    $(this).toggleClass('open');
		    $('.faqOpenRefusee').toggle();
		})

    $('.faqOpenReleve').hide();
    $('.readMoreReleve').click(
		function(e) {
		    e.preventDefault();
		    $(this).toggleClass('open');
		    $('.faqOpenReleve').toggle();
		})

    /*********** GESTION LAYER CALCULATRICE ************/
    $('#accessCode').hide();
    $('#connectFirst .btnValider').click(
		function(e) {
		    e.preventDefault();
		    $(this).toggleClass('open');
		    $('#accessCode').toggle();
		});


    $('#accessCodePerso').hide();
    $('#connectPerso .btnValider').click(
		function(e) {
		    e.preventDefault();
		    $(this).toggleClass('open');
		    $('#accessCodePerso').toggle();
		});

    $('#bulle').hide();
    $('#hoverBulle').hover(
		function(e) {
		    e.preventDefault();
		    $(this).toggleClass('open');
		    $('#bulle').toggle();
		});

    $('#bullePerso').hide();
    $('#hoverBullePerso').hover(
		function(e) {
		    e.preventDefault();
		    $(this).toggleClass('open');
		    $('#bullePerso').toggle();
		});

    $('.encartbloc .more').hide();
    $('.encartbloc .showHide').click(
		function(e) {
		    e.preventDefault();
		    $(this).parent('div').find('div.more').slideToggle();
		    $(this).toggleClass('open');
		});

    $('a.basic').click(function(e) {
        e.preventDefault();
        $('#popUp').modal();
    });

    /*********** Assurance chien et chat V3 ************/
    $('a.toggleBlock').click(
		function(e) {


		    e.preventDefault();
		    if ($(this).children().attr('src') == '/Style Library/img/btn_plus-assurance.gif') {
		        $(this).children().attr('src', '/Style Library/img/btn_minus-assurance.gif');
		    } else {
		        $(this).children().attr('src', '/Style Library/img/btn_plus-assurance.gif');
		    }
		    $(this).closest('div').next('.container').toggle().toggleClass("open");
		}
	);

    /*********** FACILITE PAIEMENT ************/
    $('#type1').hide();
    $('.facilitesPaiement #openType1').click(
		function(e) {
		    e.preventDefault();
		    $(this).toggleClass('open');
		    $('#openType1').hide();
		    $('#secondType').hide();
		    $('#thirdType').hide();
		    $('#type1').toggle();
		});

    $('#type1').hide();
    $('#type1 .close').click(
		function(e) {
		    e.preventDefault();
		    $(this).toggleClass('open');
		    $('#openType1').show();
		    $('#secondType').show();
		    $('#thirdType').show();
		    $('#type1').toggle();
		});

    $('#type2').hide();
    $('.facilitesPaiement #openType2').click(
		function(e) {
		    e.preventDefault();
		    $(this).toggleClass('open');
		    $('#openType2').hide();
		    $('#firstType').hide();
		    $('#thirdType').hide();
		    $('#type2').toggle();
		});

    $('#type2').hide();
    $('#type2 .close').click(
		function(e) {
		    e.preventDefault();
		    $(this).toggleClass('open');
		    $('#openType2').show();
		    $('#firstType').show();
		    $('#thirdType').show();
		    $('#type2').toggle();
		});

    $('#type3').hide();
    $('.facilitesPaiement #openType3').click(
		function(e) {
		    e.preventDefault();
		    $(this).toggleClass('open');
		    $('#openType3').hide();
		    $('#firstType').hide();
		    $('#secondType').hide();
		    $('#type3').toggle();
		});

    $('#type3').hide();
    $('#type3 .close').click(
		function(e) {
		    e.preventDefault();
		    $(this).toggleClass('open');
		    $('#openType3').show();
		    $('#firstType').show();
		    $('#secondType').show();
		    $('#type3').toggle();
		});

    // ESPACE PERSO FORMULAIRE AFFICHAGE BLOC JEUNE FILLE //
    $('.nomJeuneFille').hide();
    $('.mme').click(
		function(e) {
		    //e.preventDefault();
		    $('.nomJeuneFille').show();
		});
    $('.mlle').click(
		function(e) {
		    //e.preventDefault();
		    $('.nomJeuneFille').hide();
		});
    $('.mr').click(
		function(e) {
		    //e.preventDefault();
		    $('.nomJeuneFille').hide();
		});

    $('.CDD').click(
		function(e) {
		    //e.preventDefault();
		    $('.finContrat').hide();
		});
    $('.CDI').click(
		function(e) {
		    //e.preventDefault();
		    $('.finContrat').show();
		});
    $('.Autre').click(
		function(e) {
		    //e.preventDefault();
		    $('.finContrat').show();
		});

    // choisir une seul checkbox dans un group
    var checkboxes = $(".ckbox");
    checkboxes.click(function() {
        var self = this;
        checkboxes.each(function() {
            if (this != self) this.checked = ''
        });
    });

    var checkboxes2 = $(".ckbox2");
    checkboxes2.click(function() {
        var self = this;
        checkboxes2.each(function() {
            if (this != self) this.checked = ''
        });
    });

    // parametrage de l'onglet qui est ouvert par default
    $('div.t2, div.t3').hide();
    $('div.t1').show();
    $('.assType ul.tab .defaultOpen').addClass('current');
    // Ouverture et fermetures des autre onglets
    $('.assType .tab li').click(function() {
        var thisClass = this.className.slice(0, 2);
        $('.assType div').hide();
        $('.assType div div').show();
        $('div.' + thisClass).show();
        $('.assType ul.tab li').removeClass('current');
        $(this).addClass('current');
        //$('.conditionCont').hide();
    });

    //$('.conditionCont').hide();
    $('.condition .opener a').click(
	function(e) {
	    e.preventDefault();
	    $(this).parent().toggleClass("open");
	    $(this).closest('.opener').next().toggle();
	});

    $('#souscrire').click(function(e) {
        var nePasSouscrire = $('#souscrire').attr('checked');

        if (nePasSouscrire == true) {
            $('.checkboxAss').css('visibility', 'hidden');
            $('.checkboxAss').addClass(' hideMe');
        }
        else if (nePasSouscrire == false) {
            $('.checkboxAss').css('visibility', 'visible');
            $('.checkboxAss').removeClass(' hideMe');
        }
    });

    /*********** BCA PAGE ACTU OVERTURE/FERMETURE BLOC *********/
    $('.firstActualites').show();
    $('.toggleActu').click(
		function(e) {
		    e.preventDefault();
		    var jThis = $(this);
		    var jChildren = jThis.children();
		    if (jChildren.attr('src') == '/Style%20Library/img/btn_close.gif') {
		        jChildren.height(9).width(13).attr('src', '/Style%20Library/img/btn_open.gif');
		        jThis.parents('.heading').next('.actualites').slideDown();
		    }
		    else {
		        jChildren.height(13).width(9).attr('src', '/Style%20Library/img/btn_close.gif');
		        jThis.parents('.heading').next('.actualites').slideUp();
		    }
		});

});

	/*********** GESTION SLIDER ************/  
	function changeAmount(value){ 	
		if(value <= 800){
			$("#amount").val(20);
			$("#montant").html('20 &euro;/mois');
		}else if(value > 800 && value <= 1524){
			$("#amount").val(40);
			$("#montant").html('40 &euro;/mois');
		}else if(value > 1524 && value <= 2300){
			$("#amount").val(60);
			$("#montant").html('60 &euro;/mois');
		}else if(value > 2300 && value <= 3000){
			$("#amount").val(80);
			$("#montant").html('80 &euro;/mois');
		}else if(value > 3000 && value <= 4000){
			$("#amount").val(100);
			$("#montant").html('100 &euro;/mois');
		}else if(value > 4000 && value <= 5000){
			$("#amount").val(120);
			$("#montant").html('120 &euro;/mois');
		}else{
			$("#amount").val(value*0.025);
			$("#montant").html(value*0.025+' &euro;/mois');
		}
	}
				
	$.fn.BCSlider = function(option){
		$(this).slider(option);
			
		$(this).each(function(i,slider){
			val = $(this).slider('value');
			$(slider).find('.ui-slider-handle').html('<span id="sliderValue">' + val + '</span>');
		});
						
		$(this).bind('slide', function(event, ui) {
		  	val = ui.value; 
			$(this).find('#sliderValue').html( val + '&euro;' );
			changeAmount(val);
		});			
	}


/*********** GESTION LAYER PACK ************/
layerPack = function() {

	$('.layer').hide();
	//$('#layerpack2').show();

	var timeout = 500;
	var closetimer = 0;
	var ddmenuitem = 0;
	
	function nav_open(currentId){
		nav_canceltimer();
		nav_close();
		ddmenuitem = $('#'+currentId).show();
		$('#' + currentId.replace('layer','') ).attr('src',function(i,src){
			return src.replace('.jpg','_on.jpg');
		});
	}

	function nav_close(){  
		if(ddmenuitem)  ddmenuitem.hide();
		$('.pack').attr('src',function(i,src){
			return src.replace('_on.jpg','.jpg');
		});
	}

	function nav_timer(){  
		closetimer = window.setTimeout(nav_close, timeout);
	}

	function nav_canceltimer(){
		if(closetimer){  
			window.clearTimeout(closetimer);
			closetimer = null;
		}
	}
	
	$('.pack,.layer').hover(
		function(e){
			currentId = $(this).hasClass('layer') ? $(this).attr('id') : 'layer' + $(this).attr('id');
			nav_open(currentId);
		},
		function(e) {
		    // Contournement bug IE
		    if (window.event && window.event.toElement == null) {
		        return;
		    }
		    nav_timer();
		}
	);
}








// ******************************************************************************************
// Ouvrir PopUp - page gamme-cartes
// ******************************************************************************************
function validateFrmCarte(Form)
{
	if(Form.radioCarte[0].checked)
	{
		jQuery(".layerFormCarte").css("display", "none");
		jQuery("#bgddiv").unbind("click")
						 .bind("click", function () {
							
							closePopUp(".layerCarteSmile");
							 
						 });
						 
		openPopUp(".layerCarteSmile");
	}
	else if(Form.radioCarte[1].checked)
	{
		window.open("https://espace-client-secure.banque-casino.fr/fr/PCR5_CASINO_Default.aspx", "windowName");
	}
}



function openlayerFormCartePopUp()
{
	displayBackgroundPopUp(".layerFormCarte");	
}

function openComparezPopUp() {
    displayBackgroundPopUp(".layerComp");
}

function displayBackgroundPopUp(layerClass) {

    Height = jQuery(document).height();

    jQuery("<iframe>").load(function() {

        jQuery(document).scrollTop(0);
        openPopUp(layerClass);

    })
					  .attr("src", "background.html")
                      .attr("frameborder", "0")
                      .attr("scrolling", "no")
                      .attr("id", "bgdiframe").css({ top: 0,
                          left: 0,
                          width: '100%',
                          height: Height,
                          position: 'absolute',
                          display: 'block',
                          zIndex: 998,
                          border: 0,
                          opacity: 0.7
                      }).appendTo("body");

    jQuery("<div>").attr("id", "bgddiv").css({ top: 0,
        left: 0,
        width: '100%',
        height: Height,
        position: 'absolute',
        display: 'block',
        zIndex: 999,
        border: 0,
        backgroundColor: '#fff',
        opacity: 0.1
    })
										  .click(function() { closePopUp(layerClass); })
										  .appendTo("body");
}

function undisplayBackgroundPopUp() {

    jQuery("#bgddiv").remove();
    jQuery("#bgdiframe").remove();
}

function openPopUp(LayerClass) {

    // Open Popup
    LayerObj = jQuery(LayerClass);
    LayerWidth = LayerObj.width();
    LayerHeight = LayerObj.height();
    windowWidth = jQuery(window).width();
    windowHeight = jQuery(window).height();
    documentWidth = jQuery(document).width();
    documentHeight = jQuery(document).height();

    Left = (documentWidth / 2) - (LayerWidth / 2);
    //Top = (documentHeight / 2) - (LayerHeight / 2);
    Top = 170;

    LayerObj.css({ display: 'block', top: Top, left: Left });

    // Undisplay telechargement
}

function closePopUp(LayerClass) {

    // close popup
    LayerObj = jQuery(LayerClass);
    LayerObj.css({ display: 'none' });

    undisplayBackgroundPopUp();
}

// ******************************************************************************************
// Ouvrir PopUp - page gamme-cartes
// ******************************************************************************************

$(document).ready(function() {
    $('.goldCard').hover(function(e) {
        $('.blocCarteGold').toggle();
        $('.blocMastercard').toggle();
    });

    $(".layerComp").pngFix();
});
