window.onload=init;

var plopTrix=null;
function init() {
	
	Nifty("#yahoopath","transparent");
	Nifty("#header,#tags","transparent same-height");
	Nifty("div.bloc h2","transparent top");
	Nifty("div.warning","transparent");
	Nifty("#footer","transparent");
	Nifty("#global","transparent");
	Nifty("div.billet_bloc_bglight,div.billet_bloc_bgdark,div.comment_bglight,div.comment_bgdark,#souscategories li","transparent");
	
	plopTrix=new matrixBloc(initMatrix());
}

/* bloc déplacable */

function initMatrix()
{
	var mat=new Array();
	mat[0]=new Array();
	mat[0][0]=$('calendrier');
	mat[0][1]=$('search');
	mat[1]=new Array();
	mat[1][0]=$('categories');
	mat[1][1]=$('a_retenir');
	mat[2]=new Array();
	mat[2][0]=$('syndication');
	mat[2][1]=$('liens');
	return mat;
}


function matrixBloc(matrice) { 
	var currentY = 0;
	var currentObject= false;
	var decalageTopElement=0;
 	//** 
 	 
 	//**
 	for(var i=0;i<matrice.length;i++)
 	{
 		for(var j=0;j<matrice[i].length;j++)
 		{
 			var bloc=matrice[i][j];
			bloc.style['cursor']="move";
			bloc.style["position"]="relative";
			bloc.style["top"]="0px";
			bloc.setAttribute('rel',i+':'+j);
			bloc.onmousedown=function(e){
				var targ;
				e= e||window.event;
				if (e.target) targ = e.target;
				else if (e.srcElement) targ = e.srcElement;
				if (targ.nodeType == 3) // defeat Safari bug
					targ = targ.parentNode;
				var cible=this.getElementsByTagName('H2')[0];	
				if (targ!=cible) return false;
				currentObject=this;
				currentY = (window.ActiveXObject) ? (window.event.clientY + document.body.scrollTop)  : e.pageY ;
				decalageTopElement=(window.ActiveXObject) ? (window.event.offsetY)  : e.layerY ;
				document.onmousemove=onMouseMove;
				document.onmouseup=onMouseUp;
				FnD(currentObject);
				return false;
			}
 			
 		}
 	}
 	function onMouseMove(e) {
			var difY = (window.ActiveXObject) ? (window.event.clientY+document.body.scrollTop - getTop(currentObject)) : e.pageY-getTop(currentObject) ;
			var newY1 = parseInt(currentObject.style["top"])+parseInt(difY)-decalageTopElement;
			currentY = (window.ActiveXObject) ? (window.event.clientY + document.body.scrollTop)  : e.pageY ;

			var item = currentObject;
			var next = DragUtils.nextItem(item);
			while (next != null && currentObject.offsetTop >= next.offsetTop - 2) {
				var item = next;
				var next = DragUtils.nextItem(item);
			}
			if (currentObject != item) {
				DragUtils.swap(currentObject, next);
				return;
			}
			var item = currentObject;
			var previous = DragUtils.previousItem(item);
			while (previous != null && currentObject.offsetTop <= previous.offsetTop + 2) {
				var item = previous;
				var previous = DragUtils.previousItem(item);
			}
			if (currentObject != item) {
				DragUtils.swap(currentObject, item);
				return;
			}
			currentObject.style["top"]=newY1+"px";
		return false;
	}
	/**/
	function onMouseUp(e) {
		FnU(currentObject);
		currentObject.style["top"] = "0px";
		currentObject.style["left"] = "0px";
		document.onmousemove=null;
		document.onmouseup=null;
		toolbarsend();
		return false;
	}
	var FnD=function(objCourrant)
	{
		if (window.ActiveXObject) objCourrant.style["filter"]="alpha(opacity="+(50)+")";
		else objCourrant.style["opacity"]=(50/100);
		objCourrant.style["zIndex"]=10000;
		objCourrant.style['backgroundColor']="#fefefe";
		objCourrant.style['border']="1px dashed red";
	}
	var FnU=function(objCourrant)
	{
		if ((window.ActiveXObject)) objCourrant.style["filter"]="";
		else 	objCourrant.style["opacity"]="";
		objCourrant.style["zIndex"]="";
		objCourrant.style["backgroundColor"]="";
		objCourrant.style['border']="";


	}
	function toolbarsend()
	{
		var date=new Date();
		date.setFullYear(date.getFullYear()+10);
		var boxsleft=$$CN('bloc','DIV','barre_sommaire');
		var boxsright=$$CN('bloc','DIV','barre_lien');
		var leftvalue="";
		var rightvalue="";
		for(var i=0;i<boxsleft.length;i++) leftvalue+=boxsleft[i].getAttribute('id')+":";
		for(var i=0;i<boxsright.length;i++) rightvalue+=boxsright[i].getAttribute('id')+":";
		setCookie('toolbarleft',leftvalue,date);
		setCookie('toolbarright',rightvalue,date);
	}
}
