﻿var maskDiv = $('<div style="position:absolute;z-index:-1;left:0px;top:0px; background:#666666;"></div>');
//if($.browser.msie)
//{
//    if($.browser.version == "6.0")
//    {
//    }
//}
$.extend
({
Mask : function()
{
    if(maskDiv.css("z-index") == "98")
    {
        return;
    }
    maskDiv.css("opacity","0");
    maskDiv.appendTo("body");
    maskDiv.css("z-index","98");
    maskDiv.width("100%");
    maskDiv.height($(document).height());
    maskDiv.animate({opacity:"0.5"},500);
    $("select").css("visibility","hidden");
},
unMask : function()
{
    maskDiv.animate({opacity:"0"},500,function(){maskDiv.css("z-index","-1");maskDiv.height("0");});
    
    $("select").css("visibility","");
}
});

$.fn.Checked = function(obj)
{
    $(this).find("input[type=checkbox]").attr("checked",$(obj).attr("checked"));
};
$.extend(
{
    //输入框提示
    Cue : function(obj)
    {
        if($(obj).data("oldValue"))
        {
            return;
        }
        $(obj).data("oldValue",$(obj).val());
        $(obj).val("");
        $(obj).focus(function()
        {
            if($(this).val()==$(this).data("oldValue"))
            {
                $(this).val("");
            }
        });
        $(obj).blur(function()
        {
            if($(this).val()=="")
            {
                $(this).val($(this).data("oldValue"));
            }
        });
    },
    //预览上传的图片 fc:上传文件控件 width,height:预览图片的尺寸
    PreviewPic : function(fc,width,height)
    {
        var img = $("<img />").width(width).height(height);
        if($(fc).next().data("uc")==$(fc).attr("id"))
        {
            $(fc).next().remove();
        }       
        if(fc.files)
        {
            img.attr('src',fc.files[0].getAsDataURL());
            $(fc).after(img); 
        }
        else
        {            
            img = $("<div/>").width(width).height(height);
            $(fc).after(img); 
            img.css("filter","progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)");
            if(img[0].filters)
            {
                img[0].filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = $(fc).val();
            }
            else
            {
                img.remove();
            }
        }
        img.data("uc",$(fc).attr("id"));
    },
    //动画显示提示信息,obj:触发提示的控件, showDiv:提示信息div元素,不需要包含位置信息,display:none; left top:相对于obj控件左上角的位置.
    //纯透明度变化动画
    Define : function(obj,showDivID,rleft,rtop)
    {
        var showDiv = $("#"+showDivID);
        var div = showDiv.clone();
        div.css("position","absolute");
        div.css("z-index",99);
        div.css("left",$(obj).offset().left+rleft);
        div.css("top",$(obj).offset().top+rtop);
        div.appendTo("body");
        div.fadeIn(500);
        $(obj).one("blur",function(){div.fadeOut(500,function(){div.remove();});});
        return div;
    },
    //大小,和透明度变化动画
    SizeDefine : function(obj,showDivID,rleft,rtop)
    {
        var showDiv = $("#"+showDivID);
        var div = showDiv.clone();
        div.css("position","absolute");
        div.css("z-index",99);
        div.width(0);
        div.height(0);
        div.css("left",$(obj).offset().left+rleft+showDiv.width()/2);
        div.css("top",$(obj).offset().top+rtop+showDiv.height()/2);
        div.css("display","");
        div.animate({opacity:0},function()
        {
            div.appendTo("body");
            div.animate({width:showDiv.width(),height:showDiv.height(),opacity:1,left:$(obj).offset().left+rleft,top:$(obj).offset().top+rtop},500);
        });
        $(obj).one("blur",function(){div.fadeOut(500,function(){div.remove();});});
        return div;
    },
    //使元素闪烁, obj:闪烁的元素, n:与闪烁次数成正比 例:6;
    flicker : function(obj,n)
    {
        if(n>=0)
        {
            if(n%2 > 0)
            {
                $(obj).fadeOut(100,function(){$.flicker(obj,n-1);});
            }
            else
            {
                $(obj).fadeIn(100,function(){$.flicker(obj,n-1);});
            }
        }
    },
    //横向滑入滑出效果, obj:动画元素或元素ID
    lateralToggle : function(obj,speed)
    {
        var Item;
        if(!document.getElementById(obj))
        {
           Item = $(obj);
        }
        else
        {
            Item = $(document.getElementById(obj));
        }
        if(!Item.data("HasWrap"))
        {
            Item.data("ov",Item.css("overflow"));
            Item.height(Item.height());
            Item.width(Item.width());
            Item.css("overflow","hidden");
            Item.wrapInner("<div style='overflow:hidden;margin:0;padding:0;border:0;'></div>");
            Item.children("div").width(Item.children("div").width());
            Item.children("div").height(Item.children("div").height());
            Item.data("HasWrap",true);
            Item.data("width",Item.width());
        }
        if(Item.width()<1)
        {
            Item.animate({width:Item.data("width")},speed,function()
            {
                Item.html(Item.children("div").html());
                Item.data("HasWrap",false);
                Item.css("overflow",Item.data("ov"));
            });
        }
        else
        {
            Item.animate({width:0},speed);
        }
    }
});
