﻿// 打开层窗口
var dialogFirst = false;
var BgUrls = "../js/s_bg.gif";
    function OpenLayer(title,content,width,height,cssName){
        if(dialogFirst==false){
        if($("#Layer").length>0){
            $("#Layer").remove(); 
        }
        var temp_Layer=new String;
        temp_Layer="<div id=\"Layer\">"
        temp_Layer+="<div id=\"LayerBoxBg\" style=\"height:"+$(document).height()+"px;\"></div>";
        temp_Layer+="<div id=\"LayerBox\" class=\"LayerBox\">";
        temp_Layer+="<div class=\"title\"><h4></h4><span>关闭</span></div>";
        temp_Layer+="<div class=\"content\"></div>";
        temp_Layer+="</div>";
        temp_Layer+="</div>";
        $("body").append(temp_Layer);
        dialogFirst=true;
        }

        $("#LayerBox .title span").click(function(){
        $("#LayerBoxBg").animate({opacity:"0"},"normal",function(){});
        $("#LayerBoxBg").css({display:"none"});
        $("#LayerBox").animate({top:($(document).scrollTop()-(height=="auto"?300:parseInt(height)+500))+"px"},"normal",function(){}); 
              $("#LayerBox .content").html("");
        dialogFirst=false;
        });

        $("#LayerBox .title h4").html(title);
        contentType=content.substring(0,content.indexOf(":"));
        content=content.substring(content.indexOf(":")+1,content.length);
        switch(contentType){
        case "url":
        var content_array=content.split("?");
        $("#LayerBox .content").ajaxStart(function(){
            $(this).html("loading...");
        });
        $.ajax({
            type:content_array[0],
            url:content_array[1],
            data:content_array[2],
            error:function(){
            $("#LayerBox .content").html("error...");
            },
            success:function(html){
              $("#LayerBox .content").html(html);
            }
        });
        break;
        case "text":
        $("#LayerBox .content").html(content);
        break;
        case "id":
        $("#LayerBox .content").html($("#"+content+"").html());
        $("#"+content+"").remove(); 
        break;
        case "iframe":
        $("#LayerBox .content").html("<iframe id=\"MyPage\" src=\""+content+"\" width=\"100%\" height=\""+(parseInt(height)-30)+"px"+"\" allowTransparency=\"true\" scrolling=\"no\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\"></iframe>");
        }

        $("#LayerBoxBg").show();
        //$("#LayerBoxBg").animate({opacity:"0.3"},"normal");
        $("#LayerBox").attr("class","LayerBox "+cssName);
        $("#LayerBox").css({display:"block",left:(($(document).width())/2-(parseInt(width)/2))+"px",top:($(document).scrollTop()-(height=="auto"?300:parseInt(height)))+"px",width:width,height:height});
        //$("#LayerBox").animate({top:($(document).scrollTop()+50)+"px"},"normal"); 
        $("#LayerBox").animate({top:parseInt((pageHeight()-height)/2)+"px"},"normal"); 
        //alert(parseInt((pageHeight()-height)/2)+"px");
    }
    /*改变父窗口宽度和高度*/
    function ChangeFwh(NewTitle,width,height){//*
             var $MyLayer = $(window.parent.document).find("#LayerBox");
             var $MyTitle = $(window.parent.document).find("#LayerBox .title h4");
             $MyTitle.html(NewTitle);
             var $MyContent = $(window.parent.document).find("#content");
             var $MyPage = $(window.parent.document).find("#MyPage");

             var Lefts=parseInt((pageWidth()-width)/2)+"px";
             var Tops=parseInt((pageHeight()-height)/2)+"px";
             
             $MyLayer.animate({height:height,width:width,top:Tops,left:Lefts},"normal");
             $MyContent.animate({height:height-30,width:width},"normal");
             $MyPage.animate({height:height-30,width:width},"normal");
             //*/
    }
    //*/返回父窗口页面高度 
    function pageHeight(){ 
        if($.browser.msie){ 
            return document.compatMode == "CSS1Compat"? window.parent.document.documentElement.clientHeight : window.parent.document.body.clientHeight; 
        }else{ 
            return window.parent.innerHeight; 
        } 
    }; 
    //返回父窗口页面宽度 
    function pageWidth(){ 
        if($.browser.msie){ 
            return document.compatMode == "CSS1Compat"? window.parent.document.documentElement.clientWidth :  window.parent.document.body.clientWidth; 
        }else{ 
            return window.parent.innerWidth; 
        } 
    };
