function equalHeight(group) {
	var tallest = 0;
	group.each(function() {
		var thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}

function parseNavigation(id) {
	brows = navigator.appName.toLowerCase();
	
	$("#"+id+" li:first").addClass("first");
	$("#"+id+" li:last").addClass("last");
	
	$("#"+id+" li").each(function(){
		if ($('ul',this).length != 0) {
			$(this).addClass("hassub");
					
			$(this).bind("mouseover",function(){
				$(this).addClass("hover");
				$("ul:first",this).addClass("over");
			})
			//si c'est ie on utilise mouseleave pour eviter le flickering
			if (brows.indexOf("microsoft") != -1 || brows.indexOf("msie") != -1) {
				$(this).bind("mouseleave",function(){
					$(this).removeClass("hover");
					$("ul:first",this).removeClass("over");
				})
			} else {
				$(this).bind("mouseout",function(){
					$(this).removeClass("hover");
					$("ul:first",this).removeClass("over");
				})
			}
		} else {
			this.onmouseover = function() {	$(this).addClass("hover"); }
			
			//si c'est ie on utilise mouseleave pour eviter le flickering
			if (brows.indexOf("microsoft") != -1 || brows.indexOf("msie") != -1) {
				this.onmouseleave = function() { $(this).removeClass("hover"); }
			} else {
			 	this.onmouseout = function() {	$(this).removeClass("hover"); }
			}
		}
	});
}


var currentTab = '';

$(function() {

    if (currentTab == '') {
        currentTab = '#tabs1';
        $('a[href*=#tabs1]').parent().parent().addClass("selected");
        $(currentTab).show();
    }


    // Gestion du click sur les tabs en bas
    $("#bottom_cta li a").click(function(e) { e.preventDefault(); });
    $("#bottom_cta li a").hover(function(e) {

        if (!$(this).parent().parent().hasClass("selected")) {
            $("#bottom_cta li.selected").removeClass("selected");
            $(this).parent().parent().addClass("selected");
            $("#barre_slideshow").slideDown("fast");
            //$($(this).attr("href")).show();	

            if (currentTab != '') {
                $(currentTab).hide();
            }

            $($(this).attr("href")).show();
            currentTab = $(this).attr("href");
        } else {
            $("#barre_slideshow").slideDown("fast");
        }

    });


    //FAQ

    $("#faq li a:first-child").click(function(e) {
        $(this).parent().find("div").show();
        e.preventDefault();
    })
    $("#faq p.btn_fermer a").click(function(e) {
        $(this).parent().parent().parent().find("div").hide();
        e.preventDefault();
    });
    //

    $(".blocFestival:first").addClass("first");
    $(".blocFestival:last").addClass("last");
    equalHeight($(".blocFestival"));

    $(".opencontent a").click(function(e) {
        if ($(this).hasClass("open")) {
            $("#zone_content .hidden").hide();
            $(this).removeClass("open");
        } else {
            $("#zone_content .hidden").show();
            $(this).addClass("open");
        }
        e.preventDefault();
    });




    parseNavigation("subnav");



    var tempVal;

    // gestion du click sur les fleches pour le nombre de billets
    $("a.choose").click(function() {
        tempVal = this;
        var pos = $(this).parent().position();

        $("#zone_content").append(
				$(this).siblings(".listesNB")
				.clone(true)
				.attr("id", "tempListe")
				.css("top", pos.top)
				.css("left", pos.left)
				.css("display", "block")
			);
        return false;
    });
    $(".listesNB").mouseleave(function() { $(this).remove(); });

    // click quand on choisi un nombre
    $("#catalogue_fiche_produit .listesNB a").click(function() {
        $(this).parent().parent(".listesNB").remove();

        var selQte = $(this).attr("title");
        var selValeurPrixQte = $(this).siblings("input[type=hidden]")[0].value;
        var selTextePrixQte = $(this).siblings("input[type=hidden]")[1].value;

        $(tempVal).siblings(".nombreChoisis").text(selQte);
        $(tempVal).siblings("input[type=hidden]")[0].value = selValeurPrixQte;
        $(tempVal).siblings("input[type=hidden]")[1].value = selQte;
        $(tempVal).parents("tr").find("td .selTextePrixQte").text(selTextePrixQte);

        var total = 0;
        $(tempVal).parents("table").find(".nombre").each(function() {
            total += parseFloat($(this).find("input[type=hidden]")[0].value);
        });
        $(tempVal).parents("table").find("tr.total span").text(total.toFixed(2) + "$");

        return false;
    });

    // click quand on choisi un nombre
    $("#catalogue_panier .listesNB a").click(function() {
    $(this).parent().parent(".listesNB").remove();
        var selQte = $(this).attr("title");
        $(tempVal).siblings(".nombreChoisis").text(selQte);
        return true;
    });


});








