function Popup(){
	this.wrapper;
	this.saran;
	this.topWrap;
	this.topLeft;
	this.topRight;
	this.topMid;
	this.bottomWrap;
	this.bottomLeft;
	this.bottomRight;
	this.bottomMid;
	this.content;
	this.Width;
	this.Height;
	this.appendTo;
	this.title; 
	this.close;
	this.topPad;
	this.removeClose = false;
	
	var thispop = this;
	
	this.init = function(){

		this.getWrapper();
		this.getTopWrapper();
		this.getBottomWrapper();
		this.getContent();
		this.topPad = 100;
		this.setHeight(200);
		this.setWidth(200);
		
	};
		
	this.getWrapper = function(){
		if(this.wrapper == null){
			this.wrapper = new Element("div",{'id':'popup','class':'popup'});
		}
		return this.wrapper;
	};
	
	this.getTopWrapper = function(){
		if(this.topWrap == null){
			
			this.topWrap = new Element("div",{'id':'topWrap'});
			this.topLeft = new Element("div",{'id':'topLeft'});
			this.topRight = new Element("div",{'id':'topRight'});
			this.topMid = new Element("div",{'id':'topMid'});
			this.title = new Element("div",{'class':'title'});
			this.close = new Element("div",{'class':'popClose'});
			Event.observe(this.close, 'click', function(){ closePop(); } );
			
			this.topWrap.setStyle({height: '28px'});
			
			this.topLeft.setStyle({background: "url('/images/corner-top-left.png')"});
			this.topRight.setStyle({background: "url('/images/corner-top-right.png')"});
		}
		return this.topWrap;
	};
	
	this.getBottomWrapper = function(){
		if(this.bottomWrap == null){
			this.bottomWrap = new Element("div",{'id':'bottomWrap'});
			this.bottomLeft = new Element("div",{'id':'bottomLeft'});
			this.bottomRight = new Element("div",{'id':'bottomRight'});
			this.bottomMid = new Element("div",{'id':'bottomMid'});
			this.bottomWrap.setStyle({height: '6px'});
			this.bottomLeft.setStyle({backgroundImage: "url('/images/corner-bottom-left.png')"});
			this.bottomRight.setStyle({backgroundImage: "url('/images/corner-bottom-right.png')"});
			
		}
		return this.bottomWrap;
	};
	
	this.setWidth = function (w){
		this.Width = parseInt(w);
	};
	
	this.buildWidth = function(w){
		this.getWrapper().setStyle({
			width: parseInt(this.Width)+"px"
		});
		[this.getBottomWrapper(),this.getTopWrapper()].collect(
				function (s){ 
					s.setStyle({
						width: parseInt(thispop.Width)+"px"
					});
				});
		[this.getBottomWrapper(),this.getTopWrapper()].collect(
				function (s){ 
					s.setStyle({
						width: parseInt(thispop.Width)+"px"
					});
				});
		[$(this.topMid),$(this.bottomMid)].collect(
				function (s){
					s.setStyle({
						width: parseInt(thispop.Width-12)+"px"
					});
				});
		[$(this.topLeft),$(this.bottomLeft),$(this.topRight),$(this.bottomRight)].collect(
				function (s){
					s.setStyle({
						width: "6px"
					});
				});
		
	};
	
	this.setRemoveClose = function(c){
		this.removeClose = c;
	}
	this.setHeight = function(h){
		this.Height = parseInt(h);
	}
	
	this.buildHeight = function(){
		//set the height of the content div 
		this.getWrapper().setStyle({height: this.Height+"px"});
		this.getContent().setStyle({height: (this.Height-12)+"px"});
		
		[this.bottomLeft,this.bottomRight].collect(function (s){ s.setStyle({width: s.getStyle('width'),'float': "left",height: "6px"});});
		[this.topLeft,this.topRight].collect(function (s){ s.setStyle({width: s.getStyle('width'),'float': "left",height: "28px"});});
		
		this.topMid.setStyle({width: this.topMid.getStyle('width'), 'float': 'left', height: '27px'});
		this.bottomMid.setStyle({width: this.bottomMid.getStyle('width'),'float': "left",height: "5px"});
	};
	
	this.getContent = function(){
		if(this.content == null){
			this.content = new Element("div",{'id':'popContent'});
			this.content.setStyle({color: 'black'});
		}
		return this.content;
	};
	
	this.addContent = function(elem){
		if(this.content == null){
			this.getContent();
		}
		
		this.getContent().appendChild(elem);
		
	};
	
	this.addHTML = function(html){
		if(this.content == null){
			this.getContent();
		}
		
		this.getContent().innerHTML = html;
	};
	
	this.setAppendTo = function (appendElem){
		this.appendTo = appendElem;
	};
	
	this.setTitle = function(title){
		this.title.update(title);
	};
	
	this.setTopPad = function (topPad){
		this.topPad = topPad;
	};
	
	this.render = function(){
		
		this.topMid.appendChild(this.title);
		if(this.removeClose == false){
			this.topMid.appendChild(this.close);
		}
		[this.bottomLeft,this.bottomMid,this.bottomRight].collect(function(s){ thispop.getBottomWrapper().appendChild(s);});
		[this.topLeft,this.topMid,this.topRight].collect(function(s){ thispop.getTopWrapper().appendChild(s);});
		
		
		this.buildWidth();
		this.buildHeight();
		
		[$(this.getTopWrapper()),
		 	$(this.getContent()),
		 	$(this.getBottomWrapper())].collect(
		 			function(s){ 
		 				$(thispop.getWrapper()).appendChild(s); 
	 				});
		$(this.appendTo).appendChild(new Element("div",{'class':'saran','id':'saran'}).setOpacity(.5));
		$(this.appendTo).appendChild(this.getWrapper());
		
		$("popup").absolutize();
		$("popup").setStyle({top: this.topPad+"px"});
	};
	
	this.close = function(){
		$("popup").remove();
		$("saran").remove();
	};
	
	this.init();
}

function closePop(){
	$("popup").remove();
	$("saran").remove();
}
