/**
 * @author jaikuai
 */
var popStatus;
var videoStatus;
$.extend({
    showScreen: function(id){
        $("#" + id).show();
    },
    closeScreen: function(id){
        $("#" + id).hide();
    },
    addCloseButton: function(id, closeAfterShowId){
        var html = "<span id=\"closeButton" + id + "\" style=\"position: absolute;width:19px; height:19px;cursor:pointer;top:7px;rith:3px;";
        html += "overflow: hidden;background-image:url('http://mat01.gcimg.cn/2010/common/img/f_close.gif');z-index:11;\"><\/span>";
        $("#" + id).css({
            "z-index": "10",
			position: "relative"
        });
		$("#" + id).prepend(html);
        if (closeAfterShowId != "") {
            $("#closeButton" + id).live('click', function(){
                $.closeScreen(id, $.showScreen(closeAfterShowId));
            });
        }
        else {
            $("#closeButton" + id).live('click', function(){
                $.closeScreen(id);
            });
        }
    },
    popScreen: function(id, closeAfterShowId){
        var html = "<span id=\"popClose\" style=\"position: absolute;width:19px; height:19px;cursor:pointer;right: 7px;top:7px;background-image:url('http://mat01.gcimg.cn/2010/common/img/f_close.gif');z-index:11;\"><\/span>";
        $("#" + id).css({
            top: "70px",
            left: (window.screen.width - 720) / 2 + "px",
            width: "auto",
            "margin-right": "auto",
            "margin-left": "auto",
            position: "absolute",
            height: "auto",
            "z-index": "10"
        });
        $("#" + id).prepend(html);
        $("#" + id).show();
        if (closeAfterShowId != "") {
            $("#popClose").live('click', function(){
                $.closeScreen(id, $.showScreen(closeAfterShowId));
            });
        }
        else {
            $("#popClose").live('click', function(){
                $.closeScreen(id);
            });
        }
        popStatus = setInterval("$.popScroll('" + id + "')", 100);
    },
    popScroll: function(id){
        if ($("#" + id).css("display") != "none") {
            $("#" + id).css("top", (document.documentElement.scrollTop + 70) + 'px');
        }
    },
    rightVideo: function(id, closeAfterShowId){
        var html = "<div style=\"cursor:pointer;width:100%; height:20px; line-height:20px; background:url(http://at160.com/images/case_title.jpg) repeat-x; font-weight:bold;font-size:12px;\">&nbsp;<span style=\"width:30px;\" id=\"videoClose\">关闭&nbsp;&nbsp;<\/span><\/div>";
        $("#" + id).css({
            border: "1px solid #999999",
            height: "245px",
            bottom: "1px",
            right: "1px",
            margin: "0",
            padding: "1px",
            position: "absolute",
            background: "#FFFFFF",
            "z-index": "18",
            overflow: "hidden"
        });
        $("#" + id).prepend(html);
        $("#" + id).show();
        if (closeAfterShowId != "") {
            $("#videoClose").live('click', function(){
                $.closeScreen(id, $.showScreen(closeAfterShowId));
            });
        }
        else {
            $("#videoClose").live('click', function(){
                $.closeScreen(id);
            });
        }
        videoStatus = setInterval("$.videoScroll('" + id + "')", 100);
    },
    videoScroll: function(id){
        if ($("#" + id).css("display") == "none") {
            clearInterval(videoStatus);
        }
        else {
            $("#" + id).css("top", (document.documentElement.clientHeight + document.documentElement.scrollTop - $("#" + id).height()) + 'px');
        }
    },
    floatScreen: function(id, top, replayId){
        var html = "<div style=\"width:100%; height:20px; line-height:20px;font-size:10px;cursor:pointer;\">";
        html += "<span id=\"replay" + id + "\">重播&nbsp;&nbsp;<\/span>&nbsp;&nbsp;";
        html += "<span id=\"floatClose" + id + "\">关闭&nbsp;&nbsp;<\/span><\/div>";
        $("#" + id).css({
            height: $("#" + id).height() + 20
        });
        $("#" + id).prepend(html);
        if (replayId != "") {
            $("#replay" + id).live('click', function(){
                $.showScreen(replayId);
            });
        }
        $("#floatClose" + id).live('click', function(){
            $.closeScreen(id);
        });
        setInterval("$.floatScroll('" + id + "','" + top + "')", 100);
        $("#" + id).show();
    },
    floatScroll: function(id, top){
        if ($("#" + id).css("display") != "none") {
            $("#" + id).css("top", ((Number(top) + Number(document.documentElement.scrollTop)) + 'px'));
        }
    },
	loadAdjs:function(id,url){
		$("<scri"+"pt>"+"</scr"+"ipt>").attr({
                src:url,
                type:'text/javascript',
                id:'load'
            }).appendTo($(id));
	}
});
