var Glossary = (function(){
	function constructor(nav,glossary){
		this.nav = nav;
		this.g = glossary;
		this.navItems = this.nav.getElementsByTagName('li');
		this.lis = this.g.getElementsByTagName('li');
		this.offset = 0;
		this.createGlossary();
	}
	
	constructor.prototype.createGlossary = function(){
		if('Cufon' in window){Cufon.replace('#glossary-nav li',{fontFamily:'a1h'});}
		/*for(var k=0;k<this.lis.length;k++){
			this.lis[k].style.top = -(this.lis[k].scrollHeight+this.offset)+"px";
			this.offset += this.lis[k].scrollHeight;
			this.lis[k].yTween = new Tween(this.lis[k],"marginTop",0,this.lis[k].scrollHeight,450,'','px',"easeSin",true);
			this.navItems[k].list = this.lis[k];
			this.navItems[k].onclick = function(){
				this.list.yTween.play();
				return false;
			}
		}*/
	}
	
	
	function startInterval(instance){
		instance.interval = setInterval(function(){instance.updateBackground();},instance.updateInterval);
	}
	
	constructor.prototype.createFrame = function(){
		this.frame = document.createElement('iframe');
		this.frame.frameborder = "0";
		this.frame.onreadystatechange = function(){
			if(this.readyState == "complete"){
				this.contentWindow.document.getElementById('close-window').controller = this.controller;
				this.contentWindow.document.getElementById('close-window').onclick = function(){
					this.controller.remove();
				}
			}
		}
		this.frame.onload = function(){
			this.contentDocument.getElementById('close-window').controller = this.controller;
			this.contentDocument.getElementById('close-window').onclick = function(){
				this.controller.remove();
			}
		}
		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.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);
	}
	
	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.onclick = function(){
			this.controller.remove();	
		}
		this.bg.style.width = this.dw+"px";
		this.bg.style.height = this.dh+"px";
		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,150,'','',"easeSin",false);
		this.bg.rTween = new Tween(this.bg,"r",this.bg.r,this.ww,150,'','',"easeSin",false);
		this.bg.bTween = new Tween(this.bg,"b",this.bg.b,this.wh,150,'','',"easeSin",false);
		this.bg.lTween = new Tween(this.bg,"l",this.bg.l,0,150,'','',"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.d.lastChild.removeChild(this.obj.controller.d.lastChild.lastChild);
			this.stop();
		}
		
		this.d.lastChild.appendChild(this.bg);
	}
	
	constructor.prototype.stopBackground = function(){
		clearInterval(this.interval);
		this.bg.style.clip = "rect(auto, auto, auto, auto)";
		this.frame.contentWindow.animation.insert();
		this.frame.style.display = "block";
		if(/MSIE/.test(navigator.userAgent)){
			this.frame.style.display = "block";
		} else {
			this.frame.oTween.play();	
		}
	}
	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();
		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.d.lastChild.lastChild);
		} else {
			this.bg.endTween.play();
		}
	}
	
	return constructor;
})();