﻿
function hideLeftFloat(anvIframeStr){
   $("#Hide").html("<div id='hideLeftFloat'></div><div id='hideBackImg'></div>");
   $("#hideLeftFloat").html(anvIframeStr);
   $("#hideBackImg").html("<div id='switch'></div><div id='HideText'></div><div id='zoom'></div>");
}

function hideRightFLoat(anvIframeStr){
   $("#Hide").html("<div id='hideBackImg'></div><div id='hideRightFloat'></div>");
   $("#hideRightFloat").html(anvIframeStr);
   $("#hideBackImg").html("<div id='switch'></div><div id='HideText'></div><div id='zoom'></div>");
}
function createFloatDiv(anvUrl,anvWidth,anvHeight,location){
   var obj = "<div id='anvFLoatWindow'><div id='Hide'>";
	obj = obj + "</div></div>";
   $("body").append(obj);/*追加DIV*/
   var anvIframeStr = "<IFRAME id='anvIframe' src='"+anvUrl+"' frameBorder=0 width="+anvWidth+" scrolling=no height="+anvHeight+"></IFRAME>";
   $("#anvFLoatWindow").floatdiv(location,anvIframeStr);

}

jQuery.fn.floatdiv=function(location,anvIframeStr){
	//ie6要隐藏纵向滚动条
	var isIE6=false;
	if($.browser.msie && $.browser.version=="6.0"){
		$("html").css("overflow-x","auto").css("overflow-y","hidden");
		isIE6=true;
	};
	$("body").css({margin:"0px",padding:"0 10px 0 10px",
		border:"0px",
		height:"100%",
		overflow:"auto"
	});
	return this.each(function(){
		var loc;//层的绝对定位位置
		if(location==undefined || location.constructor == String){
			switch(location){
				case("rightbottom")://右下角
					hideRightFLoat(anvIframeStr);
					loc={right:"18px",bottom:"0px"};
					showRightAnvWindow();
					break;
				case("leftbottom")://左下角
					hideLeftFloat(anvIframeStr);
					loc={left:"0px",bottom:"0px"};
					showLeftAnvWindow();
					break;	
				case("lefttop")://左上角
					hideLeftFloat(anvIframeStr);
					loc={left:"0px",top:"0px"};
					showLeftAnvWindow();
					break;
				case("righttop")://右上角
					hideRightFLoat(anvIframeStr);
					loc={right:"15px",top:"0px"};
					showRightAnvWindow();
					break;
				case("rightmiddle")://右中间
					hideRightFLoat(anvIframeStr);
					var tr=0;//居上
					var windowWidth,windowHeight;//窗口的高和宽
					//取得窗口的高和宽
					if (self.innerHeight) {
						windowHeight=self.innerHeight;
					}else if (document.documentElement&&document.documentElement.clientHeight) {
						windowHeight=document.documentElement.clientHeight;
					} else if (document.body) {
						windowHeight=document.body.clientHeight;
					}
					tr=windowHeight/2-$(this).height()/2;
					loc={right:18+"px",top:tr+"px"};
					showRightAnvWindow();
					break;
				case("leftmiddle")://左中间左
					hideLeftFloat(anvIframeStr);
					var t=0;//居上
					var windowWidth,windowHeight;//窗口的高和宽
					//取得窗口的高和宽
					if (self.innerHeight) {
						windowHeight=self.innerHeight;
					}else if (document.documentElement&&document.documentElement.clientHeight) {
						windowHeight=document.documentElement.clientHeight;
					} else if (document.body) {
						windowHeight=document.body.clientHeight;
					}
					t=windowHeight/2-$(this).height()/2;
					loc={left:"0px",top:t+"px"};
					showLeftAnvWindow();
					break;
				default://默认为右下角
					hideRightFLoat(anvIframeStr);
					loc={right:"18px",bottom:"0px"};
					showRightAnvWindow();
					break;
			}
		}else{
			loc=location;
		}
		$(this).css("z-index","9999").css(loc).css("position","fixed");
		if(isIE6){
			if(loc.right!=undefined){
				//当自定义right位置时无效，这里加上一个判断
				//有值时就不设置，无值时要加18px已修正层位置
				if($(this).css("right")==null || $(this).css("right")==""){
					$(this).css("right","18px");
				}
			}
			$(this).css("position","absolute");
		}
	});
};

function showRightAnvWindow(){
   $("#switch").html("<a id='anvShow' href='javascript:hideRightAnvWindow()'><img src='anvWindow/images/closeright.png' /></a>");
   $("#HideText").html("<a href='javascript:hideRightAnvWindow()'>隐藏电视台</a>");
   $("#zoom").html("<a href='javascript:hideRightAnvWindow()'><img src='anvWindow/images/minright.png' /></a>");
	$("#anvIframe").show(1000);
}
function hideRightAnvWindow(){
   $("#switch").html("<a id='anvShow' href='javascript:showRightAnvWindow()'><img src='anvWindow/images/openright.png' /></a>");
   $("#HideText").html("<a href='javascript:showRightAnvWindow()'>打开电视台</a>");
   $("#zoom").html("<a href='javascript:showRightAnvWindow()'><img src='anvWindow/images/maxright.png' /></a>");
	$("#anvIframe").hide(1000);
}

function showLeftAnvWindow(){
   $("#switch").html("<a id='anvShow' href='javascript:hideLeftAnvWindow()'><img src='anvWindow/images/closeleft.png' /></a>");
   $("#HideText").html("<a href='javascript:hideLeftAnvWindow()'>隐藏电视台</a>");
   $("#zoom").html("<a href='javascript:hideLeftAnvWindow()'><img src='anvWindow/images/minleft.png' /></a>");
	$("#anvIframe").show(1000);
}
function hideLeftAnvWindow(){
   $("#switch").html("<a id='anvShow' href='javascript:showLeftAnvWindow()'><img src='anvWindow/images/openleft.png' /></a>");
   $("#HideText").html("<a href='javascript:showLeftAnvWindow()'>打开电视台</a>");
   $("#zoom").html("<a href='javascript:showLeftAnvWindow()'><img src='anvWindow/images/maxleft.png' /></a>");
	$("#anvIframe").hide(1000);
}
