$(document).ready(function (){
    $("#IsContent img").each(function (){
        changeImgSize(this);
    });
    SetMenu();
}); 
//-----------------------------------------------------------------------
//前台缩略图按比例缩放函数
var flag=false;
function setPicRange(ImgD,iwidth,iheight)
{
    //参数(图片,允许的宽度,允许的高度)
    var image=new Image();
    image.src=ImgD.src;
    if(image.width>0 && image.height>0)
    {
        flag=true;
        if(image.width/image.height>= iwidth/iheight)
        {
            if(image.width>iwidth)
            {  
                ImgD.width=iwidth;
                ImgD.height=(image.height*iwidth)/image.width;
            }
            else
            {
                ImgD.width=image.width;  
                ImgD.height=image.height;
            }
        }
        else
        {
            if(image.height>iheight){  
                ImgD.height=iheight;
                ImgD.width=(image.width*iheight)/image.height;        
            }
            else
            {
                ImgD.width=image.width;  
                ImgD.height=image.height;
            }
        }
    }
}
//正文图片载入大小限制
function changeImgSize(obj)
{
	$(obj).css("cursor","pointer");

	$(obj).load(function(){setPicRange(obj,800,800);});//解决图片没办法自动缩小的问题
	setPicRange(obj,800,800);//解决图片没办法自动缩小的问题，从缓存中读出来的话就要马上设置
	
	if (!$(obj).parent().is("a"))
	{
	    $(obj).wrap("<a href='"+obj.src+"' target='_blank' title='按此在新窗口浏览图片'></a>"); 
	    $(obj).attr("border","0");
	}
}
//-----------------------------------------------------------------------
//免激活方式显示FLASH
function insertFlash(url, w, h) { 
var str = ''; 
str += '<object width="'+ w +'" height="'+ h +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0">'; 
str += '<param name="movie" value="'+ url +'">'; 
str += '<param name="wmode" value="transparent">'; 
str += '<param name="quality" value="autohigh">'; 
str += '<embed width="'+ w +'" height="'+ h +'" src="'+ url +'" quality="autohigh" wmode="transparent" type="application/x-shockwave-flash" plugspace="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></embed>'; 
str += '</object>'; 
document.write(str); 
}
//-----------------------------------------------------------------------
function CheckInput(ID,Str,DefauleValue)
{
    if ($.trim($('#'+ID).attr("value"))=="")
    {
        alert(Str);
        $('#'+ID).focus();
        return false;
    }
    if (DefauleValue)
    {
        if ($.trim($('#'+ID).attr("value"))==DefauleValue)
        {
            alert(Str);
            $('#'+ID).focus();
            return false;
        }
    }
    return true;
}
//-----------------------------------------------------------------------
function SetMenu()
{
    $("#TheNav li ul").hide();

    $("#TheNav li").each(function(i){
        $(this).bind("mouseenter",function(){$(this).find("ul").show();})
        $(this).bind("mouseleave",function(){$(this).find("ul").hide();})
    });
}
function ShowSearch()
{
    if (CheckInput("Key","请输入搜索关键字！"))
    {
        var Url="/";
        this.location=Url+"Key-"+$("#Key").val()+".html";
    }
}
//-----------------------------------------------------------------------
function collect()
{
    var ctrl = (navigator.userAgent.toLowerCase()).indexOf('mac') != -1 ? 'Command/Cmd': 'CTRL';
    try{
        if (document.all) { //IE类浏览器
            //try {
                //window.external.toString(); //360浏览器不支持window.external，无法收藏
                //window.alert("国内开发的360浏览器等不支持主动加入收藏。\n您可以尝试通过浏览器菜单栏或快捷键 ctrl+D 试试。");
            //}
            //catch (e){
                try{
                    window.external.addFavorite(window.location.href, document.title);
                }
                catch (e){
                    window.external.addToFavoritesBar(window.location.href, document.title);  //IE8
                }
            //}
        }
        else if (window.sidebar) { //firfox等浏览器
            window.sidebar.addPanel(document.title, window.location.href, "");
        }
        else {
            alert('您可以尝试通过快捷键' + ctrl + ' + D 加入到收藏夹~');
        }
    }
    catch (e){
        window.alert("因为IE浏览器存在bug，添加收藏失败！\n解决办法：\n1.您可以尝试通过快捷键" + ctrl + " + D 加入到收藏夹~\n2.在注册表中查找\n HKEY_CLASSES_ROOT\\TypeLib\\{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}\\1.1\\0\\win32 \n将 C:\\WINDOWS\\system32\\shdocvw.dll 改为 C:\\WINDOWS\\system32\\ieframe.dll ");
    }
}
