$(document).ready(function() {
    $(".filterDdl").change(function() {
        window.scrollTo(0, 814);
    });

    if (!isIE) {
        //Remove the attributes valid just for IE
        $(".dataIFrame").removeAttr("allowtransparency");
        $(".dataIFrame").removeAttr("backgroundcolor");
        $(".MACUBSIFrame").removeAttr("allowtransparency");
        $(".MACUBSIFrame").removeAttr("backgroundcolor");

        $("#ContactLnk").click(function() {
            $(".lockerContainer").fadeIn("fast", function() {
                $("#ContactUs").fadeIn();
            });
        });

        $("#ContactCloseLnk").click(function() {
            $("#ContactUs").fadeOut("fast", function() {
                $(".lockerContainer").fadeOut("fast");
            });
        });

        $("#TermsLnk").click(function() {
            $(".lockerContainer").fadeIn("fast", function() {
                $("#TermsConditions").fadeIn();
                popup_opened = false;
            });
        });

        $("#PopupTermsLnk").click(function() {
            parent.$("#TermsConditions").fadeIn();
        });

        $("#TermsCloseLnk").click(function() {
            $("#TermsConditions").fadeOut("fast", function() {
                if (!popup_opened) {
                    $(".lockerContainer").fadeOut("fast");
                }
            });
        });

        $("#MapAreaClose").click(function() {
            parent.$(".dataIFrameContainer").fadeOut("fast", function() {
                parent.$(".lockerContainer").fadeOut("fast", function() {
                    updateIFrameContent("IFrameMMU", "MMUPopup.aspx");
                    popup_opened = false;
                });
            });
        });
    }
    else {
        if (isIE6) {
            // Fix transparent PNGs (IE 6 and below)
            var blank = new Image();
            blank.src = 'themes/common/images/Blank.gif';

            $(document).ready(function() {
                var badBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
                if (badBrowser) {
                    // get all pngs on page, which rel='png'
                    $('img[rel$=png]').each(function() {
                        if (!this.complete) {
                            this.onload = function() { fixPng(this) };
                        } else {
                            fixPng(this);
                        }
                    });
                }
            });

            function fixPng(png) {
                // get src
                var src = png.src;
                // set width and height
                if (!png.style.width) { png.style.width = $(png).width(); }
                if (!png.style.height) { png.style.height = $(png).height(); }
                // replace by blank image
                png.onload = function() { };
                png.src = blank.src;
                // set filter (display original image)
                png.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
            }

            // Fix Locker container height
            $(".lockerContainer").height($(".outerContainer").height());

            $("#ContactLnk").click(function() {
                $("select").css("visibility", "hidden");
                $(".lockerContainer").show();
                $("#ContactUs").css(
                    {
                        "width": "617",
                        "height": "327",
                        "z-index": "200",
                        "visibility": "visible"
                    }
                );
            });

            $("#ContactCloseLnk").click(function() {
                $("#ContactUs").css(
                    {
                        "visibility": "hidden",
                        "z-index": "-1000",
                        "width": "1",
                        "height": "1"
                    }
                );
                $(".lockerContainer").hide();
                $("select").css("visibility", "visible");
            });

            $("#TermsLnk").click(function() {
                $("select").css("visibility", "hidden");
                $(".lockerContainer").show();
                $("#TermsConditions").css(
                    {
                        "width": "800",
                        "height": "529",
                        "z-index": "200",
                        "visibility": "visible"
                    }
                );
                popup_opened = false;
            });

            $("#PopupTermsLnk").click(function() {
                parent.$("#TermsConditions").css(
                    {
                        "width": "800",
                        "height": "529",
                        "z-index": "200",
                        "visibility": "visible"
                    }
                );
            });

            $("#TermsCloseLnk").click(function() {
                $("#TermsConditions").css(
                    {
                        "visibility": "hidden",
                        "z-index": "-1000",
                        "width": "1",
                        "height": "1"
                    }
                );
                if (!popup_opened) {
                    $(".lockerContainer").hide();
                    $("select").css("visibility", "visible");
                }
            });

            $("#MapAreaClose").click(function() {
                parent.$(".dataIFrameContainer").hide();
                parent.$(".lockerContainer").hide();
                parent.$("select").css("visibility", "visible");
                updateIFrameContent("IFrameMMU", "MMUPopup.aspx");
                popup_opened = false;
            });
        }
        else {
            $("#ContactLnk").click(function() {
                $(".lockerContainer").show();
                $("#ContactUs").show();
            });

            $("#ContactCloseLnk").click(function() {
                $("#ContactUs").hide();
                $(".lockerContainer").hide();
            });

            $("#TermsLnk").click(function() {
                $(".lockerContainer").show();
                $("#TermsConditions").show();
                popup_opened = false;
            });

            $("#PopupTermsLnk").click(function() {
                parent.$("#TermsConditions").show();
            });

            $("#TermsCloseLnk").click(function() {
                $("#TermsConditions").hide();
                if (!popup_opened) {
                    $(".lockerContainer").hide();
                }
            });

            $("#MapAreaClose").click(function() {
                parent.$(".dataIFrameContainer").hide();
                parent.$(".lockerContainer").hide();
                updateIFrameContent("IFrameMMU", "MMUPopup.aspx");
                popup_opened = false;
            });
        }
    }
});