var hscfg="";
var opt_states=[];
function isChild(child,parent){
   for(var elm=child;elm!=null&&elm!=parent;elm=elm.parentNode);
   return (elm==parent);
}
function getwinsize(){
	var w = 0, h = 0;
	if(typeof(window.innerWidth) == 'number'){w = window.innerWidth;h = window.innerHeight;}
	else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)){
		w = document.documentElement.clientWidth;h = document.documentElement.clientHeight;
	}
	else if(document.body && (document.body.clientWidth || document.body.clientHeight)){
		w = document.body.clientWidth;h = document.body.clientHeight;
	}
	var sx = 0, sy = 0;
	if(typeof(window.pageYOffset ) == 'number'){sy = window.pageYOffset;sx = window.pageXOffset;}
	else if(document.body && (document.body.scrollLeft || document.body.scrollTop)){
		sy = document.body.scrollTop;sx = document.body.scrollLeft;
	}
	else if(document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)){
		sy = document.documentElement.scrollTop;sx = document.documentElement.scrollLeft;
	}
	return {w:w,h:h,sx:sx,sy:sy};
}
function enableTextSelection(flag){
	var fn=flag?null:function(){return false};
	document.body.ondrag=fn;
	document.body.onselectstart=fn;
	var mozclass=flag?"":"noselection";
	document.body.className=mozclass;
}
function boxOver(o){
	var box=o.id.split("_")[0];
	if(oedit=gel(box+"_edit")){
		oedit.style.display="block";
	}
}
function boxOut(o){
	var box=o.id.split("_")[0];
	var num=box.substr(3);
	if(opt_states[num]!=true){
		if(oedit=gel(box+"_edit")){
			oedit.style.display="none";
		}
	}
}
function Controls(){
	this.holder=null;
	this.txt=null;
	this.html=null;
	this.type=null;
	this.subtype=null;
	this.visible=false;
	this.ready=false;
	this.optslistlength=0;
	this.getHTML=function(){
		if(!this.html){
			/*
			_localizer.openGroup('customizer');
			var mopts=[],ropts=[];
			if(!this.isDisabledModule('news')) mopts.push({id:"news",tit:_localizer.tr('optnewstitle'),txt:_localizer.tr('optnewstext')});
			if(!this.isDisabledModule('charts')) mopts.push({id:"charts",tit:_localizer.tr('optchartstitle'),txt:_localizer.tr('optchartstext')});
			if(!this.isDisabledModule('newsstyles')) mopts.push({id:"newsstyles",tit:_localizer.tr('optstylestitle'),txt:_localizer.tr('optstylestext')});
			if(!this.isDisabledModule('topsearch')) mopts.push({id:"topsearch",tit:_localizer.tr('opttopsearchtitle'),txt:_localizer.tr('opttopsearchtext')});
			if(!this.isDisabledModule('dir')) ropts.push({id:"dir",tit:_localizer.tr('optcatalogtitle'),txt:_localizer.tr('optcatalogtext')});
			if(!this.isDisabledModule('live')) ropts.push({id:"live",tit:_localizer.tr('optonairtitle'),txt:_localizer.tr('optonairtext')});
			if(!this.isDisabledModule('ebay')) ropts.push({id:"ebay",tit:_localizer.tr('optebaytitle'),txt:_localizer.tr('optebaytext')});
			if(!this.isDisabledModule('tod')) ropts.push({id:"tod",tit:_localizer.tr('opttopofthedaytitle'),txt:_localizer.tr('opttopofthedaytext')});
			var h="";
			//h+="<div class=cbox_a><table class=ctbl cellpadding=0 cellspacing=0><tr valign=top><td class=chdr style=\"padding-left:40px;cursor:default\"><a class=chdrtitle>"+_localizer.tr('paneltitle')+"</a></td><td valign=middle><a href=\"#\" onclick=\"return _controls.hide()\"><img class=iboxclose src=\""+pictv41_dir+"hm_box_close.gif\" width=19 height=15 border=0></a></td></tr></table><div class=ctrlstop>"+_localizer.tr('panelhelp')+" :</div><div class=boxctrlscontent><table width=100%><tr valign=top><td>";
			h+="<div class=cbox_a><div class=\"boxctrlshelp\">"+_localizer.tr('panelhelp')+"</div><div class=boxctrlscontent><table width=100%><tr valign=top><td>";
			for(var i=0;i<mopts.length;i++){h+="<div class=ctrlsbox id=\"opts_"+mopts[i].id+"\" href=# onclick=\"return _controls.setContentType('"+mopts[i].id+"')\" onmouseover=\"_controls.boxov('"+mopts[i].id+"')\" onmouseout=\"_controls.boxout('"+mopts[i].id+"')\"><div class=ctrlsboxin id=\"optsi_"+mopts[i].id+"\"><div class=ctrlsboxt>"+mopts[i].tit+"</div><div class=ctrlsboxi>"+mopts[i].txt+"</div></div></div>";}
			h+="</td><td width=305>";
			for(var i=0;i<ropts.length;i++){h+="<div class=ctrlsbox id=\"opts_"+ropts[i].id+"\" href=# onclick=\"return _controls.setContentType('"+ropts[i].id+"')\" onmouseover=\"_controls.boxov('"+ropts[i].id+"')\" onmouseout=\"_controls.boxout('"+ropts[i].id+"')\"><div class=ctrlsboxin id=\"optsi_"+ropts[i].id+"\"><div class=ctrlsboxt>"+ropts[i].tit+"</div><div class=ctrlsboxi>"+ropts[i].txt+"</div></div></div>";}
			h+="</td>";
			h+="</tr></table>";
			h+="</div></div>";
			this.html=h;
			*/
			_localizer.openGroup('customizer');
			var ropts=[];
			if(!this.isDisabledModule('dir')) ropts.push({id:"dir",tit:_localizer.tr('optcatalogtitle'),txt:_localizer.tr('optcatalogtext')});
			if(!this.isDisabledModule('live')) ropts.push({id:"live",tit:_localizer.tr('optonairtitle'),txt:_localizer.tr('optonairtext')});
			if(!this.isDisabledModule('ebay')) ropts.push({id:"ebay",tit:_localizer.tr('optebaytitle'),txt:_localizer.tr('optebaytext')});
			if(!this.isDisabledModule('tod')) ropts.push({id:"tod",tit:_localizer.tr('opttopofthedaytitle'),txt:_localizer.tr('opttopofthedaytext')});
			var h="";
			//h+="<div class=cbox_a><table class=ctbl cellpadding=0 cellspacing=0><tr valign=top><td class=chdr style=\"padding-left:20px;cursor:default\"><a class=chdrtitle>"+_localizer.tr('paneltitle')+"</a></td><td valign=middle><a href=\"#\" onclick=\"return _controls.hide()\"><img class=iboxclose src=\""+pictv41_dir+"hm_box_close.gif\" width=19 height=15 border=0></a></td></tr></table><div class=ctrlstop>"+_localizer.tr('panelhelp')+" :</div><div class=boxctrlscontent><table width=100%><tr><td>";
			h+="<div class=cbox_a><div class=\"boxctrlshelp\">"+_localizer.tr('paneltitle')+"</div><div class=boxctrlscontent><table width=100%><tr valign=top><td><div class=\"panelhelp\">"+_localizer.tr('panelhelp')+" :</div>";
			for(var i=0;i<ropts.length;i++){h+="<div class=ctrlsbox id=\"opts_"+ropts[i].id+"\" href=# onclick=\"return _controls.setContentType('"+ropts[i].id+"')\" onmouseover=\"_controls.boxov('"+ropts[i].id+"')\" onmouseout=\"_controls.boxout('"+ropts[i].id+"')\"><div class=ctrlsboxin id=\"optsi_"+ropts[i].id+"\"><div class=ctrlsboxt>"+ropts[i].tit+"</div><div class=ctrlsboxi>"+ropts[i].txt+"</div></div></div>";}
			h+="</td>";
			h+="</tr></table>";
			h+="</div></div>";
			this.html=h;
		}
		return this.html;
	}
	this.isDisabledModule=function(mod_id){
		if(typeof(wdgtdsbl)=='undefined') return false;
		for(var i=0;i<wdgtdsbl.length;i++){if(mod_id==wdgtdsbl[i]) return true;}
		return false;
	}
	this.setContentType=function(type){
		if(this.type==type){this.type=null;this.closeOptions();}
		else{this.closeOptions(true);this.type=type;this.showOptions();}
		return false;
	}
	this.boxov=function(type){
		if(b=gel("optsi_"+type)){b.style.padding=0;b.style.border="2px solid black";}
	}
	this.boxout=function(type){
		if(this.type!=type){
			if(b=gel("optsi_"+type)){b.style.border="";b.style.padding="2px";}
		}
	}
	this.getRSSSources=function(){
		var hw = "687474703a2f2f7777772e";
		var rss_sources=[{txt:"France 3 - musique",uid:"687474703a2f2f7273732e6672616e6365332e66722f63756c747572652d65742d6c6f69736972732d6d7573697175652e786d6c"},{txt:"LesInrocks.com - news",uid:hw+"6c6573696e726f636b732e636f6d2f786d6c2f7273732f6c6573696e726f636b732e786d6c"},{txt:"LesInrocksParis.com - concerts",uid:hw+"6c6573696e726f636b732e636f6d2f786d6c2f7273732f6c6573696e726f636b7370617269735f636f6e632e786d6c"},{txt:"Libération.fr - musiques",uid:hw+"6c696265726174696f6e2e66722f696e74657261637469662f7273732f63756c747572657273732f6d757369717565737273732f696e6465782e46522e706870"},{txt:"MCM News",uid:hw+"6d636d2e6e65742f666565647273732f6d636d2f6d636d2e786d6c"},{txt:"Novaplanet.com - News",uid:hw+"6e6f7661706c616e65742e636f6d2f73796e6469636174696f6e2d7273732d786d6c2f7273732d6e6577732d6d7573697175652e786d6c"},{txt:"NRJ Music News",uid:hw+"6e726a2e66722f64796e616d69632f7273732e7068703f69643d3132343426747970653d727373322e30"},{txt:"RTL Muzik",uid:hw+"72746c2e66722f7265666572656e63656d656e742f72746c6d757a696b2e617370"}];
		return rss_sources;
	}
	this.getOptionsContent=function(){
		_localizer.openGroup('customizer');
		this.subtype = -1;
		var h="";
		h+="<table cellpadding=0 cellspacing=0><tr valign=top><td>";
		switch(this.type){
			case "news":case "charts":
				/*
				h+="<div id=ctrlsoptcontent><div id=ctrlsoptcontentt>"+_localizer.tr('choosestyle')+"</div><div id=ctrlsoptlist><div class=ctrlsoptidx id=ctrlsoptidx0 style=\"font-weight:bold\" onclick=\"return _controls.setOptionsIndex(0)\" onmouseover=\"this.className='ctrlsoptidxov'\" onmouseout=\"this.className='ctrlsoptidx'\">"+_localizer.tr('styles/mixed')+"</div>";
				for(var i=1;i<Number(_localizer.tr('utils/totalstyles'));i++){h+="<div class=ctrlsoptidx id=ctrlsoptidx"+i+" onclick=\"return _controls.setOptionsIndex("+i+")\" onmouseover=\"this.className='ctrlsoptidxov'\" onmouseout=\"this.className='ctrlsoptidx'\">"+_localizer.tr('styles/style'+i)+"</div>";}
				h+="</div>";
				this.subtype=0;this.optslistlength=ssts.length;
				*/
				h+="<div id=ctrlsoptcontent style=\"padding-top:3px;padding-bottom:2px\">";
				this.subtype=0;
			break;
			case "rss":
				var rss_sources = this.getRSSSources();
				h+="<div id=ctrlsoptcontent><table cellpadding=0 cellspacing=0 width=100%><tr><td><b style=\"font-size:12px\">Sélectionnez un fil RSS</b></td><td align=right style=\"padding-left:8px\"><a href=\"#\" onclick=\"return _controls.closeOptions()\"><img src=\""+pictv41_dir+"hm_box_close.gif\" width=19 height=15 border=0></a></td></tr></table><div id=ctrlsoptlist>";
				h+="<div style=\"margin-bottom:4px\">Choisisssez parmi les exemples de fils d'actualité musicale :</div>";
				for(var i=0;i<rss_sources.length;i++){h+="<div id=ctrlsoptidx"+i+"_on><a href=# onclick=\"return _controls.setOptionsIndex("+i+")\">"+rss_sources[i].txt+"</a></div><div id=ctrlsoptidx"+i+"_off style=\"display:none\"><b style=\"color:#4c3d9a\">&raquo; "+rss_sources[i].txt+"</b></div>";}
				h+="<div style=\"margin-top:6px\">... ou ajoutez un fil RSS en copiant son adresse ci-dessous :<br><input type=text id=rssurl style=\"border:1px solid #999999;width:180px\"></div>";
				h+="</div>";
				this.optslistlength=rss_sources.length;
			break;
			default:
				h+="<div id=ctrlsoptcontent style=\"padding-top:3px;padding-bottom:2px\">";
		}
		h+="<table cellpadding=0 cellspacing=0 align=center><tr><td align=center><a class=\"txtbtn\" href=# onclick=\"return _controls.addContent()\">"+_localizer.tr('addmodule').toUpperCase()+"</a></td></tr></table></div></td></tr></table>";
		return h;
	}
	this.setOptionsIndex=function(idx){
		this.subtype=idx;
		for(var i=0;i<this.optslistlength;i++){
			/*if(o=gel("ctrlsoptidx"+i+"_on")){o.style.display=(i==idx?"none":"block");}
			if(o=gel("ctrlsoptidx"+i+"_off")){o.style.display=(i==idx?"block":"none");}*/
			if(o=gel("ctrlsoptidx"+i)){o.style.fontWeight=(i==idx?"bold":"normal");}
		}
		return false;
	}
	this.showOptions=function(){
		//this.closeOptions();
		var ref=gel("opts_"+this.type);var refpos=getPos(ref);
		var opts=document.createElement("div");
		opts.setAttribute("id","ctrlsopt");opts.innerHTML=this.getOptionsContent();opts.style.left=(refpos.x+1)+"px";opts.style.top=(refpos.y+33)+"px";
		this.holder.appendChild(opts);
		if(document.attachEvent)document.attachEvent("onclick",_controls.clickOutside);
		else if(document.addEventListener)document.addEventListener("click",function(e){_controls.clickOutside(e)},false);
		return false;
	}
	this.closeOptions=function(out){
		if(o=gel("ctrlsopt")){this.holder.removeChild(o);}
		if(out){var ptype=this.type;this.type=null;this.boxout(ptype)};
		return false;
	}
	this.clickOutside=function(e){
		var srcEle=null;
		var ev=window.event?window.event:e;
		ev.cancelBubble=true;
		if(window.event) srcEle = window.event.srcElement;
		else if(e) srcEle = e.target;
		if(srcEle!=gel("opts_"+_controls.type)&&!isChild(srcEle,gel("opts_"+_controls.type))&&!isChild(srcEle,gel("ctrlsopt"))){
			if(document.detachEvent)document.detachEvent("onclick",_controls.clickOutside);
			else if(document.removeEventListener)document.removeEventListener("click",function(e){_controls.clickOutside(e)},false);
			_controls.closeOptions(true);
		}
		
	}
	this.addContent=function(){
		switch(this.type){
			//case "news":case "charts":_mngr.addModule("main",this.type,this.subtype);break;
			case "news":case "charts":_mngr.addModuleEx("main",this.type,this.subtype);break;
			case "newsstyles":_mngr.addModuleEx("main",this.type);break;
			case "topsearch":_mngr.addModuleEx("main",this.type);break;
			case "live":case "dir":case "ebay":case"tod":_mngr.addModuleEx("right",this.type);break;
			case "rss":if(this.subtype > -1){var urss=this.getRSSSources()[this.subtype]["uid"];_mngr.addModule("right",this.type,urss)}else _mngr.addModuleError(this.type);break;
		}
		return false;
	}
	this.show=function(){
		_login.hide2();
		this.holder.innerHTML=this.getHTML();
		this.holder.style.display="block";
		this.txt.innerHTML=_localizer.tr('customizer/close');
		this.txt.style.color = "#282828";
		this.txt.style.backgroundColor = "#adadac";
		this.visible=true;
		return false;
	}
	this.hide=function(){
		this.holder.style.display="none";
		this.txt.innerHTML=_localizer.tr('customizer/personalizepage');
		this.txt.style.color = "#282828";
		this.txt.style.backgroundColor = "#adadac";
		this.visible=false;
		return false;
	}
	this.hide2=function(){
		if(this.ready && this.visible) this.hide();
	}
	this.showhide=function(){
		if(this.visible) this.hide();
		else this.show();
	}
	this.init=function(holderId,txtId){
		this.holder=gel(holderId);
		this.txt=gel(txtId);
		this.ready=true;
	}
}
function Login(){
	this.holder=null;
	this.txt=null;
	this.html=null;
	this.visible=false;
	this.ready=false;
	this.getHTML=function(){
		if(!this.html){
			var h="";
			h+="<div class=cbox_a><table class=ctbl><tr valign=top><td class=chdr><a class=chdrtitle>Connexion</a></td><td valign=middle><a href=\"#\" onclick=\"return _login.hide()\"><img class=iboxclose src=\""+pictv41_dir+"hm_box_close.gif\" width=19 height=15 border=0></a></td></tr></table><div class=boxctrlscontent>";
			h+="<table><form><tr><td colspan=3><b>Saisissez vos identifiants :</b></td></tr><tr><td>Adresse e-mail</td><td>:</td><td><input type=text></td></tr><tr><td>Mot de passe</td><td>:</td><td><input type=password></td></tr></form></table>";
			h+="</div></div>";
			this.html=h;
		}
		return this.html;
	}
	this.show=function(){
		_controls.hide2();
		this.holder.innerHTML=this.getHTML();
		this.holder.style.display="block";
		this.txt.innerHTML="Fermer";
		this.visible=true;
		return false;
	}
	this.hide=function(){
		this.holder.style.display="none";
		this.txt.innerHTML="Connexion";
		this.visible=false;
		return false;
	}
	this.hide2=function(){
		if(this.ready && this.visible) this.hide();
	}
	this.showhide=function(){
		if(this.visible) this.hide();
		else this.show();
	}
	this.init=function(holderId,txtId){
		this.holder=gel(holderId);
		this.txt=gel(txtId);
		this.ready=true;
	}
}
function HomeManager(){
	this.cfg=null;
	this.f=null;
	this.ftxt=null;
	this.mholder=null;
	this.rholder=null;
	this.mdup=null;
	this.rdup=null;
	this.evtmanager={};
	this.cfgref={};
	this.init=function(f_id,scfg){
		this.f=gel(f_id);
		this.ftxt=gel(f_id+"txt");
		this.initCfg(scfg);
		this.ftxt.value=scfg;
		this.initModules();
	}
	this.initCfg=function(scfg){
		//alert(scfg);
		this.cfg=_s2o.unserialize(scfg);
		//alert(debugObj(this.cfg));
	}
	this.initModules=function(){
		if(this.mholder=gel("mpanel")){
			var voids=[];
			var count=0;
			for(var i=0;i<this.mholder.childNodes.length;i++){
				var c=this.mholder.childNodes[i];
				if(c.nodeType==3) voids.push(c);
				else if(c.id.substr(0,3)=="box"){c.style.width="100%";this.setDraggable(c.id);this.initEventResponder(c);this.cfgref[c.id]="main_"+count;count++}
			}
			for(var i=0;i<voids.length;i++) this.mholder.removeChild(voids[i]);
		}
		if(this.rholder=gel("rpanel")){
			var voids=[];
			var count=0;
			for(var i=0;i<this.rholder.childNodes.length;i++){
				var c=this.rholder.childNodes[i];
				if(c.nodeType==3) voids.push(c);
				else{
					if(c.id.substr(0,3)=="box"){c.style.width="100%";this.setDraggable(c.id);this.initEventResponder(c);this.cfgref[c.id]="right_"+count;count++}
				}
			}
			for(var i=0;i<voids.length;i++) this.rholder.removeChild(voids[i]);
		}
	}
	this.moveModule=function(e,dragger){
		var srcEle = null;
		if(window.event) srcEle = window.event.srcElement;
		else if(e) srcEle = e.target;
		if(srcEle.tagName && (srcEle.tagName == "A"||srcEle.tagName == "SPAN")) return false;
		var mod=gel(dragger.id.split("_")[0]);
		if(mod.id.substr(3,1)=="m") this.onPanelStartMove("main");
		else this.onPanelStartMove("right");
		this.dup=this.duplicate(mod);this.cmod=mod;
		document.onmousemove=this.onDocMouseMove;
		document.onmouseup=this.onDocMouseUp;
	}
	this.overModule=function(e,box){
		if(t=gel(box.id+'_tbl')){
			t.className='ctbl_ov';
		}
	}
	this.outModule=function(e,box){
		if(t=gel(box.id+'_tbl')){
			t.className='ctbl';
		}
	}
	this.onDocMouseMove=function(e){
		var ev=window.event?window.event:e;
		_mngr.doMove(ev);
	}
	this.onDocMouseUp=function(e){
		var ev=window.event?window.event:e;
		_mngr.doMouseUp(ev);
	}
	this.onPanelStartMove=function(ptype){
		enableTextSelection(false);
		for(var ref in this.cfg[ptype]){
			if(this.cfg[ptype][ref]["t"]=="ad"){var adcontent=gel("boxcontentr"+ref);this.save_ad=adcontent.innerHTML;adcontent.innerHTML="<div style=\"height:250px\"></div>"};
		}
	}
	this.onPanelEndMove=function(ptype){
		enableTextSelection(true);
		for(var ref in this.cfg[ptype]){
			if(this.cfg[ptype][ref]["t"]=="ad"){var adcontent=gel("boxcontentr"+ref);adcontent.innerHTML=this.save_ad};
		}
		this.makeNewCfg();
		this.setNewCfgAsync();
	}
	this.doMove=function(ev){
		if(this.dup){
			var ws=getwinsize();var ys=0;var t=(ws.sy+ev.clientY - 10);
			if(t>ws.sy+ws.h-150) ys=10;else if(t<ws.sy+50) ys=-10;
			if(ys) window.scrollBy(0,ys);
			this.dup.style.top=(t+ys)+"px";
			this.organize();
		}
	}
	this.doMouseUp=function(ev){
		document.onmousemove=null;
		document.onmouseup=null;
		if(this.dup){this.dup.style.display="none";this.cholder.replaceChild(this.cmod,this.cplace);}
		if(this.cmod){
			if(this.cmod.id.substr(3,1)=="m") this.onPanelEndMove("main");
			else this.onPanelEndMove("right");
		}
	}
	this.isBox=function(mod){
		return (mod.id.substr(0,3)=="box");
	}
	this.getBoxes=function(){
		var mods=[];
		for(var i=0;i<this.cholder.childNodes.length;i++){var c=this.cholder.childNodes[i];if(this.isBox(c))mods.push(c);else if(c==this.cplace) mods.push(c);}
		if(this.cholder==this.rholder){
			mods=mods.slice(2);
		}
		return mods;
	}
	this.organize=function(){
		var dist=-1;
		var nearest=null;
		var debug="";
		var mods=this.getBoxes();
		for(var i=0;i<mods.length;i++){
			var pos=getPos(mods[i]);
			var dpos=getPos(this.dup);
			debug+=mods[i].id+": "+Math.abs(dpos.y - pos.y)+" ";
			if(dist==-1){nearest=mods[i];dist=Math.abs(dpos.y - pos.y)}else if(Math.abs(dpos.y - pos.y)<dist){nearest=mods[i];dist=Math.abs(dpos.y - pos.y)};
		}
		if(nearest){
			if(nearest==mods[mods.length-1]){
				this.cholder.insertBefore(this.cplace,nearest.nextSibling);
			}
			else{
				if(this.cplace==nearest.nextSibling) this.cholder.insertBefore(this.cplace,nearest);
				else this.cholder.insertBefore(nearest,this.cplace);
			}
		}
	}
	this.duplicate=function(mod){
		this.cholder=(mod.id.substr(3,1)=="m"?this.mholder:this.rholder);
		if(this.cholder==this.mholder){
			if(!this.mdup){this.mdup=document.createElement("div");this.mdup.style.position="absolute";this.mdup.style.zIndex=1000;this.mholder.appendChild(this.mdup);}
			var pos=getPos(mod);var md=this.mdup;
			md.style.left=pos.x+"px";md.style.top=pos.y+"px";md.className=mod.className;md.style.width=mod.offsetWidth+"px";md.style.display="block";md.style.opacity=.5;md.style.filter="alpha(opacity=50)";md.innerHTML=mod.innerHTML;
			if(!this.mplace){this.mplace=document.createElement("div");this.mplace.setAttribute("id","mplace");this.mplace.style.border="2px solid #808080";this.mplace.style.marginBottom="10px";}
			var mp=this.mplace;
			mp.style.width=(mod.offsetWidth-4)+"px";mp.style.height=(mod.offsetHeight-4)+"px";
			this.mholder.replaceChild(mp,mod);
			this.cplace=this.mplace;
			return this.mdup;
		}
		if(this.cholder==this.rholder){
			if(!this.rdup){this.rdup=document.createElement("div");this.rdup.style.position="absolute";this.rdup.style.zIndex=1000;this.rholder.appendChild(this.rdup);}
			var pos=getPos(mod);var rd=this.rdup;
			rd.style.left=pos.x+"px";rd.style.top=pos.y+"px";rd.className=mod.className;rd.style.width=mod.offsetWidth+"px";rd.style.display="block";rd.style.opacity=.5;rd.style.filter="alpha(opacity=50)";rd.innerHTML=mod.innerHTML;
			if(!this.rplace){this.rplace=document.createElement("div");this.rplace.setAttribute("id","rplace");this.rplace.style.border="2px solid #808080";this.rplace.style.marginBottom="10px";}
			var rp=this.rplace;
			rp.style.width=(mod.offsetWidth-4)+"px";rp.style.height=(mod.offsetHeight-4)+"px";
			this.rholder.replaceChild(rp,mod);
			this.cplace=this.rplace;
			return this.rdup;
		}
	}
	this.setDraggable=function(mod_id){
		if(d=gel(mod_id+"_drag")){
			d.onmousedown=function(e){_mngr.moveModule(e,this)};
		}
		if(b=gel(mod_id)){
			b.onmouseover=function(e){_mngr.overModule(e,this)};
			b.onmouseout=function(e){_mngr.outModule(e,this)};
		}
	}
	this.initEventResponder=function(mod){
		this.evtmanager[mod.id]={onExpand:function(){},onCollapse:function(){}};
	}
	this.addBoxEvent=function(mod_id,eventName,fn){
		this.evtmanager[mod_id][eventName]=fn;
	}
	this.setBoxBehavior=function(mod_id,btype,o){
		if(btype=="spy"){
			this.addBoxEvent(mod_id,'onCollapse',function(){o.spyPlay(false)});
			this.addBoxEvent(mod_id,'onExpand',function(){o.spyPlay(true)});
		}
	}
	this.setNewCfg=function(){
		try{
			var scfg=_o2s.serialize(this.cfg);
			this.ftxt.value=scfg;
			this.f.submit();
		}
		catch(e){}
	}
	this.setNewCfgAsync=function(){
		try{
			//alert(debugObj(this.cfg));
			var scfg=_o2s.serialize(this.cfg);var d=new Date();var aj=new ajax();
			aj.call("homecfg.ajax.php?scfg="+scfg+"&mk="+d.getTime());
		}
		catch(e){}
	}
	this.makeNewCfg=function(){
		var ncfg={};ncfg["main"]=[];ncfg["right"]=[];
		var nref={};var count=0;
		for(var i=0;i<this.mholder.childNodes.length;i++){var c=this.mholder.childNodes[i];if(this.isBox(c)){var cref=this.cfgref[c.id].split("_");ncfg["main"].push(this.cfg[cref[0]][cref[1]]);nref[c.id]="main_"+count;count++}}
		var count=0;
		for(var i=0;i<this.rholder.childNodes.length;i++){var c=this.rholder.childNodes[i];if(this.isBox(c)){var cref=this.cfgref[c.id].split("_");ncfg["right"].push(this.cfg[cref[0]][cref[1]]);nref[c.id]="right_"+count;count++}}
		this.cfg=ncfg;
		this.cfgref=nref;
	}
	this.saveModule=function(mod_id){
		var cref=this.cfgref["box"+mod_id].split("_");
		if(mobj=this.cfg[cref[0]][cref[1]]){
			var mf =gel("form_"+mod_id);var mtype=mobj["t"];
			switch(mtype){
				case "charts": mobj["n"]=mf.nb.value; mobj["r"]=mf.type.value; mobj["p"]=mf.period.value; break;
				case "news": mobj["n"]=mf.nb.value; mobj["r"]=mf.type.value; break;
			}
			this.cfg[cref[0]][cref[1]]=mobj;
			this.setNewCfg();
		}
	}
	this.switchModuleState=function(mod_id,x){
		var cref=this.cfgref["box"+mod_id].split("_");
		if(mobj=this.cfg[cref[0]][cref[1]]){mobj["x"]=x;this.cfg[cref[0]][cref[1]]=mobj;this.setNewCfgAsync();}
		if(x=="x") this.evtmanager["box"+mod_id].onExpand();
		else if(x=="c") this.evtmanager["box"+mod_id].onCollapse();
	}
	this.getSize=function(panel){
		var s=0;for(var ref in this.cfg[panel]) s++;return s;
	}
	this.addModule=function(panel,t,s){
		var mod={t:t,x:"x","n":4};
		switch(t){
			case "charts": mod["r"]="c"; mod["s"]=s; break;
			case "news": mod["r"]="c"; mod["s"]=s; mod["p"]="wk"; break;
			case "rss": mod["u"]=s;break;
			case "live": mod["n"]=3;break;
			case "tod": mod["n"]=3;break;
		}
		var ncfg=[];ncfg[0]=mod;for(var ref in this.cfg[panel]) ncfg.push(this.cfg[panel][ref]);this.cfg[panel]=ncfg;this.setNewCfg();
	}
	this.addModuleEx=function(panel,t,s){
		if(!this.checkModuleEx(panel,t,s)) this.addModule(panel,t,s);else this.addModuleError("exclusive");
	}
	this.addModuleError=function(t){
		switch(t){
			case "exclusive": alert(_localizer.tr('customizer/errormoduleexclusive'));break;
			case "rss": alert("Choisissez l'un des fils RSS proposés ou entrez son adresse pour l'ajouter.");break;
		}
		return false;
	}
	this.checkModuleEx=function(panel,t,s){
		var is_in=false;	for(var ref in this.cfg[panel]){if(this.cfg[panel][ref]["t"]==t) is_in=true;}return is_in;
	}
	this.removeModule=function(mod_id){
		//alert(debugObj(this.cfg));
		var cref=this.cfgref["box"+mod_id].split("_");
		this.cfg["deleted"]=this.cfg[cref[0]][cref[1]]["t"];
		var ncfg=[];
		for(var ref in this.cfg[cref[0]]){if(ref!=cref[1]) ncfg.push(this.cfg[cref[0]][ref]);}
		this.cfg[cref[0]]=ncfg;
		this.setNewCfg();
		//holder.removeChild(gel("box"+mod_id));
	}
}
function openControls(holderId,txtId){
	if(!_controls.ready) _controls.init(holderId,txtId);
	_controls.showhide();
	return false;
}
function openLogin(holderId,txtId){
	if(!_login.ready) _login.init(holderId,txtId);
	_login.showhide();
	return false;
}
function boxdel(count){
	var msg=_localizer.tr('customizer/confirmdelmodule');
	if(t=gel("box"+count+"title")){msg=_localizer.tr('customizer/confirmdelthismodule', "\""+gtxt("box"+count+"title")+"\"");}
	if(confirm(msg)){_mngr.removeModule(count);}
	return false;
}
function boxedit(count){
	if(c=gel("box"+count+"_form")){
		if(c.style.display && c.style.display=="block") c.style.display="none";
		else c.style.display="block";
	}
	return false;
}
function boxclex(count){
	var c=gel("boxcontent"+count);
	var ed=gel("boxedit"+count);
	if(i=gel("iboxclex"+count)){
		if(i.src.indexOf("clps") > -1){
			i.src=i.src.replace("clps","expd");
			_mngr.switchModuleState(count,"c");
			if(c) c.style.display="none";
			if(ed) ed.style.display="none";
		}
		else{
			i.src=i.src.replace("expd","clps");
			_mngr.switchModuleState(count,"x");
			if(c) c.style.display="block";
			if(ed) ed.style.display="inline";
		}
	}
	return false;
}
function homeLayoutInit(){
	var h=document.location.hash;
	if(h!=""){
		h=h.substr(1);
		if(h.indexOf("/")==0 && h!="/musique/" && h!="/"){
			document.location.replace(h);
		}
	}
}
var _mngr=new HomeManager();
var _controls=new Controls();
var _login = new Login();