var FCKAPI;
var FCKPageAreaId;
var FCKOverlibAreaId;

var hiddenElement=new Array();

function editInPlace(elmt,toolsbar){
	var id=elmt.id;
	var config=getEditInPlaceConfig(elmt);
	if(config.editInPlace){
		var cssClass='layer';
		if(config.toolsbar) cssClass='modal';
		window.parent.imModal(config.url,config.id,cssClass);
	}else{
		if(typeof config['newzindex']!=='undefined')
			hideElements(elmt,config['newzindex']);
		if(toolsbar){
			displayContent(config['url']+'-toolsbar','Outils','Fermer');
		}else{
			updateDivContent(config['url'],id,'auto');
			elmt.setAttribute('onmouseover','editInPlaceHightLight(this,false)');
			elmt.setAttribute('ondblclick','void(0);');
			elmt.onmouseover=function(){editInPlaceHightLight(this,false);}
			elmt.ondblclick=function(){void(0);}
		}
	}
}
function editInPlaceHightLight(elmt,display,enabledToolsbar){
	if(display){
		elmt.style.background='#DDDDDD';
		elmt.style.cursor='url(/common_images/izimedia/editInPlace.cur), auto;';
	}else{
		elmt.style.background='';
		elmt.style.cursor='default';
	}
}
function getEditInPlaceConfig(elmt){
	var jqe=$(elmt);
	var rel=jqe.attr('rel');
	if(rel){
		if(rel.substring(0,1)==='{') return eval('('+rel+')');

		var config=elmt.getAttribute('rel').split(';');
		var params=new Array();var tmp;
		for(var x=0;x<config.length;x++){
			tmp=config[x].split(':');
			params[tmp[0]]=tmp[1];
		}
		return params;
	}
	return false;
}
function loadEditInPlaceElement(){
	$('div[@rel]').each(function(i,div){
		var jqE=$(div);
		div.ondblclick=function(){
			editInPlace(this);
		}
		jqE.mouseover(function(){editInPlaceHightLight(this,true);});
		jqE.mouseout(function(){editInPlaceHightLight(this,false);});
	});
}
function reInitElement(elmtID){
	var elmt=document.getElementById(elmtID);
	var config=getEditInPlaceConfig(elmt);
	if(typeof config['newzindex']!=='undefined')
		showElements(elmt);	

	var toolsbar='false';var toolsbarIE=false;
	if(config['toolsbar']==='true'){ toolsbar='true';toolsbarIE=true;}
	elmt.setAttribute('ondblclick','editInPlace(this,'+toolsbar+')');
	elmt.ondblclick=function(){editInPlace(this,toolsbarIE)}

	elmt.setAttribute('onmouseover','editInPlaceHightLight(this,true)');
	elmt.onmouseover=function(){editInPlaceHightLight(this,true)}
	return false;
}
function hideElements(elmt,zIndexValue){
	elmt.style.position='relative';
	elmt.style.zIndex=zIndexValue;
}

function showElements(elmt){
	elmt.style.position=elmt.parentNode.style.position;
	elmt.style.zIndex=false;
}

if(typeof jQuery=='function'){
	$(document).ready(function(){
		loadEditInPlaceElement();
	});
}