/*
	131 Notif Window
	Creator: MxD
	http://www.131.com
	Created 2009-12-14
	Updated 2009-12-23.
*/

/*

*/

//兼容性补丁
if(!window.ActiveXObject){
	window.HTMLElement.prototype.__defineGetter__("children",function(){
		var c=[];
		for(var i=0,cs=this.childNodes;i<cs.length;i++){
			if(cs[i].nodeType==1)
				c.push(cs[i]);}
		return c;});
	window.HTMLElement.prototype.__defineSetter__("innerText",function(s){
		return this.textContent=s;});
	window.HTMLElement.prototype.__defineGetter__("innerText",function(){
		return this.textContent;});
	CSSStyleDeclaration.prototype.__defineGetter__("posWidth",function(){return parseInt(this.width);});
	CSSStyleDeclaration.prototype.__defineSetter__("posWidth",function(s){this.width=s+"px";});
	CSSStyleDeclaration.prototype.__defineGetter__("posHeight",function(){return parseInt(this.height);});
	CSSStyleDeclaration.prototype.__defineSetter__("posHeight",function(s){this.height=s+"px";});
	CSSStyleDeclaration.prototype.__defineGetter__("posTop",function(){return parseInt(this.top);});
	CSSStyleDeclaration.prototype.__defineSetter__("posTop",function(s){this.top=s+"px";});
	CSSStyleDeclaration.prototype.__defineGetter__("posBottom",function(){return parseInt(this.bottom);});
	CSSStyleDeclaration.prototype.__defineSetter__("posBottom",function(s){this.bottom=s+"px";});
	CSSStyleDeclaration.prototype.__defineGetter__("posLeft",function(){return parseInt(this.left);});
	CSSStyleDeclaration.prototype.__defineSetter__("posLeft",function(s){this.left=s+"px";});
	CSSStyleDeclaration.prototype.__defineGetter__("posRight",function(){return parseInt(this.right);});
	CSSStyleDeclaration.prototype.__defineSetter__("posRight",function(s){this.right=s+"px";});
}

var $=function(e){
	var o=document.getElementById(e);
	compatibleWrap(o);
	return o;
}

var compatibleWrap=function(o){
	o.addClass=function(name){
		if(!this.className)this.className=name;
		else if(this.hasClass(name))return;
		this.className+=" "+name;
	};

	o.hasClass=function(name){
		return new RegExp("\\b"+name+"\\b").test(this.className);
	};

	o.removeClass=function(name){
		if(!this.className)return;
		this.className=this.className.replace(new RegExp("\\b"+name+"\\b","ig"),"");
	};

	return o;
}

