var mousepos={x:0,y:0}; var tooltipvisible=false;
function efc_getMousePos(e) {
	if(!e){e=window.event};
	if (e.pageX||e.pageY) {
		mousepos.x=e.pageX;
		mousepos.y=e.pageY;
	}else {
		mousepos.x=e.clientX+(document.documentElement.scrollLeft||document.body.scrollLeft)-document.documentElement.clientLeft;
		mousepos.y=e.clientY+(document.documentElement.scrollTop||document.body.scrollTop)-document.documentElement.clientTop;
	}
	return false;
}
function efc_mousemove(e){
		efc_getMousePos(e);
		efc_tooltip_move();
		var over_cp=false;
	if(typeof(efc_check_mouseover_contentpane)=="function"){
		over_cp=efc_check_mouseover_contentpane();
	}
		var over_cm=false;
	if(typeof(efc_check_mouseover_contentmodule)=="function"){
		over_cm=efc_check_mouseover_contentmodule();
	}
		if(typeof(efc_mousemove_dnd)=="function"){
		efc_mousemove_dnd(e);
	}
}
function efc_tooltip_show(head,text){
	document.getElementById("efc_tooltip_head").innerHTML=head;
	document.getElementById("efc_tooltip_text").innerHTML=text;
	document.getElementById("efc_tooltip").style.visibility="visible";
	tooltipvisible=true;
}
function efc_tooltip_hide(){
	document.getElementById("efc_tooltip").style.visibility="hidden";
	document.getElementById("efc_tooltip_head").innerHTML="";
	document.getElementById("efc_tooltip_text").innerHTML="";
	document.getElementById("efc_tooltip").style.left="0px";
	document.getElementById("efc_tooltip").style.top="0px";
	tooltipvisible=false;
}
function efc_tooltip_move(){
	if(tooltipvisible){
		var w=document.getElementById("efc_tooltip").offsetWidth;
		if(mousepos.x+w+50<window.innerWidth){
			document.getElementById("efc_tooltip").style.left=(mousepos.x+30)+"px";
		}else{
			document.getElementById("efc_tooltip").style.left=(mousepos.x-w-40)+"px";
		}
		var h=document.getElementById("efc_tooltip").offsetHeight;
		if(mousepos.y+h<window.innerHeight){
			document.getElementById("efc_tooltip").style.top=(mousepos.y-20)+"px";
		}else{
			document.getElementById("efc_tooltip").style.top=(mousepos.y-20-h)+"px";
		}
	}
}
document.onmousemove=efc_mousemove;
var movingObj=null; var movingOffset={x:0,y:0}; var movingType=0; var sortContainers = new Array(); var sortables = new Array(); var sortingDidHappen=false; var sortingObj=null; var sortingContainer=null; var sortingOffset={x:0,y:0}; var sortingType=0; var sortingObjClass=""; function efc_getObjPos(obj){
	var objPos={x:0,y:0,width:0,height:0,realx:0,realy:0};
	objPos.width=obj.offsetWidth;
	objPos.height=obj.offsetHeight;
	objPos.realx=obj.offsetLeft;
	objPos.realy=obj.offsetTop;
	while(obj!=null){
		objPos.x+=obj.offsetLeft;
		objPos.y+=obj.offsetTop;
		obj=obj.offsetParent;
	}
	return objPos;
}
function efc_mousemove_dnd(e){
	if(movingObj!=null){
		if(movingType==1){ 						newx=(mousepos.x-movingOffset.x);
			newy=(mousepos.y-movingOffset.y);
						if(newx<0){newx=0;} 			if(newy<0){newy=0;} 			if(newx>movingObj.offsetParent.offsetWidth-movingObj.offsetWidth){newx=movingObj.offsetParent.offsetWidth-movingObj.offsetWidth;} 			if(newy>movingObj.offsetParent.offsetHeight-movingObj.offsetHeight){newy=movingObj.offsetParent.offsetHeight-movingObj.offsetHeight;} 						movingObj.style.left=newx+"px";
			movingObj.style.top=newy+"px";
		}else if(movingType==2){ 						neww=(mousepos.x-movingOffset.x);
			newh=(mousepos.y-movingOffset.y);
						if(neww<16){neww=16;} 			if(newh<16){newh=16;} 			if(neww>movingObj.offsetParent.offsetWidth-movingObj.offsetLeft){neww=movingObj.offsetParent.offsetWidth-movingObj.offsetLeft;} 			if(newh>movingObj.offsetParent.offsetHeight-movingObj.offsetTop){newh=movingObj.offsetParent.offsetHeight-movingObj.offsetTop;} 						movingObj.style.width=neww+"px";
			movingObj.style.height=newh+"px";
						var cdrn=movingObj.childNodes;
			for(var i=0;i<cdrn.length;i++){
				if(cdrn[i].tagName=="IMG"){
					cdrn[i].style.width=neww+"px";
					cdrn[i].style.height=newh+"px";
				}
			}
		}
	}
	if(sortingObj!=null){
		var moveX=true;
		var moveY=true;
		if(sortingType==2){moveY=false;}else
		if(sortingType==3){moveX=false;}
						var xPos=0;
		var yPos=0;
		if(moveX){
			xPos=mousepos.x-sortingOffset.x;
		}else{
			xPos=sortingOffset.x;
		}
		if(moveY){
			yPos=mousepos.y-sortingOffset.y;
		}else{
			yPos=sortingOffset.y;
		}
		document.getElementById("efc_dnd").style.left=xPos+"px";
		document.getElementById("efc_dnd").style.top=yPos+"px";
		document.getElementById("efc_dnd").innerHTML=sortingObj.innerHTML;
				document.getElementById("efc_dnd").style.visibility="visible";
				if(sortingObjClass==""){
			sortingObjClass=sortingObj.getAttribute("class");
			sortingObj.setAttribute("class","currentlymoving");
		}
				for(var i=0;i<sortables.length;i++){
						if(sortables[i][1]==sortingContainer.id&&sortables[i][0]!=sortingObj.id){
				var pos=efc_getObjPos(document.getElementById(sortables[i][0]));
								if(pos.x<=mousepos.x&&pos.y<=mousepos.y&&pos.x+pos.width>=mousepos.x&&pos.y+pos.height>mousepos.y){
										var t_content=document.getElementById(sortables[i][0]).innerHTML;
					var t_id=sortables[i][0];
					var t_sort_id=sortingObj.id;
					sortingObj.setAttribute("class",sortingObjClass);
					document.getElementById(sortables[i][0]).innerHTML=sortingObj.innerHTML;
					document.getElementById(sortables[i][0]).setAttribute("id",sortingObj.id);
					sortingObj.innerHTML=t_content;
					sortingObj.setAttribute("id",t_id)
										sortingObj=document.getElementById(t_sort_id);
					sortingObjClass=sortingObj.getAttribute("class");
					sortingObj.setAttribute("class","currentlymoving");
										sortingDidHappen=true;
				}
			}
		}
	}
}
function efc_ajaxSendMove(){
	var xmlMessage = efc_buildPOST("efc_moveform");
	xmlHttp.open("POST", '/ajax/', true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttp.onreadystatechange = function () {
		if (xmlHttp.readyState == 4) {
		}
	};
	xmlHttp.send(xmlMessage);
}
function efc_makeSortContainer(id, moveX, moveY){
	var num=sortContainers.length;
	sortContainers[num]=new Array(id,moveX,moveY);
}
function efc_makeSortable(id,id_container){
		var num=sortables.length;
	sortables[num]=new Array(id,id_container);
}
function efc_startDragSort(e){
	obj=e.target; 		while(obj.id==""){obj=obj.parentNode;}
		var found=-1;
		for(var i=0;i<sortables.length;i++){
		if(sortables[i][0]==obj.id){found=i;}
	}
		if(found!=-1){
				var found2=-1;
		for(var i=0;i<sortContainers.length;i++){
			if(sortContainers[i][0]==sortables[found][1]){found2=i;}
		}
				if(found2!=-1){
									sortingObj=document.getElementById(sortables[found][0]);
			sortingContainer=document.getElementById(sortables[found][1]);
						if(sortContainers[found2][1]&&!sortContainers[found2][2]){
								sortingType=2;
			}else if(!sortContainers[found2][1]&&sortContainers[found2][2]){
								sortingType=3;
			}else{
								sortingType=1;
			}
									var pos=efc_getObjPos(sortingObj);
			sortingOffset.x=mousepos.x-pos.x;
			sortingOffset.y=mousepos.y-pos.y;
						sortingDidHappen=false;
		}
	}
}
function efc_startDrag(e){
			if(efc_mouseover_contentmodule!=false){
				movingObj=document.getElementById(efc_mouseover_contentmodule);
						var pos=efc_getObjPos(movingObj);
		movingOffset.x=mousepos.x-pos.realx;
		movingOffset.y=mousepos.y-pos.realy;
				movingType=1;
	}
}
function efc_startResize(e){
	obj=e.target;
			if(efc_mouseover_contentmodule!=false){
				movingObj=document.getElementById(efc_mouseover_contentmodule);
						var pos=efc_getObjPos(movingObj);
		movingOffset.x=mousepos.x-pos.width;
		movingOffset.y=mousepos.y-pos.height;
				movingType=2;
	}
}
function efc_toggleMax(){
	if(efc_mouseover_contentmodule!=false){
		obj=document.getElementById(efc_mouseover_contentmodule);
				obj.style.top="0px";
		obj.style.left="0px";
		obj.style.right="0px";
		obj.style.bottom="0px";
		obj.style.width="auto";
		obj.style.height="auto";
		efc_commitMovement("mov("+obj.id+",-1,-1)");
		efc_commitMovement("res("+obj.id+",-1,-1)");
				efc_ajaxSendMove();
	}
}
function efc_stopDrag(){
		document.getElementById('efc_dnd').style.visibility="hidden";
		if(movingObj!=null){
				if(movingType==1){
						efc_commitMovement("mov("+movingObj.id+","+movingObj.offsetLeft+","+movingObj.offsetTop+")");
		}else if(movingType==2){
						efc_commitMovement("res("+movingObj.id+","+movingObj.offsetWidth+","+movingObj.offsetHeight+")");
		}
				efc_ajaxSendMove();
				movingObj=null;
		movingType=0;
		movingOffset.x=0;
		movingOffset.y=0;
	}
		if(sortingObj!=null){
								var sorted=sortingContainer.childNodes;
		if(sorted[0].nodeName=="TBODY"){sorted=sorted[0].childNodes;} 		var qs="menusort=";
		var tmp="";
		var k=0;
		for(var i=0;i<sorted.length;i++){
			if(sorted[i].id!=undefined&&sorted[i].id!=""){
				if(k>0){tmp+="-";}
				tmp+=sorted[i].id;
				k++;
			}
		}
		qs+=escape(tmp);
				efc_ajax_arbitrary(qs);
				if(sortingDidHappen){
			var tmp=window.location.href;
			tmp=tmp.split("/");
			var url="http:\/\/"+tmp[2]+"\/"+tmp[3]+"\/"+tmp[4]+"\/"+tmp[5]+"\/";
			window.location.href=url;
		}
				sortingObj.setAttribute("class",sortingObjClass);
		sortingObj=null;
		sortingContainer=null;
		sortingOffset.x=0;
		sortingOffset.y=0;
		sortingType=0;
		sortingObjClass="";
	}
}
function efc_deleteCMInstance(){
	if(efc_mouseover_contentmodule!=false){
				var link=window.location.href; 		tmp1=link.split("/");
		link=tmp1[0]+"/"+tmp1[1]+"/"+tmp1[2]+"/"+tmp1[3]+"/"+tmp1[4]+"/";
		link+="deleteinstance/";
		link+=efc_mouseover_contentmodule+"/";
		window.location.href=link;
	}
}
function efc_addEventListener(obj,eventname,functionname){
	if(obj.addEventListener) {
		obj.addEventListener(eventname,functionname,false); 	}else if(obj.attachEvent) {
		obj.attachEvent("on"+eventname,functionname); 	}else{
		eval("obj.on"+eventname+"="+functionname); 	}
	return false;
}
function efc_init_dnd(){
	efc_addEventListener(document,"mouseup",efc_stopDrag);
	efc_addEventListener(document,"mousedown",efc_startDragSort);
}
efc_init_dnd();
function efc_js_errormsg_close(){
	document.getElementById('error').style.visibility="hidden";
	document.getElementById('lightbox').style.visibility="hidden";
}
function efc_js_successmsg_close(){
	document.getElementById('success').style.visibility="hidden";
	document.getElementById('lightbox').style.visibility="hidden";
}
function efc_js_lightbox_show(content){
	document.getElementById('lightboxcontent').innerHTML=content;
	document.getElementById('lightboxcontent').style.visibility="visible";
	document.getElementById('lightbox').style.visibility="visible";
}
function efc_js_lightbox_hide(){
	document.getElementById('lightboxcontent').style.visibility="hidden";
	document.getElementById('lightbox').style.visibility="hidden";
}
function efc_js_submenu_show(id){
	for(var i=0;i<efc_submenus.length;i++){ 	if(efc_submenus[i]==id){
				submenu_timer=9;
		submenu_timer_running=false;
				for(var i=0;i<efc_submenus.length;i++){
			document.getElementById("submenu"+efc_submenus[i]).style.display="none";
		}
				document.getElementById("submenu"+id).style.display="inline";
	}
	}
}
function efc_js_submenu_hide(){
	submenu_timer=5;
	submenu_timer_running=true;
}
function efc_js_submenu_pause(){
	submenu_timer=9;
	submenu_timer_running=false;
}
var submenu_timer=0;
var submenu_timer_running=true;
function efc_js_submenu_timer(){
	if(submenu_timer_running){
		submenu_timer--;
		if(submenu_timer<=0){ 						submenu_timer=0;
			submenu_timer_running=false;
						for(var i=0;i<efc_submenus.length;i++){
				document.getElementById("submenu"+efc_submenus[i]).style.display="none";
			}
		}
	}
	setTimeout("efc_js_submenu_timer()",300);
}
setTimeout("efc_js_submenu_timer()",1000);