//*/

//定义类滚动条
function AddClassGd(obj){
    $(document).ready(function(){
	    $("."+obj).jscroll({ W:"15px"
					    ,BgUrl:"url(" + BgUrls + ")"
					    ,Bg:"right 0 repeat-y"
					    ,Bar:{Bd:{Out:"#BBBBBB",Hover:"#FFFFFF"}
						     ,Bg:{Out:"-45px 0 repeat-y",Hover:"-58px 0 repeat-y",Focus:"-71px 0 repeat-y"}}
					    ,Btn:{btn:true
						     ,uBg:{Out:"0 0",Hover:"-15px 0",Focus:"-30px 0"}
						     ,dBg:{Out:"0 -15px",Hover:"-15px -15px",Focus:"-30px -15px"}}
					    ,Fn:function(){}
					    });
    });
}
//定义ID滚动条
function AddIdGd(obj){
    $(document).ready(function(){
	    $("#"+obj).jscroll({ W:"15px"
					    ,BgUrl:"url(" + BgUrls + ")"
					    ,Bg:"right 0 repeat-y"
					    ,Bar:{Bd:{Out:"#BBBBBB",Hover:"#FFFFFF"}
						     ,Bg:{Out:"-45px 0 repeat-y",Hover:"-58px 0 repeat-y",Focus:"-71px 0 repeat-y"}}
					    ,Btn:{btn:true
						     ,uBg:{Out:"0 0",Hover:"-15px 0",Focus:"-30px 0"}
						     ,dBg:{Out:"0 -15px",Hover:"-15px -15px",Focus:"-30px -15px"}}
					    ,Fn:function(){}
					    });
    });
}
//视频播放
function VideosPlay(vidtitle,width,height,vidurl,vidcontent){
    height -= 28;
    var vidplayer=new String;
    vidplayer = "<div id=\"videos\" style=\"width: " + width + "px; height: " + height + "px; display: block\">";
    vidplayer += "<div style=\"width: 100%; height: 22px;padding-top: 4px; text-align: right;\">";
    vidplayer += "<span id=\"toplay\" class=\"btn\">视频播放</span>";
    vidplayer += "<span id=\"toinfo\" class=\"btn\">视频信息</span>";
    vidplayer += "</div>";
    vidplayer += "<div id=\"vidplay\">";
    vidplayer += "<embed src=\"" + vidurl + "\" id=\"vidplays\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allownetworking=\"internal\" allowfullscreen=\"true\" wmode=\"opaque\" width=\"" + width + "\" height=\"" + (height -22) + "\"></embed>";
    vidplayer += "</div>";
    vidplayer += "<div id=\"vidinfo\" style=\"display: none; overflow: hidden;width: " + width + "px; height: " + (height -22) + "px;\" class=\"vidinfo\">";
    vidplayer += vidcontent;
    vidplayer += "</div>";
    vidplayer += "<scr"+"ipt type=\"text/javas"+"cript\" src=\"js\/jscroll.js\"><\/scr"+"ipt>";
    vidplayer += "</div>";
        $("body").append(vidplayer);
        OpenLayer(vidtitle,'id:videos',width,height+32,'');
        /*********************/
            $("#LayerBox .content #toinfo").click(function(){
                $("#LayerBox .content #vidplay").css({display:"none"});
                $("#LayerBox .content #vidinfo").css({display:"block"});
                BgUrls = "js/s_bg.gif";
                AddIdGd("vidinfo");
                });
        /*********************/
            $("#LayerBox .content #toplay").click(function(){
                $("#LayerBox .content #vidplay").css({display:"block"});
                $("#LayerBox .content #vidinfo").css({display:"none"});
                });
        
}
function GetGrade(Grade){
    var thisgrade = parseInt($("#TheLo").val());
    //alert(thisgrade);
    return thisgrade;
}
