(function ($) {
    $.buildClass = function () {
        var argc = 0;

        //Methods of the current class
        var methods = arguments[argc] ? arguments[argc++] : {};

        //Definition of the upper class or empty class if no one is provided
        var P = $.isFunction(arguments[argc]) ? arguments[argc] : function () { };

        //Class of the object uber
        var Uber = function (base) {
            if (P.prototype.__U) this.uber = new P.prototype.__U(base);
            this.__o = base;
        }

        //For each function defined in the parent class, we have to dynamically generate one for the uber object through eval
        for (var f in P.prototype) {
            if ($.isFunction(P.prototype[f])) {
                //Use eval to generate all functions « on the fly ». Otherwize you're screwed up.
                Uber.prototype[f] = eval('(function(){return function(){return P.prototype[\''
								+ f.replace(/\\'/g, '\\\'').replace(/\\/g, '\\')
								+ '\'].apply(this.__o, arguments);};})();');
            }
        }

        var Constructor = function () {
            //Set the uber object
            this.uber = new Uber(this);

            //Run the provided contructor if it exists
            if (methods.constructor) methods.constructor.apply(this, arguments);
        }

        //Create a new prototype for our class
        var F = function () { }
        F.prototype = P.prototype;
        Constructor.prototype = new F();

        //Set assign methods to this prototype
        $.extend(Constructor.prototype, methods, { __U: Uber });
        Constructor.prototype.constructor = Constructor;

        return Constructor;
    }
})(jQuery);

$(document).ready(function () {

    if ($.browser.msie && $.browser.version == "6.0" || $.browser.version == "7.0") {
        $("#Logo").hide().show();   
    }
    if ($.browser.msie && $.browser.version == "6.0") {
        var ie6Msg = $("<div></div>").attr("id", "IE6Message");
        ie6Msg.append($("<h1></h1>").text("Oups!"));
        ie6Msg.append($("<h2></h2>").text("Vous utilisez toujours Internet Exporer " + $.browser.version + ": il y a des façons plus agréables de naviguer sur le web ..."));
        ie6Msg.append($("<p></p>").text("Pour vivre une expérience de navigation optimale, nous vous recommandons fortement de télécharger la dernière version d'Internet Explorer ou de télécharger un navigateur plus récent. Vous trouverez ci-dessous des liens vers les navigateurs les plus populaires."));
        var browserList = $("<div></div>")
                                .append($("<a></a>").attr("href", "http://www.google.com/chrome/?hl=fr").attr("class", "browserList").text("Google Chrome")
                                    .prepend($("<img src='/App_Themes/FEQ/Images/chrome.png' alt='Chrome' />")))
                                .append($("<a></a>").attr("href", "http://www.mozilla.com/fr/firefox/").attr("class", "browserList").text("Firefox")
                                    .prepend($("<img src='/App_Themes/FEQ/Images/firefox.png' alt='firefox' />")))
                                .append($("<a></a>").attr("href", "http://www.apple.com/fr/safari/download/").attr("class", "browserList").text("Safari")
                                    .prepend($("<img src='/App_Themes/FEQ/Images/safari.png' alt='Safari' />")))
                                .append($("<a></a>").attr("href", "http://www.opera.com/download/").attr("class", "browserList").text("Opera")
                                    .prepend($("<img src='/App_Themes/FEQ/Images/opera.png' alt='opera' />")))
                                .append($("<a></a>").attr("href", "http://www.microsoft.com/canada/fr/windows/internet-explorer").attr("class", "browserList").text("Internet Explorer")
                                    .prepend($("<img src='/App_Themes/FEQ/Images/ie.png' alt='ie' />")));


        ie6Msg.append(browserList);
        ie6Msg.append($("<a></a>").attr("class", "close").text("Fermer et continuer tout de même").click(function () {
            $("#BgPopUp").remove();
            $("#IE6Message").remove();
        }));

        $("#Degrade").prepend($("<div></div>").attr("id", "BgPopUp"));
        $("#Degrade").prepend(ie6Msg);
    }

    if ($("body").hasClass("ENCA")) {
        $("#MainMenu").addClass("en-ca");
        $("#BigImageProgDiv").addClass("en-ca");
    }

    if ($("#OngletText").length > 0) {
        $("#OngletText")
        .prepend($("<div></div>").attr("class", "onglet-text-deco-left"))
        .prepend($("<div></div>").attr("class", "onglet-text-deco-right"));
    }

    var bg = new Image();
    if ($("#CarouselWrap").length > 0 || $("#ScheduleTable").length > 0) {
        bg.src = "/App_Themes/FEQ/Images/bg_home.jpg";
    } else {
        bg.src = "/App_Themes/FEQ/Images/bg_header_decorator.jpg";
    }

    bg.onload = function () {
        $("#HeaderDecorator").css({
            backgroundImage: "url('" + bg.src + "')",
            backgroundPosition: "center top",
            backgroundRepeat: "no-repeat",
            height: "788px"
        });
    };
});


