var RegisterPopUp = (function(){
	function constructor(element){
		this.a = element;
		this.fw = 480;
		this.fh = 682;
		this.d = document.documentElement;
		this.t = this.d.scrollTop;
		this.ox = this.a.offsetTop;
		this.oy = this.a.offsetLeft;
		
		this.ow = this.a.scrollWidth;
		this.oh = this.a.scrollHeight;
		this.ww = this.d.clientWidth;
		this.wh = this.d.clientHeight+this.t;
		this.dw = this.d.scrollWidth;
		this.dh = this.d.scrollHeight;
		this.frame;
		this.bg;
		this.interval;
		this.updateInterval = 4;
		this.bgTweenSpeed = 150;
		window.controller = this;
	}
	
	function startInterval(instance){
		instance.interval = setInterval(function(){instance.updateBackground();},instance.updateInterval);
	}
	
	constructor.prototype.createFrame = function(){
		this.frame = document.createElement('iframe');
		this.frame.id = "frame";
		this.frame.frameborder = "0";
		this.frame.allowTransparency="true"

		this.frame.src = this.a.href;
		this.frame.controller = this;
		
		this.frame.width = this.fw;
		this.frame.height = this.fh;
	//	this.frame.style.top = (this.d.clientHeight-this.fh)/2+this.t+"px";
		this.frame.style.top = this.t+50+"px";
		this.frame.style.left = (this.ww-this.fw)/2+"px";
		
		this.frame.oTween = new Tween(this.frame,"opacity",0,1,450,'','',"easeSin",true);
		
		//this.bg.appendChild(this.frame);
		this.d.lastChild.appendChild(this.frame);
		if(/MSIE 6/.test(navigator.userAgent)){
			this.stopBackground();	
		}
	}
	
	constructor.prototype.createBackground = function(){
		this.bg = document.createElement('div');
		
		this.bg.t = this.ox;
		this.bg.r = this.oy+this.ow;
		this.bg.b = this.ox+this.oh;
		this.bg.l = this.oy;
		this.bg.id = "pop-up-bg";
		this.bg.controller = this;

		this.bg.style.width = this.dw+"px";
		this.bg.style.height = this.dh+"px";
		if(!/MSIE 6/.test(navigator.userAgent)){
			this.bg.style.clip = "rect("+this.bg.t+"px,"+this.bg.r+"px,"+this.bg.b+"px,"+this.bg.l+"px)";
			this.bg.tTween = new Tween(this.bg,"t",this.bg.t,this.t,this.bgTweenSpeed,'','',"easeSin",false);
			this.bg.rTween = new Tween(this.bg,"r",this.bg.r,this.ww,this.bgTweenSpeed,'','',"easeSin",false);
			this.bg.bTween = new Tween(this.bg,"b",this.bg.b,this.wh,this.bgTweenSpeed,'','',"easeSin",false);
			this.bg.lTween = new Tween(this.bg,"l",this.bg.l,0,this.bgTweenSpeed,'','',"easeSin",false);
			this.bg.tTween.onTweenFinished = function(){
				this.obj.controller.stopBackground();
				this.stop();
			}
		}
		
		
		
		this.bg.endTween = new Tween(this.bg,"opacity",1,0,50,'','',"easeSin",true);
		this.bg.endTween.onTweenFinished = function(){
			this.obj.controller.frame.parentNode.removeChild(this.obj.controller.frame);
			this.obj.controller.bg.parentNode.removeChild(this.obj.controller.bg);
			this.stop();
		}
		
		this.d.lastChild.appendChild(this.bg);
	}
	
	constructor.prototype.stopBackground = function(){
		clearInterval(this.interval);
		
		this.frame.style.display = "block";
		if(/MSIE/.test(navigator.userAgent)){
			this.frame.style.display = "block";
		} else {
			this.bg.style.clip = "rect(auto, auto, auto, auto)";
			this.frame.oTween.play();
			this.frame.oTween.onTweenFinished = function(){
				this.stop();
			}
			
		}
	}
	constructor.prototype.updateBackground = function(){
		this.bg.style.clip = "rect("+this.bg.t+"px "+this.bg.r+"px "+this.bg.b+"px "+this.bg.l+"px)";
	}
	
	constructor.prototype.display = function(){
		this.t = this.d.scrollTop;
		this.wh = this.d.clientHeight+this.t;
		this.createBackground();
		this.createFrame();
		if(!/MSIE 6/.test(navigator.userAgent)){
			this.bg.tTween.play();
			this.bg.rTween.play();
			this.bg.bTween.play();
			this.bg.lTween.play();
			startInterval(this);
		}
		
	}
	
	constructor.prototype.remove = function(){
		this.frame.oTween.stop();
		if(/MSIE/.test(navigator.userAgent)){
			this.d.lastChild.removeChild(this.frame);
			this.d.lastChild.removeChild(this.bg);
		} else {
			this.bg.endTween.play();
		}
	}
	
	return constructor;
})();