var xw;
var config = {
widthMax:300,				//放大后内容的宽
heightMax:300,				//放大后内容的高（整体的高为此值再加20）
widthMin:100,				//缩小后的宽
heightMin:100,				//缩小后的高
margin:10,					//距底部的距离
speed:200,					//效果的速度
effect:1,					//选择效果，效果可以自己扩展 0-无效果 1-滑动特效
imgurl:"/guanggao/image/img.jpg",		//缩小后的背景图片地址
key:1,						//选择默认窗体状态 0-缩小 1-放大
acolor:"#fff",				//缩小后链接的颜色
flash:"http://space.tv.cctv.com/library/column/xinwenqita/jingjixinxilianboC916/new1/C916/stylenew/player.swf",	//flash地址
adurl:"http://a.cctv.com/hserver/aamsz=300_250/site=tv.cctv.com/ADTYPE=vod/PAGE_GROUP=C18307000002/PAGE_LOCATION=FIRST_SCREEN/", //flash参数地址
advurl:"http://www.gionee.net/"	//缩小后广告地址
}
jQuery(function(){
xw = new xTipWin(config);			
xw.install();
});
function clearPlayer(){
adStop();
xw._w_min();
}
function adStop(){
thisMovie("adplayer").adPlayStop();
}
function adReplay(){
thisMovie("adplayer").adReplay();
}
function thisMovie(movieName) {
if (navigator.appName.indexOf("Microsoft") != -1) {
return window[movieName];
}else {
return document[movieName];
}
}
function xTipWin(cfg){
cfg.heightMax += 20;
var opts = this.cfgs = jQuery.extend({title:"cctv",widthMax:200,heightMax:200,widthMin:50,heightMin:50,speed:250,effect:0,margin:10,imgurl:"123.gif",content:'hello world!'},cfg);				//默认属性，如果有配置信息则被覆盖
var pm 				 = this.cfgs.margin;	
var win_status 	 	 = this.cfgs.key;					//0缩小,1放大
this._w_min =function() {
w_min();
}
//安装
this.install =function(options) {
var tc = [],i=0;
tc[i++] = '  <div id="cctv_float_win">';
tc[i++] = ' 	 <div id="cctv_float_max">';
tc[i++] = ' 		 <div id="cctv_float_win_content">';
tc[i++] = ' 			 <script type="text/javascript">';
tc[i++] = ' 				addFlashTo("cctv_float_win_content","'+this.cfgs.flash+'?adurl='+this.cfgs.adurl+'",'+this.cfgs.widthMax+','+this.cfgs.heightMax+',{"id":"adplayer","name":"adplayer","wmode":"transparent"});';
tc[i++] = ' 			 <\/script>';
tc[i++] = ' 		 </div>';
tc[i++] = ' 		 <div id="cctv_float_min" >';
tc[i++] = ' 			<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">';
tc[i++] = ' 			  <tr>';
tc[i++] = ' 				 <td class="advs" height="75" colspan="2"></td>';
tc[i++] = ' 			  </tr>';
tc[i++] = ' 			  <tr>';
tc[i++] = ' 				 <td height="25" width="50%" align="right">';
tc[i++] = ' 					<a href="javascript:void(0)" class="w_replay">重播</a>';
tc[i++] = ' 				 </td>';
tc[i++] = ' 				 <td align="center">';
tc[i++] = ' 					<a href="javascript:void(0)" class="w_close">关闭</a>';
tc[i++] = ' 				 </td>';
tc[i++] = ' 			  </tr>';
tc[i++] = ' 			</table>';
tc[i++] = ' 		 </div>';
tc[i++] = ' 	 </div>';
tc[i++] = '  </div>';
tc	= tc.join('');
if(this.cfgs.key==0){
jQuery(tc).css({width:this.cfgs.widthMin,height:this.cfgs.heightMin}).appendTo("body");
jQuery("#cctv_float_win_content").css({left:this.cfgs.widthMax});
}else{
jQuery(tc).css({width:this.cfgs.widthMax,height:this.cfgs.heightMax}).appendTo("body");
jQuery("#cctv_float_min").css("display","none");
jQuery("#cctv_float_win_content").css({width:this.cfgs.widthMax,height:this.cfgs.heightMax});
}
jQuery("#cctv_float_min").css("background","url("+this.cfgs.imgurl+")");
jQuery("#cctv_float_min table a").css("color",this.cfgs.acolor);
this.redraw();
//jQuery("#cctv_float_win_header a.w_min").click(function(){w_min()});
jQuery("#cctv_float_min a.w_close").click(function(){w_close()});
jQuery("#cctv_float_min a.w_replay").click(function(){w_show()});
jQuery("#cctv_float_min .advs").bind("click",function(){ window.open(opts.advurl) });
}
//窗体位置
var play = window.setInterval(function(){return movie()},10);
//当窗体滚动或改变大小时重绘
var movie = this.redraw = function(){
var t;
if(document.documentElement.scrollTop > document.body.clientHeight){
document.documentElement.scrollTop = document.body.clientHeight;
}	
t = (document.documentElement.clientHeight - jQuery("#cctv_float_win").height() - pm)+document.documentElement.scrollTop;
jQuery('#cctv_float_win').css({top:t});
}
//变大
function w_show(){
if(win_status == 1) return;
jQuery("#cctv_float_min").css("display","none");
stop_t();
effects(opts.effect);
win_status = 1;
}
//变小
function w_min(){
if(win_status == 0) return;
jQuery("#cctv_float_win_content").css({left:opts.widthMax});
stop_t();
effects(opts.effect);
win_status = 0;
}
//关闭
function w_close(){
window.clearInterval(play);
jQuery("#cctv_float_win").css( {display:'none'} );
}
//关闭刷屏
function stop_t(){
window.clearInterval(play);
if(navigator.userAgent.indexOf('MSIE 6.0')>0){
jQuery("#cctv_float_win").css( {bottom:opts.margin-2,top:'auto'} );
}else{
jQuery("#cctv_float_win").css( {bottom:opts.margin-Number(document.documentElement.scrollTop)-2,top:'auto'} );
}
}
//特效
function effects(type){
var eh = new ef_height();
switch(type){
case 1:
jQuery("#cctv_float_win").animate({width:eh.w,height:eh.h},opts.speed,function(){if(win_status==0){jQuery("#cctv_float_min").css("display","")}else{jQuery("#cctv_float_win_content").css({top:0,left:0});};play = window.setInterval(function(){return movie()},10); win_status==1?adReplay():"";});
break;
default:
jQuery("#cctv_float_win").css({width:eh.w,height:eh.h});
win_status==1?jQuery("#cctv_float_min").css("display",""):jQuery("#cctv_float_win_content").css({top:20,left:0});
if(win_status==0){
jQuery("#cctv_float_min").css("display","")
}else{
jQuery("#cctv_float_win_content").css({top:0,left:0});
}
play = window.setInterval(function(){return movie()},10);
adReplay();
break;
}
}
//特效高度的自动转换
function ef_height(){
if(win_status==0){
return {h:opts.heightMax,w:opts.widthMax};
}
return {h:opts.heightMin,w:opts.widthMin};
}
}