(function($) {
    function ChangeLanguage(obj) {
        $("#DivContentInside").block();
        $.ajax({
            url: '/modules/Language/client/ChangeLanguageAndCulture.aspx?l=' + $(obj).attr("id"),
            cache: false,
            complete: function() {
                // unblock when remote call returns 
                //obj.css("background-color", "#fff");
                $("#DivContentInside").unblock();
                $("#DivOtherLangue").css("display", "none");
                document.location.href = document.location.href;
            }
        });
    }

    function CheckDesignResize() {
        var height = 0;
        var heightDivContent;
        heightDivContent = $("#DivContent").css("height").replace("px", "");

        if (heightDivContent == 'auto') { heightDivContent = $("#DivContent").css("min-height").replace("px", ""); }

        if ($(window).height() > heightDivContent) {

            height = $(window).height();
            height -= $("#DivHeader").css("height").replace("px", "");
            height -= $("#DivFooter").css("height").replace("px", "");
            height -= $("#DivFooter").css("border-top-width").replace("px", ""); ; //la bordure

            var heightContent = $("#DivContent").css("min-height").replace("px", "");
            if (height < 380) { height = 380; }
            var paddingtop = height;
            paddingtop -= $("#DivContentInside").css("height").replace("px", "");
            paddingtop = paddingtop / 2;

            $("#DivContentInsideRPT").css("padding-top", paddingtop + "px")

            if ($.browser.name.indexOf('msie') > -1 && $.browser.versionNumber < 7) {
                //$("#DivContent .ContentSection").css("height", parseInt(height) + "px");
                $("#DivContent").css("height", parseInt(height) + "px");
            }
            else {
                $("#DivContent").css("min-height", parseInt(height) + "px");
            }

            $("#DivContentInsideRPT").css("height", parseInt(height - paddingtop) + "px");

        }
        else { $("#DivContentInsideRPT").css("padding-top", "2px") }
    }

    $(document).ready(function() {
        CheckDesignResize();

        $.blockUI.defaults.fadeOut = 0;
        $.blockUI.defaults.centerX = true; // <-- only effects element blocking (page block controlled via css above) 
        $.blockUI.defaults.centerY = false;
        $.blockUI.defaults.overlayCSS = {
            backgroundColor: '#000',
            opacity: '0.1'
        };
        $.blockUI.defaults.message = '<h3>Patientez pendant la mise &agrave; jour...</h3>';
        $.blockUI.defaults.css = {
            padding: '0 0 0 0 ',
            margin: 0,
            width: '90%',
            top: '0',
            left: '0',
            textAlign: 'center',
            color: '#000',
            border: '3px solid #aaa',
            backgroundColor: '#fff',
            cursor: 'wait',
            opacity: '0.6'
        };

        $(window).bind("resize", function() { CheckDesignResize() });
        $("img").pngfix();

        $(".DivSelectMenu").corner("top 6px");
        $(".DivChoixLangue span.Language").prepend("<span class='SelectLanguage'>&nbsp;</span>");
        $(".DivOtherChoixLangue span.Language").prepend("<span class='SelectLanguage'>&nbsp;</span>");

        $(".DivChoixLangue").click(function() {
            setTimeout('$(\'#DivOtherLangue\').fadeOut(\'slow\')', 5000)
            if ($("#DivOtherLangue").css("display") == "none") { $("#DivOtherLangue").fadeIn("slow"); }
            else { $("#DivOtherLangue").fadeOut("slow"); }
        })


        $(".OtherLanguage").click(function() {
            ChangeLanguage(this);
        })

        $("input[type=text], input[type=password], textarea").focus(function() {
            $(this).addClass("InputFocus");
        }).blur(function() {
            $(this).removeClass("InputFocus");
        });

        $(".ButtonShort").mouseover(function() {
            $(this).addClass("ButtonShortOver");
        }).mouseout(function() { $(this).removeClass("ButtonShortOver"); });

        $(".ButtonLarge").mouseover(function() {
            $(this).addClass("ButtonLargeOver");
        }).mouseout(function() { $(this).removeClass("ButtonLargeOver"); });


        $(".ButtonOrange").mouseover(function() {
            $(this).addClass("ButtonOrangeOver");
        }).mouseout(function() { $(this).removeClass("ButtonOrangeOver"); });

    });
})(jQuery);