﻿Vagifem.Util.Namespace('Vagifem.App');

Vagifem.App = {
    "Menu": function (url) {
        var currentUrl = window.location.pathname + window.location.search; // window.location.hash
        var divMenu = $("#header > div.menu > div.menu_lins");
        var divSubMenus = $("#header > div.menu > div.sub_menu_lins");
        var topMenuBackgroud = "url(/Images/menu_point.png) no-repeat bottom center";
        divMenu.css("background", "");

        var linkTopMenus = divMenu.find("a");
        for (var i = 0; null != linkTopMenus && i < linkTopMenus.length; i++) {
            var link = linkTopMenus.eq(i);
            link.data("index", i);
            link.bind('mousemove', function () {
                divSubMenus.hide();
                divSubMenus.eq($(this).data("index")).show();
                divMenu.css("background", "");
                if (0 != $(this).data("index")) {
                    divMenu.eq($(this).data("index")).css("background", topMenuBackgroud);
                }
            });
        }
    },
    "FixPng": function () {
        var arVersion = navigator.appVersion.split("MSIE")
        var version = parseFloat(arVersion[1])

        if ((version >= 5.5 && version < 7.0) && (document.body.filters)) {
            for (var i = 0; i < document.images.length; i++) {
                var img = document.images[i];
                var imgName = img.src.toUpperCase();
                if (imgName.indexOf(".PNG") > 0) {
                    var width = img.width;
                    var height = img.height;
                    var sizingMethod = (img.className.toLowerCase().indexOf("scale") >= 0) ? "scale" : "image";
                    img.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + img.src.replace('%23', '%2523').replace("'", "%27") + "', sizingMethod='" + sizingMethod + "')";
                    img.src = "/images/blank.gif";
                    img.width = width;
                    img.height = height;
                }
            }
        }
    },
    "Search": function (tb) {
        var value = $.trim(tb.val());
        if (value.length == 0) {
            tb.focus();
        }
        else {
            window.location.href = "/Search.aspx?search=" + escape(value);
        }
    },
    "EnterSearch": function (tbId, e) {
        e = (e) ? e : window.event;
        var code = (e.keyCode || e.which);
        if (code == 13 || code == 32) {
            Vagifem.App.Search($("#" + tbId));
            return false;
        }

        if (window.event) {
            e.cancelBubble = true;
        } else {
            e.stopPropagation();
        }
        return true;
    }
};
