function PopupManager(){
	var arr_popups = [];
	
	function pushPopup(){}
	function getPopup(){}
	
}

function Popup(){
	var popupBox = init();
	var popupHead, popupBody, popupTitle, popupActions, popupFoot;
	$(popupBox).draggable({ handle: popupHead });
	
	var x1 = 0;
	var y1 = 0;
	var isActive = true;
	
	// declare functions
	this.test = test;
	this.init = init;
	this.display = display;
	this.clear = clear;
	this.close = close;
	this.setTitle = setTitle;
	this.clearHead = clearHead;
	this.clearBody = clearBody;
	this.clearFoot = clearFoot;
	this.appendHead = appendHead;
	this.appendAction = appendAction;
	this.appendBody = appendBody;
	this.appendFoot = appendFoot;
	this.setInnerHTML = setInnerHTML;

	this.setWidth = setWidth;
	this.setHeadColor = setHeadColor;
	this.setHeadBGColor = setHeadBGColor;
	this.setBodyColor = setBodyColor;
	this.setBodyBGColor = setBodyBGColor;
	
	function test(){
		alert('test');
	}
		
	function init(){
		var popup = cElement('div');
		popup.className = 'popup';
		
			var head = cElement('div');
			head.className = 'popup_head';
			popupHead = head;
			popup.appendChild(head);
			
				var title = cElement('div');
				title.className = 'popup_title';
				popupTitle = title;
				head.appendChild(title);
				
				var actions = cElement('div');
				actions.className = 'popup_actions';
				popupActions = actions;
				head.appendChild(actions);
				
				head.appendChild(cClearFloat());
				
			var body = cElement('div');
			body.className = 'popup_body';
			popupBody = body;
			popup.appendChild(body);
			
			var foot = cElement('div');
			foot.className = 'popup_foot';
			popupFoot = foot;
			popup.appendChild(foot);
		
		return popup;
	}
	
	function display(){
		var width = Number(popupBox.style.width.replace('px',''));
		var height = Number(popupBox.style.height.replace('px',''));
		popupBox.style.position = 'absolute';
		popupBox.style.left = "200px";
		popupBox.style.top = "100px";	
		getElement('layover').style.display = 'block';
		document.body.appendChild(popupBox);
	}
	
	function setBorderColor(cssBorderColor){
		popupBox.style.border = '1px solid ' + cssBorder;
	}
	
	function setHeadColor(cssColor){
		popupHead.style.color = '' + cssColor;
	}
	
	function setHeadBGColor(cssBGColor){
		popupHead.style.backgroundColor = '' + cssBGColor;
	}
	
	function setBodyColor(cssColor){
		popupBody.style.color = '' + cssColor;
	}
	
	function setBodyBGColor(cssBGColor){
		popupBody.style.backgroundColor = '' + cssBGColor;
	}
	
	function clear(){
		clearContent(popupBox);
	}

	function close(){	
		popupBox.style.display = "none";
		this.clear();
		delete popupBox;
		getElement('layover').style.display = "none";
	}

	function setTitle(title){
		popupTitle.innerHTML = title;
	}
	
	function setWidth(cssWidth){
		popupBox.style.width = '' + cssWidth;
	}

	function clearHead(){
		while(popupHead.firstChild){
			popupHead.removeChild(popupbox_head.firstChild);
		}
	}
	function clearBody(){
		while(popupBody.firstChild){
			popupBody.removeChild(popupbox_content.firstChild);
		}
	}
	function clearFoot(){
		while(popupFoot.firstChild){
			popupFoot.removeChild(popupbox_foot.firstChild);
		}
	}

	function appendHead(element){
		popupHead.appendChild(element);
	}
	
	function appendAction(element){
		popupActions.appendChild(element);
	}

	function appendBody(element){
		popupBody.appendChild(element);
	}

	function appendFoot(element){
		popupFoot.appendChild(element);
	}

	function setInnerHTML(innerHTML){
		var wrapper = cElement('div');
		wrapper.innerHTML = innerHTML;
		popupBox.appendChild(wrapper);
	}


}

// global variables
var popupbox_wrapper_background, popup_wrapper, popupbox, popupbox_head, popupbox_title, popupbox_content, popupbox_foot;

// initializer
function initPopup(){
	popupbox_wrapper_background = getElement('popupbox_wrapper_background');
	popupbox_wrapper = getElement('popupbox_wrapper');
	popupbox = getElement('popupbox');
	popupbox_head = getElement('popupbox_head');
	popupbox_title = getElement('popupbox_title');
	popupbox_content = getElement('popupbox_content');
	popupbox_foot = getElement('popupbox_foot');
}

function openPopup(){	
	popupbox_wrapper_background.style.display = "block";
	popupbox_wrapper.style.display = "block";
}

function closePopup(){	
	popupbox_wrapper.style.display = "none";
	popupbox_wrapper_background.style.display = "none";
	clearPopupContent();
}

function setPopupTitle(title){
	popupbox_title.innerHTML = title;
}

function clearPopup(){
	clearPopupHead();
	clearPopupContent();
	clearPopupFoot();
}

function clearPopupHead(){
	while(popupbox_head.firstChild){
		popupbox_head.removeChild(popupbox_head.firstChild);
	}
}
function clearPopupContent(){
	while(popupbox_content.firstChild){
		popupbox_content.removeChild(popupbox_content.firstChild);
	}
}
function clearPopupFoot(){
	while(popupbox_foot.firstChild){
		popupbox_foot.removeChild(popupbox_foot.firstChild);
	}
}

function insertPopupHead(element){
	popupbox_head.appendChild(element);
}

function appendPopupHead(element){
	popupbox_head.appendChild(element);
}

function insertPopupContent(element){
	popupbox_content.appendChild(element);
}

function appendPopupContent(element){
	popupbox_content.appendChild(element);
}

function insertPopupFoot(element){
	popupbox_foot.appendChild(element);
}

function appendPopupFoot(element){
	popupbox_foot.appendChild(element);
}


