﻿var currentMenuItem = null; //当前菜单编号

$(document).ready(function() {
    $(window).resize(MakeContentMiddle).load(MakeContentMiddle);
    $(".menuItem").hover(
    function() {
        var s = $(this).attr("src").replace("Off", "On");
        $(this).attr("src", s);
    },
    function() {
        var s = $(this).attr("src").replace("On", "Off");
        $(this).attr("src", s);
        GoMenu(currentMenuItem);
    });
    $("a").focus(function() { this.blur(); });

    //提示框
    $("body").append($("<div id=\"Global_div_ShowWindow\"></div>"));

    document.oncontextmenu = function(e) { return false; } //禁止右键

    /****txt_body双击滚动，单击停止***********************************************************/
    craftphil_obj = $(".txt_body")[0];
    //alert(craftphil_obj.scrollTop);
    setTimeout("scb()", 2000);
    document.onmousedown = function() { try { clearInterval(timer); } catch (e) { } }
    document.ondblclick = function() { scb(); }
});
/***************************************************************/
function scb() {
    timer = setInterval('scroll()', 200);
}
var craftphil_obj = null;//滚动的对象
var craftphil_scrollVar = 0;//滚动步长
function scroll() {
    if (craftphil_obj != null) {
        craftphil_scrollVar++;
        craftphil_obj.scrollTop = craftphil_scrollVar;
    }
}


function MakeContentMiddle() {
    //$("body").css("margin-top", 0 + "px");//Reset
    var Sheight = $(document).height() - document.body.offsetHeight;
    //alert($(document).height() + "__" + document.body.offsetHeight);
    if (Sheight > 0) {
        $("body").css("margin-top", Sheight / 2 + "px");
    }
}
function GoMenu(i) { 
    $(".menuItem").each(function(x){
        var s = $(this).attr("src").replace("On", "Off");
        $(this).attr("src", s);
    });

    var obj = $(".menuItem").eq(i);
    var t = $(obj).attr("src").replace("Off", "On");
    $(obj).attr("src", t);
    currentMenuItem = i; //赋值当前菜单
}
//--------------------------------------
//  作用:将图片载入div中，并渐变显示出来
//  src:        图片路径
//  divObj:     div 对象
//  time:       毫秒数
//--------------------------------------
function loadImageFadeIn(src, divObj,time) {
    var imageLoader = new Image();
    $(imageLoader).load(function() {
        $(divObj).css("display", "none");
        $(divObj).html("<img src=\"" + src + "\" alt=\"\" />");
        $(divObj).fadeIn(time);
    });
    imageLoader.src = src; //注意顺序 ，在指定load事件处理Function之后赋值src。异步的。 http://www.cnitblog.com/CoffeeCat/archive/2008/02/01/39533.html

}

/**********************************show提示框***************************************
|   Created by Kai.Ma 马波 Email:kai.ma@163.com                                    | 
|   type:string,提示框类型{"info","alert","error","success","loading","nopic"}     | 
|   title:string,框左上标题                                                        | 
|   message:string，内容消息,支持html                                              | 
|   height:int，高度                                                               | 
|   width:int，宽度                                                                | 
|   modal:bool，是否必须手动关闭提示框才能进行页面点击,true=无关闭按钮,false=有关闭按钮
|   auto:bool                                                                      |
|   goUrl:string                                                                   |
/**********************************************************************************/
loadImage("/Images/info_big.gif");
loadImage("/Images/alert_big.gif");
loadImage("/Images/error_big.gif");
loadImage("/Images/success_big.gif");
loadImage("/Images/loading_big.gif");
/**********************************************************************************/
function ShowWindow(type, title, message, height, width, modal, auto, goUrl) {
    //初始化，关闭曾打开过的Window
    HideWindow();
    $("#Global_div_ShowWindow").empty();
    //alert($("#Global_div_ShowWindow").html());
    var html = "";
    var ul = "";
    //根据type放不同的图片
    html += "<table width=\"100%\"><tr>";
    html += "<td width=\"36px\" valign=\"middle\">";
    switch (type) {
        case "info": html += "<img src=\"/Images/info_big.gif\" />"; break;
        case "alert": html += "<img src=\"/Images/alert_big.gif\" />"; break;
        case "error": html += "<img src=\"/Images/error_big.gif\" />"; break;
        case "success": html += "<img src=\"/Images/success_big.gif\" />"; break;
        case "loading": html += "<img src=\"/Images/loading_big.gif\" />"; break;
        case "nopic": html += ""; break;
    }
    html += "</td>";
    html += "<td valign=\"middle\">" + message + "</td>";
    html += "</tr></table>";

    $("#Global_div_ShowWindow").html(html);
    url = "#TB_inline?height=" + height + "&width=" + width + "&inlineId=Global_div_ShowWindow&modal=" + modal;
    tb_show(title, url, false);
    $("#Global_div_ShowWindow").empty();

    //huangyanchao
    //2008-6-25 16:04
    //增加自动关闭功能
    if (auto != undefined && auto == true) {
        window.setTimeout('HideWindow()', 2000);
    }

    //huangyanchao
    //2008-7-1 16:04
    //增加自动关闭功能
    if (goUrl != undefined && goUrl != "") {
        setTimeout('window.location.assign("' + goUrl + '")', 2000);
    }

}

/**********************************hide提示框.扩展自thickbox*****************/
function HideWindow() {
    $("#TB_imageOff").unbind("click");
    $("#TB_closeWindowButton").unbind("click");
    //$("#TB_window").fadeOut("fast",function(){$('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();});
    $("#TB_window").hide();
    $('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();
    $("#TB_load").remove();
    if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
        $("body", "html").css({ height: "auto", width: "auto" });
        $("html").css("overflow", "");
    }
    document.onkeydown = "";
    document.onkeyup = "";
    return false;
}
function loadImage(src) {
    var imageLoader = new Image();    
    imageLoader.src = src;
}