// JavaScript Document


/**********************Drag and Drop**************************/
var isIE_=document.all;
var isNN_=!document.all && document.getElementById;
var isN4_=document.layers;
var isHot_=false;
var whichDog=0;
var zindex_max=3;
var offsetx=0;
var offsety=0;

function ddInit(e)
{
	ddEnabled=true;
	topDog=isIE_ ? "BODY" : "HTML";
	//whichDog=isIE_ ? document.all.nombrediv : document.getElementById('nombrediv')
	whichDog=CapaMover;
	hotDog=isIE_ ? event.srcElement : e.target;  
	
	// ----- Control para saber q capa movemos
	if(hotDog.id.indexOf('-')>-1)
	{
		elemento_title=new Array();
		elemento_title=hotDog.id.split('-');
		whichDog=document.getElementById(elemento_title[1]);
		whichDog.style.zIndex=zindex_max+1;
		zindex_max=zindex_max+1;
	} else
	if(hotDog.id.indexOf('titleBar')==-1)
	{	
		//while ((hotDog.id!="titleBar") && (hotDog.tagName!=topDog))
			//hotDog=isIE_ ? hotDog.parentElement : hotDog.parentNode;
	}  

	if (hotDog.id.indexOf('titleBar')>-1)
	{
		offsetx=isIE_ ? event.clientX : e.clientX;
		offsety=isIE_ ? event.clientY : e.clientY;
		nowX=parseInt(whichDog.style.left);
		nowY=parseInt(whichDog.style.top);
		ddEnabled=true;
		document.onmousemove=dd;
	}
	
}

function dd(e)
{
	if (!ddEnabled) 
		return;

	whichDog.style.left=isIE_ ? (nowX+event.clientX-offsetx)+'px' : (nowX+e.clientX-offsetx)+'px'; 
	whichDog.style.top=isIE_ ? (nowY+event.clientY-offsety)+'px' : (nowY+e.clientY-offsety)+'px';

	// Fondo de la capa
	if(CapaMoverFondo!=0)
	{
		CapaMoverFondo.style.left=(isIE_ ? nowX+event.clientX-offsetx : nowX+e.clientX-offsetx);
		CapaMoverFondo.style.top=(isIE_ ? nowY+event.clientY-offsety : nowY+e.clientY-offsety);
	}
	
	return true;  
}

function ddN4(whatDog)
{
	if (!isN4_) 
		return;
	N4=eval(whatDog);
	N4.captureEvents(Event.MOUSEDOWN|Event.MOUSEUP);

	N4.onmousedown=function(e)
	{
		N4.captureEvents(Event.MOUSEMOVE);
		N4x=e.x;
		N4y=e.y;
	}
	
	N4.onmousemove=function(e)
	{
		alert('N4');
		if (isHot_)
		{
		  N4.moveBy(e.x-N4x,e.y-N4y);
		  return false;
		}
	}
	
	N4.onmouseup=function()
	{
		N4.releaseEvents(Event.MOUSEMOVE);
	}
}

// Para mover las capas
document.onmousedown=ddInit;
document.onmouseup=function()
{
	ddEnabled=false;
	guardar_posicion();
}