//浮动层基类
var Notif=function(args){
	args=args||{};
	var me=this;
	
	this.locking=false; //锁定
	this.fragment=args.fragment;
	this.pos=args.pos||{x:100,y:100};
	this.loaded=false;
	this.corner="l-t";

	//处理要浮动的Dom对象的
	this.fragment.style.zIndex=9000;
	//this.fragment.style.border="1px solid #000";
	//this.fragment.style.overflow="hidden";
	this.fragment.style.position=args.position||"fixed";
	/*@cc_on @*/
	/*@if (@_win32 && @_jscript_version<=5.7)
	if(navigator.appVersion.indexOf("MSIE 7.0")==-1&&this.fragment.style.position=="fixed"){
		this.fragment.style.position="absolute";
		var ie6scroll=function(){
			clearTimeout(me.t00Hanlde);
			me.t00Hanlde=setTimeout(function(){
				if(me.corner=="l-t"||me.corner=="r-t")me.fragment.style.posTop=document.documentElement.scrollTop+me.Top;
				else me.fragment.style.posTop=document.documentElement.scrollTop+document.documentElement.clientHeight-me.fragment.clientHeight-me.Bottom;
			},150);
		}
	window.attachEvent("onscroll",ie6scroll);
	}
	@end @*/


	//尝试锁定
	//返回值 成功true 失败false
	this.lock=function(){
		if(this.locking)return false;
		return this.locking=true;
	}

	//释放锁
	this.releaseLock=function(){
		this.locking=false;
	}

	//显示
	this.show=function(){
		this.fragment.style.display="block";
	}

	//隐藏
	this.hide=function(){
		this.fragment.style.display="none";
	}

	//移动
	this.Left=0;
	this.Right=0;
	this.Top=0;
	this.Bottom=0;

	this.moveSingleTo=function(key,value){
		this[key]=value;
		if(value=="") this.fragment.style[key.toLowerCase()]=value;
		else this.fragment.style["pos"+key]=value;
	}

	this.moveTo=function(x,y,corner){
		if(corner && this.corner!=corner){
			this.moveSingleTo("Left","");
			this.moveSingleTo("Right","");
			this.moveSingleTo("Top","");
			this.moveSingleTo("Bottom","");
			this.corner=corner;
		}
		if(this.corner=="l-t"){
			this.moveSingleTo("Left",x);
			this.moveSingleTo("Top",y);
			return;
		}
		if(this.corner=="l-b"){
			this.moveSingleTo("Left",x);
			this.moveSingleTo("Bottom",y);
			return;
		}
		if(this.corner=="r-t"){
			this.moveSingleTo("Right",x);
			this.moveSingleTo("Top",y);
			return;
		}
		if(this.corner=="r-b"){
			this.moveSingleTo("Right",x);
			this.moveSingleTo("Bottom",y);
			return;
		}
	}

	//调整大小
	this.resizeTo=function(x,y){
		this.fragment.style.posWidth=x;
		this.fragment.style.posHeight=y;
	}

}


/*
t=new Notif(
	//参数
	{
	fragment:$("aaa"),//浮动对象，必要
	//isBottom:false,
	isSlider:true,
	//isTimer:false;
	//pos:{x:4,y:5},
	//timeout:5000.
	haveCloseButton:true,

	position:{top:5,left:5,fixed:true},
	closeButton:{url:"",top:3,left:3},
	reduceButton:{url:"",top:3,left:3},
	scaleEffect:{pos:{left:3,top:3},speed:{horizontal:5,vertical:5},size:{width:100,height:100,maxWidth:200,maxHeight:200}}
	
	}
);
t.show();




*/






var BeitouNotif=function(args){

	this.timeout=args.timeout||15000;
	var me=this;
	var ntf=new Notif({fragment:$(args.id)});
//	if(this.closeButton){
//		var a=this.fragment.appendChild(document.createElement("a"));
//		a.style.position="absolute";
//		a.style.posTop=this.closeButton.top||3;
//		a.style.posLeft=this.closeButton.left||3;
//		a.style.display="block";
//		a.style.cursor="pointer";
//		a.innerHTML=this.closeButton.url?"<img src=\""+this.closeButton.url+"\" />":"关闭";
//		a.onclick=function(){minimize().hide();}
//	}
//
//	if(this.againButton){
//		var a=this.fragment.appendChild(document.createElement("a"));
//		a.style.position="absolute";
//		a.style.top="6px";
//		a.style.display="block";
//		a.style.cursor="pointer";
//		a.innerHTML=this.closeButton.url?"<img src=\""+this.closeButton.url+"\" />":"关闭";
//		a.onclick=function(){minimize().hide();}
//	}
	
	this.close=function(){
		ntf.fragment.style.display="none";
	}

	this.minimize=function(){
		ntf.moveTo(0,20,"l-b");
		ntf.resizeTo(100,100);
		ntf.fragment.children[0].style.display="none";
		ntf.fragment.children[1].style.display="block";
		/*@cc_on
		ntf.fragment.getElementsByTagName("object")[0].StopPlay();
		ntf.fragment.getElementsByTagName("object")[1].Play();
		@*/
		ntf.fragment.children[2].style.display="none";
		ntf.fragment.children[3].style.display="block";
	}

	this.mark=false;

	this.maximize=function(){
		var t=(document.documentElement.clientHeight-400)/2;
		var l=(document.documentElement.clientWidth-600)/2;
		ntf.moveTo(l,t,"l-t");
		ntf.resizeTo(600,400);
		ntf.fragment.children[0].style.display="block";
		ntf.fragment.children[1].style.display="none";
		ntf.fragment.children[2].style.display="block";
		ntf.fragment.children[3].style.display="none";
		if(this.mark){
			ntf.fragment.getElementsByTagName("object")[0].Rewind()
			/*@cc_on
			ntf.fragment.getElementsByTagName("object")[0].Play();
			ntf.fragment.getElementsByTagName("object")[1].StopPlay();
			@*/
		}else this.mark=true;
		setTimeout(function(){me.minimize();},this.timeout);
	}

	//init
	ntf.show();
	this.maximize();
	window.onresize=function(){
		if(ntf.fragment.children[0].style.display=="none")return;
		var t=(document.documentElement.clientHeight-400)/2;
		var l=(document.documentElement.clientWidth-600)/2;
		ntf.moveTo(l,t,"l-t");
	}
}


