$(function() {

    $(".barre ul li.selected").each(function() {
        $(this).parent("ul").addClass('open');
        $(this).parent("ul").prev("h2").addClass('open');
    });

    $(".barre h2 a").click(function(e) {
        $this = $(this).parent();
        if (!$this.hasClass("open")) {
            $this.addClass('open');
            $this.next('ul').slideDown('fast');
        } else {
            $this.removeClass('open');
            $this.next('ul').slideUp('fast');
        }
        e.preventDefault();
    });


    $(".barre ul .selected").click(function() {
        $("#main").css("visibility", "visible");
        return false;
    });
    $("#close").click(function() {
        $("#main").css("visibility", "hidden");
        return false;
    });

    $(".colonnehoraire table td:first-child").addClass("first");



    var tempVal;

    // gestion du click sur les fleches pour le nombre de billets
    $("a.choose").click(function() {
        tempVal = this;
        var pos = $(this).parent().position();

        $(".panier").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
    $(".listesNB a").click(function() {
        $(this).parent().parent(".listesNB").remove();

        nombreDeBillets = $(this).attr("title");
        $(tempVal).siblings(".nombreChoisis").text(nombreDeBillets);
        return false;
    });



    $(".blocInfos input[title]").each(function() {
        if ($(this).val() == $(this).attr("title")) {
            $(this).addClass("vide");
        }
    });


    $(".blocInfos input[title]").focus(function() {
        if ($(this).val() == $(this).attr("title")) {
            $(this).val("");
            $(this).removeClass("vide");
        }
    });
    $(".blocInfos input[title]").blur(function() {
        if ($.trim($(this).val()) == "") {
            $(this).addClass("vide");
            $(this).val($(this).attr("title"))
        }
    });

    $("#faq a").toggle(
		function() { $(this).addClass("open"); $(this).siblings("div").show(); curvyCorners.redraw(); curvyCorners.redraw(); return false; },
		function() { $(this).removeClass("open"); $(this).siblings("div").hide(); curvyCorners.redraw(); curvyCorners.redraw(); return false; }
	);
});

function FixedCurvyRedraw() {

    var radioSel = "";
    $("input[type='radio']:checked").each(function() {
        radioSel += this.name + "*" + this.value + "&";
    });
    var chkSel = "";
    $("input[type='checkbox']:checked").each(function() {
        chkSel += this.id + "&";
    });

    try {
        curvyCorners.redraw();
        curvyCorners.redraw();
    }
    catch (err)
    { }

    $.each(radioSel.split("&"), function() {
        var a = this.split("*");
        if (a.length == 2) {
            $("input[type='radio'][name=" + a[0] + "][value=" + a[1] + "]").each(function() {
                this.checked = true;
            });
        }
    });
    $.each(chkSel.split("&"), function() {
        if (this != "") {
            $("input[type='checkbox'][id=" + this + "]").each(function() {
                this.checked = true;
            });
        }
    });
}
