﻿function Swf(url, w, h, o) {
    var swf = [];
    var parm = [];
    var attr = [];
    o = jQuery.extend({ allowScriptAccess: "sameDomain", quality: "high", menu: false }, o);
    swf.push('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="' + w + '" height="' + h + '">');
    swf.push('<param name="movie" value="' + url + '">');
    $.each(o, function (i, e) {
        parm.push("<param name=\"" + i + "\" value=\"" + e + "\">");
        attr.push(i + "=\"" + e + "\"");
    });
    swf.push(parm.join(""));
    swf.push("<embed ");
    swf.push(attr.join(" "));
    swf.push(' src="' + url + '" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="' + w + '" height="' + h + '"></embed>');
    swf.push('</object>');
    document.write(swf.join(""));
}

function FocusFlash(s, w, h) {
    Swf("/Images/FocusSkinA.swf?xml=" + s, w, h, { wmode: "transparent"});
}

$(function () {
    var l = 3;
    $("#TopMenu > ul > li").each(function (i, e) {
        var ul = $("> ul", $(e));
        if (ul.width() + l > 830) {
            ul.css("left", l - (ul.width() + l - 830));
        }
        else {
            ul.css("left", l);
        }
        l += $(e).width();
    });
    $("#TopMenu > ul > li .current").parent().find("> ul").show();
    $("#TopMenu > ul > li:has(ul)").hover(function () {
        if ($(".current", this).length > 0) {
            return;
        }
        $(this).addClass("item");
        $("#TopMenu li .current").removeClass("current").addClass("DISCurrent").parent().find("> ul").hide();
        $("> ul", this).show();
    }, function () {
        if ($(".current", this).length > 0) {
            return;
        }
        $("> ul", this).hide();
        $("#TopMenu li .DISCurrent").removeClass("DISCurrent").addClass("current").parent().find("> ul").show();
        $(this).removeClass("item");
    });
});

//IE 6
if (!$.support.opacity && !window.XMLHttpRequest) {
    $(function () {
        //$("#TopMenu > ul > li:has(ul)").each(function (i, e) {
           // var ul = $("> ul", $(e));
       // });
    });
}

$(function () {
    $("#iLeft .tabBox .title a").mouseover(function () {
        var t = $(this);
        if (t.hasClass("current")) {
            return;
        }
        t.parent().find(".current").removeClass("current");
        t.addClass("current");
        var rel = t.attr("rel");
        var p = t.parent().parent();
        p.find(".con:visible").hide();
        $("#con_" + rel).show();
        delete t;
        delete p;
        t = null;
        p = null;
    });
});

$(function () {
    $("#SetHomePage").click(setHomepage);
    $("#AddFavorite").click(addFavorites);
});

//SlidePhotoBox
$(function () {
    var id = "#SlidePhotoBox";
    var count = $(id + " li").length;
    if (count == 0) {
        return;
    }
    var MaxIndex = count / 2;
    if (count % 2 > 0) {
        MaxIndex++;
    }
    var height = 135;
    var MaxScrollTop = MaxIndex * height / 2;
    var Timer;
    var Play = function () {
        Timer = setInterval(function () {
            if ($(id).scrollTop() >= MaxScrollTop) {
                $(id).scrollTop(0);
            }
            else {
                $(id).animate({ scrollTop: "+=" + height }, "slow");
            }
        }, 4000);
    };
    var Pause = function () {
        if (Timer) {
            clearInterval(Timer);
        }
    };
    Play();
    $(id).hover(Pause,Play);
});

$(function () {
    if ($("#keyWord").length == 0) {
        return;
    }
    $("#btnSearch").click(function () {
        val = $("#keyWord").val();
        if (val.length == 0) {
            alert("请输入搜索关键词！");
            $("#keyWord").focus();
            return;
        }
        var isContent = $("#Radio2").attr("checked");
        location.href = "/Zh/Search.aspx?Key=" + escape(val) + "&IsContent=" + isContent;
    });
});

function addFavorites() {
    if (document.all) {
        window.external.addFavorite(document.URL + '', document.title + '');
    }
    else if (window.sidebar) {
        window.sidebar.addPanel('' + document.title, document.URL + '', '');
    }
    return false;
}
function setHomepage() {
    var url = document.URL.substring(0, document.URL.indexOf("/", 8));
    if (document.all) {
        document.body.style.behavior = 'url(#default#homepage)';
        document.body.setHomePage(url);
    }
    else if (window.sidebar) {
        if (window.netscape) {
            try {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            }
            catch (e) {
                alert("该操作被浏览器拒绝，假如想启用该功能，请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true");
            }
        }
        var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
        prefs.setCharPref("browser.startup.homepage", url);
    }
    return false;
}
