var xOffset = 5;
var yOffset = -5;
var textOn = null;
var imageOn = null;
var lastID = '';
var editMenu = 'off';
var fileName;
var page = document;
if(parent){
	var page = parent;
}

// BROWSER STATUS
function setStatus(text){
	window.status = text;
}

// REDIRECTS
function validatePage(){
	page.location.href = "http://validator.w3.org/check?uri=referer";
}
function manageData(table){
	page.location.href = tempDir+"/admin/manageData.php?table=" + escape(table);
}
function editData(table,id){
	page.location.href = tempDir+"/admin/editData.php?table=" + escape(table) + "&id=" + id + "&lastpage=" + escape(page.location.href);
}
function editFlashData(table,rowname){
	page.location.href = tempDir+"/admin/editFlashData.php?table=" + escape(table) + "&rowname=" + rowname + "&lastpage=" + escape(page.location.href);
}
function addData(table,vars){
	page.location.href = tempDir+"/admin/addData.php?table=" + escape(table) + vars + "&lastpage=" + escape(page.location.href);
}
function editText(text){
	if(text == null){
		page.location.href = tempDir+"/admin/editText.php?file=" + escape(fileName) + "&lastpage=" + escape(page.location.href);
	}else{
		page.location.href = tempDir+"/admin/editText.php?file=" + escape(text) + "&lastpage=" + escape(page.location.href);
	}
}
function editPage(){
	page.location.href = tempDir+"/admin/configPage.php?page=" + escape(phpself) + "&lastpage=" + escape(page.location.href);
}
function searchTerms(){
	page.location.href = tempDir+"/admin/searchTerms.php?page=" + escape(phpself) + "&lastpage=" + escape(page.location.href);
}
function manageFiles(dir){
	if(dir == null){
		dir = "/";
	}
	page.location.href = tempDir+"/admin/manageFiles.php?dir="+dir;
}
function editContent(data){
	if(data == null){
		page.location.href = tempDir+"/admin/editContent.php?rowname=" + escape(fileName) + "&lastpage=" + escape(page.location.href);
	}else{
		page.location.href = tempDir+"/admin/editContent.php?rowname=" + escape(data) + "&lastpage=" + escape(page.location.href);
	}
}
function editXML(){
	page.location.href = tempDir+"/admin/editXML.php?file=" + escape(fileName) + "&lastpage=" + escape(page.location.href);
}
function editImage(img){
	if(img == null){
		page.location.href = tempDir+"/admin/editImage.php?file=" + escape(fileName) + "&lastpage=" + escape(page.location.href);
	}else{
		page.location.href = tempDir+"/admin/editImage.php?file=" + escape(img) + "&lastpage=" + escape(page.location.href);
	}
}

// DIV SHOW/HIDE
function hideDiv(id){
	document.getElementById(id).style.visibility = 'hidden';
}
function showDiv(id){
	document.getElementById(id).style.visibility = 'visible';
}

// DIV ROLLOVERS
function divOver(el){
	var className = el.className+"Over";
	el.className = className;
}
function divOut(el){
	var className = el.className.replace(/Over/,"");
	el.className = className;
}	
			
// IMAGE ROLLOVERS
function imageOver(id){
	if(editMenu == 'off'){
		document.getElementById(id).className = 'imageOver';
		setStatus('Click to Edit');
	}
}
function imageOut(id){
	if(editMenu == 'off'){
		document.getElementById(id).className = 'imageOut';
		setStatus('');
	}
}

// TEXT ROLLOVERS
function textOver(id){
	if(editMenu == 'off'){
		document.getElementById(id).className = 'textOver';
		setStatus('Click to Edit');
	}
}
function textOut(id){
	if(editMenu == 'off'){
		document.getElementById(id).className = 'textOut';
		setStatus('');
	}
}

// OPEN MENU
function openMenu(id, fileInstance, event){
	if(editMenu == 'off'){
		fileName = fileInstance;
		var lastID = "text";
		if(id.indexOf("image") == 0){
			lastID = "image";
			imageOn = id;
			imageOver(id);
		}else if(id.indexOf("data") == 0){
			lastID = "data";
			textOn = id;
			textOver(id);
		}else if(id.indexOf("text") == 0){
			lastID = "text";
			textOn = id;
			textOver(id);
		}else if(id.indexOf("xml") == 0){
			lastID = "xml";
			imageOn = id;
			imageOver(id);
		}
		return !showPopup(lastID+'Menu', event);
	}
}
function showPopup(id, eventObj){
    if(eventObj){
		hideCurrent();
		eventObj.cancelBubble = true;
		var xPos = (eventObj.pageX) ? eventObj.pageX + xOffset:eventObj.x + xOffset + ((document.body.scrollLeft)?document.body.scrollLeft:0);
		var yPos = (eventObj.pageY) ? eventObj.pageY + yOffset:eventObj.y + yOffset + ((document.body.scrollTop)?document.body.scrollTop:0);
		moveObj(id, xPos, yPos);
		if(toggleObj(id, 'visible')){
			window.currentlyVisiblePopup = id;
			editMenu = 'on';
			return(true);
		}else{
			return(false);
		}
    }else{
		return(false);
    }
}
function hideCurrent(){
    if(window.currentlyVisiblePopup){
    	editMenu = 'off';
		toggleObj(window.currentlyVisiblePopup, 'hidden');
		window.currentlyVisiblePopup = false;
		if(textOn != null){
			if(lastID = 'text'){
				textOut(textOn);
			}
		}
		if(imageOn != null){
			if(lastID = 'image'){
				imageOut(imageOn);
			}
		}
    }
}

// HACKS AND WORKAROUNDS
window.onload = initializeHacks;
document.onclick = hideCurrent;
function initializeHacks(){
    if((navigator.appVersion.indexOf('MSIE 5') != -1) && (navigator.platform.indexOf('Mac') != -1) && getStyleObject('blankDiv')){
		window.onresize = explorerMacResizeFix;
    }
    resizeBlankDiv();
    createFakeEventObj();
}
function createFakeEventObj(){
    if(!window.event){
		window.event = false;
    }
}
function resizeBlankDiv(){
    if((navigator.appVersion.indexOf('MSIE 5') != -1) && (navigator.platform.indexOf('Mac') != -1) && getStyleObject('blankDiv')){
		getObj('blankDiv').width = document.body.clientWidth - 20;
		getObj('blankDiv').height = document.body.clientHeight - 20;
    }
}
function explorerMacResizeFix (){
    location.reload(false);
}

// COMMON FUNCTIONS
function getObj(objectId){
    if(document.getElementById && document.getElementById(objectId)){
		return document.getElementById(objectId).style;
    } else if(document.all && document.all(objectId)){
		return document.all(objectId).style;
    } else if(document.layers && document.layers[objectId]){
		return document.layers[objectId];
    }else{
		return(false);
    }
}
function toggleObj(id, value){
    var obj = getObj(id);
    if(obj){
		obj.visibility = value;
		return(true);
    }else{
		return(false);
    }
}
function moveObj(id, xPos, yPos){
    var obj = getObj(id);
    if(obj){
		obj.left = xPos+"px";
		obj.top = yPos+"px";
		return(true);
    }else{
		return(false);
    }
}
