var siteWidth;
var siteHeight;
var popUpBackground = 'PopupBackground';
var PopupContainer =  'PopupContainer';
var popupBackgroundObject = null;
var popupContainerObject  = null;
var resizeDelay;
var upDateDelay = '100';
var popupStatus = false;

function adjustBackground() {
	siteHeight = document.body.offsetHeight;
	clientBrowserHeightWidth(siteHeight, siteWidth);
	popupBackgroundObject.style.height = browserHeightWidth.browserHeight + 'px';
	popupBackgroundObject.style.width = browserHeightWidth.browserWidth + 'px';
}

function repositionVertical() {
	clientBrowserHeightWidth(siteHeight, siteWidth);
	siteHeight = document.body.offsetHeight;
	var popUpHeight = popupContainerObject.offsetHeight;
	var amendClientBrowserHeight = browserHeightWidth.browserHeight / 2;
	var popUpMarginTop = amendClientBrowserHeight - (popUpHeight / 2);
	popupContainerObject.style.marginTop = popUpMarginTop + 'px';
}

function repositionHorizontal() {
	clientBrowserHeightWidth(siteHeight, siteWidth);
	siteHeight = document.body.offsetHeight;
	var popUpWidth = popupContainerObject.offsetWidth;
	var amendclientBrowserWidth = browserHeightWidth.browserWidth / 2;
	var popUpMarginLeft = amendclientBrowserWidth - (popUpWidth / 2);
	popupContainerObject.style.marginLeft = popUpMarginLeft + 'px';
}

function openPopup(obj) {
	clientBrowserHeightWidth(siteHeight, siteWidth);
	var popupObject = obj.parentNode.getElementsByTagName('div');
	for(i=0; i<popupObject.length; i++){
		var popupStructureItem = popupObject[i].className;
		switch (popupStructureItem){
			case popUpBackground:
				popupBackgroundObject = popupObject[i];
				popupBackgroundObject.style.display = 'inline';
				popupBackgroundObject.style.height = browserHeightWidth.browserHeight;
				popupBackgroundObject.style.width = browserHeightWidth.browserWidth;
				
				popupBackgroundObject.onclick = function(){
					closePopup();
				}
				break;
			case PopupContainer:
				popupContainerObject = popupObject[i];
				popupContainerObject.style.display = 'inline';
				break;
			default:
				break;
		}
	}
	repositionVertical();
	repositionHorizontal();
	popupStatus = true;
}

function closePopup() {
	popupBackgroundObject.style.display = 'none';
	popupContainerObject.style.display = 'none';
	popupBackgroundObject = null;
	popupContainerObject  = null;
	popupStatus = false;

}

function resize(){
	switch (popupStatus){
		case true:
			adjustBackground();
			repositionVertical();
			repositionHorizontal();
			break;
		case false:
			break;
		default:
			break;
	}
}
