var zoomRate = 0;


/**
 * 放大网页
 * 
 * @return
 */
function zoomIn() {

    if ($.browser.msie) {
        // IE
        zoomRate += 0.2; 
        document.body.style.zoom = (1 + zoomRate);
        
        /*
        var WshShell = new ActiveXObject("Wscript.Shell");
        try{
            WshShell.SendKeys("^=");
        } catch(e){
        }
        */
    } else {
        // FF
        try {
            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
        } catch (e) {
            alert("被浏览器拒绝！\n请在浏览器地址栏输入'about:config'并回车\n然后将'signed.applets.codebase_principal_support'设置为'true'");
        }

        var ce = document.createEvent("KeyboardEvent");
        ce.initKeyEvent("keypress", true, true, window, true, // holds Ctrl
                                                                // key
                false, // holds Alt key
                false, // holds Shift key
                false, // holds Meta key
                ce.DOM_VK_ADD, "+".charCodeAt(0));
        document.dispatchEvent(ce);
    }
}

/**
 * 缩小网页
 * 
 * @return
 */
function zoomOut() {
    if ($.browser.msie) {
        // IE
        zoomRate -= 0.2; 
        document.body.style.zoom = (1 + zoomRate);
        /*
        var WshShell = new ActiveXObject("Wscript.Shell");
        try{
            WshShell.SendKeys("^-");
        } catch(e){
        }
        */
    } else {
        // FF
        try {
            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
        } catch (e) {
            alert("被浏览器拒绝！\n请在浏览器地址栏输入'about:config'并回车\n然后将'signed.applets.codebase_principal_support'设置为'true'");
        }

        var ce = document.createEvent("KeyboardEvent");
        ce.initKeyEvent("keypress", true, true, window, true, // holds Ctrl
                                                                // key
                false, // holds Alt key
                false, // holds Shift key
                false, // holds Meta key
                ce.DOM_VK_SUBTRACT, "-".charCodeAt(0));
        document.dispatchEvent(ce);
    }
}

/**
 * 回复原来大小
 * 
 * @return
 */
function revert() {

    if ($.browser.msie) {
        // IE
        var WshShell = new ActiveXObject("Wscript.Shell");
        try{
            WshShell.SendKeys("^0");
        } catch(e){
        }
    } else {
        // FF
        try {
            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
        } catch (e) {
            alert("被浏览器拒绝！\n请在浏览器地址栏输入'about:config'并回车\n然后将'signed.applets.codebase_principal_support'设置为'true'");
        }

        var ce = document.createEvent("KeyboardEvent");
        ce.initKeyEvent("keypress", true, true, window, true, // holds Ctrl
                                                                // key
                false, // holds Alt key
                false, // holds Shift key
                false, // holds Meta key
                ce.DOM_VK_0, "0".charCodeAt(0));
        document.dispatchEvent(ce);
    }
}



try {

    $(document).ready(function() { 
        
        function openTool(){
          //透明背景层
            var str = '<div style="background-color:#fff;width:100%;height:25px;z-index:999;"></div>';
            if ($.browser.msie) {
                //ie
                $(str).toggleClass("zoomtool").css("opacity", "0.6").appendTo($(document.body));
            }else{
                $(str).css({"opacity":"0.6","position":"fixed","bottom":"0px"}).appendTo($(document.body));
            }
            //按钮层
            str = '<div style="width:100%;height:25px;z-index:9999;text-align:center;">';
            str += '<input type="button" class="button_grey" value="放大" onclick="zoomIn()" style="margin-right:5px"/>';
            str += '<input type="button" class="button_grey" value="缩小" onclick="zoomOut()" style="margin-right:5px"/>';
            str += '<input type="button" class="button_grey" value="还原" onclick="revert()" style="margin-right:5px"/>';
            str += '</div>';
            if ($.browser.msie) {
                //ie
                $(str).toggleClass("zoomtool").css("opacity", "0.9").appendTo($(document.body));
            }else{
                $(str).css({"opacity":"0.9","position":"fixed","bottom":"0px"}).appendTo($(document.body));
            }            
        }
        
        var flag = getcookie("cookieZoom");
        
        if('1' == flag && '1' != $(document).data('openTool')){
            openTool();
            $(document).data('openTool', '1');  
        }
    });
    
} catch (e) {
}
