function context_menu_mouse(e,what){
	var enabled = (what.className != "item_disabled")
	
	switch(e.type){
		case "mouseover":
			what.className = (enabled)? 'item_selected' : what.className
			break
		
		case "mouseout":
			what.className = (enabled)? 'item' : what.className
			break
		
		case "click":
			return enabled
			break
		
		default:
			alert('Something strange: '+e.type)
	}
}

var user_id = 0;
var id = 0;
var picture_name = "";

function initialize_menu(e,_id,_picture_name,_user_id,_contact,_rename,_delete){
	mnuContactUser.className = (_contact)? 'item' : 'item_disabled'
	mnuRename.className = (_rename)? 'item' : 'item_disabled'
	mnuDelete.className =(_delete)? 'item' : 'item_disabled'
	
	id = _id
	picture_name = _picture_name
	user_id = _user_id
	
	show_context_menu(e)
}

function show_context_menu(e){
	if(over_context_menu){
		//context_menu.onclick.fire()
		//document.fireEvent('onclick')
		return false;
	}

	context_menu.style.display = ''
	context_menu.style.zIndex = 1
	
	shadow1.style.display = ''
	shadow2.style.display = ''
	shadow3.style.display = ''
	shadow4.style.display = ''
	
	var body_w = document.body.offsetWidth + (isIE? -25 : 0)
	var body_h = document.body.clientHeight
	
	var _left = (isIE)? e.x : e.pageX + 2
	var _top = (isIE)? e.y : e.pageY + 2
	
	//Figure out left position
	if((_left + context_menu.offsetWidth) > body_w){
		context_menu.style.left = _left - context_menu.offsetWidth - 2
		_top -= 2
	}else{
		context_menu.style.left = _left
	}
	
	//figure out top position
	if(_top + context_menu.offsetHeight > _top){
		context_menu.style.top = _top
	}else{
		context_menu.style.top = _top
	}
	
	shadow1.style.left = context_menu.offsetLeft + 5
	shadow1.style.top = context_menu.offsetTop + 5
	shadow1.style.width = context_menu.offsetWidth - 4
	shadow1.style.height = context_menu.offsetHeight - 4
	
	shadow2.style.left = shadow1.offsetLeft + 2
	shadow2.style.top = shadow1.offsetTop + 2
	shadow2.style.width = shadow1.offsetWidth - 1
	shadow2.style.height = shadow1.offsetHeight - 1
	
	shadow3.style.left = shadow2.offsetLeft + 2
	shadow3.style.top = shadow2.offsetTop + 2
	shadow3.style.width = shadow2.offsetWidth - 1
	shadow3.style.height = shadow2.offsetHeight - 1
	
	shadow3.style.left = shadow2.offsetLeft + 2
	shadow3.style.top = shadow2.offsetTop + 2
	shadow3.style.width = shadow2.offsetWidth - 1
	shadow3.style.height = shadow2.offsetHeight - 1
	
	SetOpacity(shadow1,20)
	SetOpacity(shadow2,15)
	SetOpacity(shadow3,10)
	SetOpacity(shadow3,5)
	
	document.onmousedown = context_menu_close
	
	//if(isIE){
	//	document.attachEvent("onmousedown",context_menu_close)
	//}else{
	//	document.addEventListener('mousedown',context_menu_close,false)
	//}
}

var over_context_menu = false;

function context_menu_close(){
	var args = context_menu_close.arguments;
	var mouse_over = (args.length > 0 && typeof args[0] == "boolean")? args[0] : over_context_menu;
	
	if(!mouse_over){
		context_menu.style.display = 'none'
		shadow1.style.display = 'none'
		shadow2.style.display = 'none'
		shadow3.style.display = 'none'
		shadow4.style.display = 'none'
		
		document.onmousedown = null
	}
}

function menu_function(func){
	context_menu_close(false)
	
	switch(func){
		case "contact":
			window.location = "contactuser.php?id="+user_id
			break;
		case "rename":
			var _new_name = prompt("Enter a new Name for this photo below:",picture_name)
			if(_new_name != "" && _new_name != null){
				VitaminXP.Ajax.RequestUrl(document.body,"ajax/public_album.php","func="+func+"&ids="+id+"&names="+_new_name,"POST","ok")
			}
			break;
		case "delete":
			if(confirm("Are you sure you want to DELETE photo ''"+picture_name+"'' ?")){
				VitaminXP.Ajax.RequestUrl(document.body,"ajax/public_album.php","func="+func+"&ids="+id,"POST","ok")
			}
			break;
		case "all_pictures":
			window.location = 'publicalbum.php?u='+user_id
			break;
	}
}
