﻿/*
 	Antithetical Couplet Advertisement
	Name: emoney.float	
	Author: simon
	E-mail: wwqiang45@163.com
	Website: http://www.emoney.cn/
	Copyright (c) 2008, Emoney Company, All Rights Reserved
	Application method:
		 ["name","float08320"]					--可选，浮动广告赋个名字,默认随机赋值
		 ["width","115"]								--必填，浮动广告的宽度
		 ["height","210"]								--必填，浮动广告的高度
		 ["left","5"]										--浮动广告位于左边时必填，即左边距
		 ["right","5"]									--浮动广告位于右边时必填，即右边距
		 ["top","150"]									--如果以上边距为参照对象时必填，即上边距
		 ["bottom","150"]								--如果以下边距为参照对象时必填，即下边距
		 ["src","08320.swf"]  				  --必填，浮动广告的来源路径
		 ["release",true]								--可选,当有多个浮动广告时，释放关闭所有浮动广告，默认是false
		 ["close",false]								--可选,是否显示关闭按钮，默认是显示true
		 ["static",true]								--可选,浮动广告是否静态，即不随窗口改变而改变，默认是false
		 ["type","image"]								--可选,浮动广告的类型，默认是Flash，image是图片
		 ["url","http://www.hao123.com"]--可选,浮动广告类型如果是图片，这里url指定链接地址
	Example:		 
		 new emoney.float().Show([["name","floatleft"],["width","115"],["height","210"],["left","5"],["top","150"],["src","images/08320.swf"],["release",true]]);
		 new emoney.float().Show([["name","floatright"],["width","115"],["height","365"],["right","10"],["bottom","5"],["src","/ad/float/couplet_right.swf"],["static",true]]);
*/
if(typeof(emoney)!="object")
var emoney = new Object();
var $=function(strid){	
	return (typeof(strid)=="object")?strid:document.getElementById(strid);
}
var $N=function(strid){	
	return document.getElementsByName(strid);
}
emoney.float=function(){};
emoney.float.prototype={
	_type:"flash",
	_src:"",
	_url:"",
	_width:"100",
	_height:"200",
	_left:null,
	_top:null,
	_right:null,
	_bottom:null,	
	_name:"float"+function(){return (new Date()).getTime();}(),
	_closeHTML:'<span style="color:red;text-decoration:none;font-size:12px;">[关闭]</span>',
	_close:true,
	_release:false,
	_static:false,
	_ishidden:false,	
	_browser:function(){
		var _navigator=navigator.userAgent.toLowerCase();
		return 	_navigator.indexOf("opera")!=-1?"opera":(_navigator.indexOf("firefox")!=-1?"firefox":"msie");
	}(),	
	_SetSrc:function(stor){
		this._src=stor;	
	},
	_SetWidth:function(num){	
		if(/\d/.test(num))this._width=num;
	},	
	_SetHeight:function(num){
		if(/\d/.test(num))this._height=num;
	},
	_SetName:function(stor){
		this._name=stor;
	},
	_SetcloseHTML:function(stor){
		this._closeHTML=stor;
	},	
	_AddCss:function(obj,stor,append){
		if(!append){
			this._browser=="opera"?obj.setAttribute("style",stor):obj.style.cssText=stor;
		}else{				
			this._browser=="opera"?obj.setAttribute("style",obj.getAttribute("style")+stor):obj.style.cssText+=stor;		
		}
	},
	_Remove:function(obj,sign){			
			if(obj._Intervaltime)clearInterval(obj._Intervaltime);			
			if(sign){
				var ary=$N("emoney_float");				
				var _arry=[];					
				for(var k=0;k<ary.length;k++)_arry[_arry.length]=ary[k];
				for(var j=0;j<_arry.length;j++){					
					if(_arry[j].parentNode.name!=obj._name)_arry[j].click();
				};
			}		
			$(obj._name).parentNode.removeChild($(obj._name));			
			obj=null;
			//delete obj;//CollectGarbage();			
	},	
	_Hidden:function(obj){
		if(!obj._ishidden){
			$(obj._name).style.display="none";
			obj._ishidden=true;
		}
	},
	_Show:function(obj){
		if(obj._ishidden){
			$(obj._name).style.display="";	
			obj._ishidden=false;
		}
	},
	_Move:function(obj){
		var _cH=document.body.clientHeight;
		var _sT=document.body.scrollTop;
		this._Show(obj);		
		if(eval(this._top)+eval(this._height)>_cH){
			if(eval(this._height)>_cH){
				this._Hidden(obj);
			}else{
				var _newTop=_cH-eval(this._height);
				$(obj._name).style.top=(_newTop+document.body.scrollTop)+"px";
			}			
		}else{
			if(eval(this._top)<0){
				this._Hidden(obj);
			}else{
				$(obj._name).style.top=(eval(obj._top)+document.body.scrollTop)+"px";
			}
		}		
		$(obj._name).style.left=(eval(obj._left)+document.body.scrollLeft)+"px";
	},
	_CreateFunction:function(obj,strFunc){
		var args=[];
		if(!obj)obj=window;
		for(var i=2;i<arguments.length;i++)args.push(arguments[i]);
		return function(){
			obj[strFunc].apply(obj,args);
		}
	},
	_AddEvent:function(obj,eventName,eventHandler){		
		if(obj.addEventListener){
			obj.addEventListener(eventName,eventHandler,false);
		}else{
			obj.attachEvent("on"+eventName,eventHandler);
		}
	},		
	_Create:function(){
		//create div			
		var _closeDiv=(this._close)?"<div align='right' id='"+ this._name +"_close' style='position:absolute;top:0px;right:0px;z-index:200;cursor:pointer;'>"+ this._closeHTML +"</div>":"";
		var _content="";
		if(this._type=="flash"){
			//_content +="<EMBED src='" + this._src + "' quality='high' wmode='transparent' WIDTH='" + eval(this._width) +"px' HEIGHT='" + eval(this._height) + "px' TYPE='application/x-shockwave-flash'></EMBED>";		
			_content=	'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" height="'+ this._height +'" width="'+ this._width +'">';
			_content+='<param name="movie" value="'+ this._src +'">';
			_content+='<param name="quality" value="high">';
			_content+='<param name="wmode" value="opaque">';
			_content+='<embed src="'+ this._src +'" quality="high" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"  height="'+ this._height +'" width="'+ this._width +'"></embed>';
			_content+='</object>';			
		}			
		else
			_content +="<a href='" + this._url + "' target = '_blank'><img src='" + this._src + "' WIDTH='" + eval(this._width) +"px' HEIGHT='" + eval(this._height) + "px'  border='0'></a>";			
		var _div=document.createElement("div");	
		_div.id=_div.name=this._name;	
		_div.innerHTML=_closeDiv + _content;	
		var _csstext="position:absolute;width:"+ eval(this._width)+"px;height:"+ eval(this._height)+"px;";	
		//reset position
		if(!this._top)this._top="document.body.clientHeight-eval(this._height)-eval(this._bottom)";
		if(!this._left)this._left="document.body.clientWidth-eval(this._width)-eval(this._right)";		
		_csstext+="top:"+ eval(this._top)+"px;";		
		_csstext+="left:"+ eval(this._left)+"px;";		
		//add css				
		var _divChild=document.createElement("input");
		_divChild.id=_divChild.name="emoney_float";
		_divChild.type="button";
		_divChild.style.display="none";
		this._AddEvent(_divChild,"click",this._CreateFunction(this,"_Remove",this,false));			
		_div.appendChild(_divChild);
		this._AddCss(_div,_csstext,false);
		document.body.appendChild(_div);
		_div=_divChild=null;
		//add event	
		if(this._close)this._AddEvent($(this._name+"_close"),"click",this._CreateFunction(this,"_Remove",this,this._release));			
		if(!this._static)this._Intervaltime=setInterval(this._CreateFunction(this,"_Move",this),100);
	},
	Show:function(obj){
		if(!document.body){setTimeout(this._Show(),1000);return;};
		for(var i=0;i<obj.length;i++){
			this["_"+obj[i][0]]=obj[i][1];	
		}			
		this._Create();		
	}		
};