// JavaScript Document

var domok = document.getElementById;
var bool = false;

var x;
var y;

var mDown = false;
var mResize = false;


function init(){
if (domok)
	{
	  
		skn = document.getElementById("topdecklink").style;
		
		//x =  document.getElementById("id-body").clientWidth - (document.getElementById("id-body").clientWidth  / 2) ;
		x = ( document.getElementById("global").clientWidth - 930 ) / 2 
		x = parseInt(x + 50)  + 'px';
		
		
			
		y = '50px';
		
		//alert(x);
		
		skn.left = x;
		skn.top  = y;	
		
		if(!document.all)document.captureEvents(Event.MOUSEMOVE | Event.MOUSEDOWN | Event.MOUSEUP);
		document.onmousedown=handleMouseDownEvents;
		document.onmousemove=handleMouseMoveEvents
		document.onmouseup=handleMouseUpEvents;
	}
}

function poplink(jpg)
   {	
   
       if (domok)
       {
		   //content="<img src="+jpg+" class='photo_produit' border='0' >";
		   
/*
		content = '<div id="detail" ><div style="padding:2px; border-bottom:#BFBFBF 2px solid; border-left:#BFBFBF 2px solid; width:530px; background-color:#FFFFFF">\n';
		   content = content + '<div onSelect="return false" onmousedown="windowTitleMouseDown(event);" id="windowTitle" style="cursor:move; background:url(images/produits/icone_deplacer.gif); background-position:center; background-repeat:no-repeat; background-color:#B20027;  height:19px; width:20px; float:left;" >&nbsp;</div>\n';
		   content = content + '<div style="height:19px; width:20px; background-color:#BFBFBF; float:left"><a href="#" onclick=" killlink()"><img src="images/produits/icone_fermer.gif" width="22" height="19" border="0" /></a></div>\n';
		   content = content + '<br /><div style="border:#B20027 2px solid; padding:13px; text-align:center"><img src="' + jpg + '" class="photo_produit" border="0" ><br />\n';
		   content = content + '<br /></div></div></div>\n';
*/

		content = '<div id="detail" >';
		content = content + '<table width="500" border="0" cellspacing="0" cellpadding="0" style="background-color:#ffffff"><tr><td  style="border:#3452AC 2px solid; text-align:center">\n';	
		content = content + '<div onSelect="return false" onmousedown="windowTitleMouseDown(event);" id="windowTitle" style="cursor:move; background:url(images/produits/icone_deplacer.gif); background-position:center; background-repeat:no-repeat; background-color:#243EA2;  height:19px; width:20px; float:left;" >&nbsp;</div>\n';	
		content = content + '<div style="height:19px; width:20px; background-color:#BFBFBF; float:left"><a href="#" onclick=" killlink()"><img src="images/produits/icone_fermer.gif" width="22" height="19" border="0" /></a></div>';
		content = content + '<a href="#" onclick=" killlink()"><img src="' + jpg + '" class="photo_produit" border="0"  hspace="5" vspace="5" style="padding:5px;"></a></td></tr></table>\n';	
		content = content + '</div>\n';
		
		
		   
           // Rajoute le contenu hérité		   
           document.getElementById("topdecklink").innerHTML = content;
		   skn.visibility = "visible";		   
       }
   }

//Event TITLE



function windowTitleMouseDown(e) {
	//alert('Down');
	
	mDown=true;
	captureOffsetXY(e);
}

//EVENT handle

function handleMouseUpEvents() {
	if(mDown) {
		mDown=false;
		return;
	}
}

function handleMouseMoveEvents(e) {
	
	if(mDown) {
		//alert("toto");
		initDrag(e);
		return;
	}
}

function handleMouseDownEvents(e) {
	if(mResize) {
		document.body.style.cursor = "nw-resize";
	}
}
//

function markCoordinates() {
	originalLeft  = parseInt(document.getElementById("detail").style.left);
	originalTop = parseInt(document.getElementById("detail").style.top);
}

function initDrag(e) {
	//alert("toto");
	if(!mDown)return;
	
	
	
	if(document.all) {
		x2 = (window.event.clientX - document.getElementById("global").offsetLeft)-(x+5);
		y2 = (window.event.clientY - document.getElementById("global").offsetTop)-(y+5);
	} else {
		x2 = (e.clientX - document.getElementById("global").offsetLeft) - (x+5);
		y2 = (e.clientY - document.getElementById("global").offsetTop) - (y+5);
	}
	document.getElementById("topdecklink").style.top = y2 + "px";
	document.getElementById("topdecklink").style.left = x2 + "px";
	originalLeft  = x2;
	originalTop = y2;
}

function captureOffsetXY(e) {
	if(document.all) {
		x=window.event.offsetX;
		y=window.event.offsetY
	} else {
		x = e.pageX - e.clientX;
		y = e.pageY - e.clientY;
	}
}

function captureClientXY(e) {
	if(document.all) {
		x = window.event.clientX;
		y = window.event.clientY;
	} else {
		x = e.clientX;
		y = e.clientY;
	}
}


function killlink()
{
   if (domok) skn.visibility = "hidden";
}

window.onload = function() {	
	/*init();	
	disable();*/
};