
var popup = Class.create({
	  initialize: function(title,content){		
	    this.popupDiv = new Element('div', {'id':'popUpDiv', 'style': 'display:none;'});
	    this.topDiv = new Element('div', { 'style': 'text-align:right;font-size:15px;'});
	    this.closeButton = new Element('span', {'style':'cursor:pointer;'}).update("X");
	    this.topDiv.appendChild(this.closeButton);
	    this.popupDiv.appendChild(this.topDiv);
	    this.title= new Element('h3', {});
	    this.title.innerHTML = title;
	    this.popupDiv.appendChild(this.title);
	    this.content= new Element('p', {});
	    this.content.innerHTML = content;
	    this.popupDiv.appendChild(this.content);
	    
	    Element.insert(document.body, this.popupDiv);
	    Event.observe(this.closeButton, "click",this.popup.bind(this), false);
	},

    toggle: function(div_id) {
		var el = document.getElementById(div_id);
		if ( el.style.display == 'none' ) {	el.style.display = 'block';}
		else {el.style.display = 'none';}
	},

	blanket_size: function(popUpDivVar) {
		if (typeof window.innerWidth != 'undefined') {
			viewportheight = window.innerHeight;
		} else {
			viewportheight = document.documentElement.clientHeight;
		}
		if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
			blanket_height = viewportheight;
		} else {
			if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
				blanket_height = document.body.parentNode.clientHeight;
			} else {
				blanket_height = document.body.parentNode.scrollHeight;
			}
		}
		var blanket = document.getElementById('blanket');
		blanket.style.height = blanket_height + 'px';
		var popUpDiv = document.getElementById(popUpDivVar);
		popUpDiv_height=blanket_height/2-200;	//200 is half popup's height
		//	popUpDiv.style.top = popUpDiv_height + 'px';
	},
	
	window_pos: function(popUpDivVar) {
		if (typeof window.innerWidth != 'undefined') {
			viewportwidth = window.innerHeight;
		} else {
			viewportwidth = document.documentElement.clientHeight;
		}
		if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth)) {
			window_width = viewportwidth;
		} else {
			if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) {
				window_width = document.body.parentNode.clientWidth;
			} else {
				window_width = document.body.parentNode.scrollWidth;
			}
		}
		var popUpDiv = document.getElementById(popUpDivVar);
		window_width=window_width/2-200;	//200 is half popup's width
		popUpDiv.style.left = window_width + 'px';
	},

	popup:function(windowname) {
		this.blanket_size(this.popupDiv.id);
		this.window_pos(this.popupDiv.id);
		this.toggle('blanket');
		this.toggle(this.popupDiv.id);		
	}	    
});