var SiyeNotif=function(args){
	var me=this;
	var ntf=new Notif({fragment:$(args.id),position:"absolute"});
	var sHandle=null;

	this.timeout=args.timeout||10000;
	this.width=args.width||ntf.fragment.offsetWidth;
	this.height=args.height||ntf.fragment.offsetHeight;
	this.minWidth=args.minWidth||80;
	this.minHeight=args.minHeight||80;

	this.minimize=function(){
		clearInterval(sHandle);
		sHandle=setInterval(function(){me.sliding(-33);},3);
	}

	this.maximize=function(){
		clearInterval(sHandle);
		sHandle=setInterval(function(){me.sliding(33);},3);
		ntf.fragment.children[2].getElementsByTagName("a")[0].style.display="block";
		ntf.fragment.children[2].getElementsByTagName("a")[1].style.display="none";
		ntf.fragment.children[2].getElementsByTagName("a")[2].style.display="none";
		ntf.fragment.children[0].style.display="block";
		ntf.fragment.children[1].style.display="none";
	}

	this.close=function(){
		clearInterval(sHandle);
		ntf.fragment.style.display="none";
	}

	this.sliding=function(num){
		if(num<0 && ntf.fragment.style.posWidth<=this.minWidth){
			clearInterval(sHandle);
			ntf.fragment.style.posWidth=this.minWidth;
			ntf.fragment.style.posHeight=this.minHeight;
			ntf.fragment.children[0].style.display="none";
			ntf.fragment.children[1].style.display="block";
			ntf.fragment.children[2].getElementsByTagName("a")[0].style.display="none";
			ntf.fragment.children[2].getElementsByTagName("a")[1].style.display="block";
			ntf.fragment.children[2].getElementsByTagName("a")[2].style.display="block";
		}else if(num>0 && ntf.fragment.style.posWidth>=this.width){
			clearInterval(sHandle);
			ntf.fragment.style.posWidth=this.width;
			ntf.fragment.style.posHeight=this.height;
			setTimeout(function(){me.minimize();},this.timeout);
		}else{
			ntf.fragment.style.posWidth+=num;
			ntf.fragment.style.posHeight+=num;
		}
		/*@cc_on @*/
		/*@if (@_win32 && @_jscript_version<=5.7)
		if(navigator.appVersion.indexOf("MSIE 7.0")==-1){
			ntf.fragment.style.top=ntf.fragment.style.posTop+"px";//(document.documentElement.scrollTop+(document.documentElement.clientHeight-this.fragment.clientHeight)-3);
		}
		@end @*/
	}

	//init
	ntf.moveTo(1,1,"r-t");
	ntf.show();
setTimeout(function(){me.maximize();},1000);
}




