﻿function ShowMenu() {
    var currentUrl = location.href;
    currentUrl = currentUrl.replace("http://","");
    var folders = currentUrl.split("/");
    var menuParent = "/" + folders[1];
    var menuChild = "/" + folders[1] + "/" + folders[2];
    
    var menuParentObj = $("[org='" + menuParent + "']");
    var menuChildObj = $("[org='" + menuChild + "']");
    menuParentObj.find("a").eq(0).css("background", "#056490").css("color", "#FFF");
    if (menuChildObj.find("a").html() != null)
    {
        
        menuChildObj.find("a").eq(0).css("text-decoration", "underline").css("color", "#000");
        menuChildObj.parent().show();
    }
    else
    {
        menuParentObj.next().show();
    }
    
    //alert(("[org='/" + folders[1] + "/" + folders[2] + "']").html());
    //$("[org='/" + folders[1] +"/"+ folders[2] + "']").parent.show();
}
$(document).ready(function () {
    ShowMenu();
    $("#relinks").click(function () {

        if ($("#linkmenu").is(":hidden")) {
            $("#linkmenu").slideDown("slow");
        } else {
            $("#linkmenu").slideUp();
        }
    })
    $("#customePageImag").LoadImage(true,500,"正在读取图片...");
})

jQuery.fn.LoadImage = function (scaling, width, loadpic) {
    if (this == null) return;
    if (loadpic == null) loadpic = "../images/loading.gif";
    return this.each(function () {
        var t = $(this);
        var src = $(this).attr("src")
        var img = new Image();
        //alert("Loading...")
        img.src = src;
        //自动缩放图片
        var autoScaling = function () {
            if (scaling) {
                if (img.width > 0 && img.height > 0) {
                    if (img.width >= width) {
                        if (img.width > width) {
                            t.width(width);
                            t.height((img.height * width) / img.width);
                        } else {
                            t.width(img.width);
                            t.height(img.height);
                        }
                    }
                }
            }
        }
        //处理ff下会自动读取缓存图片
        if (img.complete) {
            //alert("getToCache!");
            autoScaling();
            return;
        }
        $(this).attr("src", "");
        var loading = $(loadpic);
        //var loading = $("<img alt=\"加载中...\" title=\"图片加载中...\" src=\"" + loadpic + "\" />"); 
        t.hide();
        t.after(loading);
        $(img).load(function () {
            autoScaling();
            loading.remove();
            t.attr("src", this.src);
            t.show();
            //alert("finally!")
        });
    });
} 