var FumeitiNotif=function(args){
	//this.timeout=args.timeout||5000;
	var me=this;
	var ntf=new Notif({fragment:$(args.id)});

	this.width=args.width||ntf.fragment.offsetWidth;
	this.height=args.height||ntf.fragment.offsetHeight;
	this.place=args.place||{corner:"r-b",x:3,y:1};

//		var a=ntf.fragment.appendChild(document.createElement("a"));
//		a.style.position="absolute";
//		a.style.posTop=3;
//		a.style.posLeft=3;
//		a.style.display="block";
//		a.style.cursor="pointer";
//		a.innerHTML="<img src=\"xxx\" alt=\"close\" />";
//		a.onclick=function(){me.close().hide();}
	

	this.show=function(){
		ntf.moveTo(this.place.x,this.place.y,this.place.corner);
		ntf.show();
	}

	this.close=function(){
		ntf.fragment.style.display="none";
		ntf.fragment.innerHTML="";
	}

	//init
	this.show();
	//setTimeout(function(){me.minimize();},this.timeout);
}





var BeitouOnlyMaxNotif=function(args){

	this.timeout=args.timeout||15000;
	var me=this;
	var ntf=new Notif({fragment:$(args.id)});
	
	this.close=function(){
		ntf.fragment.style.display="none";
		ntf.fragment.innerHTML="";
	}

	this.mark=false;

	this.maximize=function(){
		var t=(document.documentElement.clientHeight-400)/2;
		var l=(document.documentElement.clientWidth-600)/2;
		ntf.moveTo(l,t,"l-t");
		ntf.resizeTo(600,400);
		if(this.mark){
			ntf.fragment.getElementsByTagName("object")[0].Rewind()
			/*@cc_on
			ntf.fragment.getElementsByTagName("object")[0].Play();
			@*/
		}else this.mark=true;
		setTimeout(function(){me.close();},this.timeout);
	}

	//init
	ntf.show();
	this.maximize();
	window.onresize=function(){
		if(ntf.fragment.children[0].style.display=="none")return;
		var t=(document.documentElement.clientHeight-400)/2;
		var l=(document.documentElement.clientWidth-600)/2;
		ntf.moveTo(l,t,"l-t");
	}
}








var BeitouMinImgNotif=function(args){

	this.timeout=args.timeout||15000;
	var me=this;
	var ntf=new Notif({fragment:$(args.id)});
	
	this.close=function(){
		ntf.fragment.style.display="none";
	}

	this.minimize=function(){
		ntf.moveTo(0,20,"l-b");
		ntf.resizeTo(100,100);
		ntf.fragment.children[0].style.display="none";
		ntf.fragment.children[1].style.display="block";
		/*@cc_on
		ntf.fragment.getElementsByTagName("object")[0].StopPlay();
		@*/
		ntf.fragment.children[2].style.display="none";
		ntf.fragment.children[3].style.display="block";
	}

	this.mark=false;

	this.maximize=function(){
		var t=(document.documentElement.clientHeight-400)/2;
		var l=(document.documentElement.clientWidth-600)/2;
		ntf.moveTo(l,t,"l-t");
		ntf.resizeTo(600,400);
		ntf.fragment.children[0].style.display="block";
		ntf.fragment.children[1].style.display="none";
		ntf.fragment.children[2].style.display="block";
		ntf.fragment.children[3].style.display="none";
		if(this.mark){
			ntf.fragment.getElementsByTagName("object")[0].Rewind()
			/*@cc_on
			ntf.fragment.getElementsByTagName("object")[0].Play();
			@*/
		}else this.mark=true;
		setTimeout(function(){me.minimize();},this.timeout);
	}

	//init
	ntf.show();
	this.maximize();
	window.onresize=function(){
		if(ntf.fragment.children[0].style.display=="none")return;
		var t=(document.documentElement.clientHeight-400)/2;
		var l=(document.documentElement.clientWidth-600)/2;
		ntf.moveTo(l,t,"l-t");
	}
}












