var nav = (navigator.appName == "Microsoft Internet Explorer") ? "ie" : "ns";
if(document.layers){origWidth=innerWidth;origHeight=innerHeight;onresize=function(){if(innerWidth!=origWidth||innerHeight!=origHeight)location.reload();}}

var listo=false;
var temps;
var limitesuptexto = 0;
var limiteinftexto = 200;
var limitesupscroll = 16;
var limiteinfscroll = 241;
var longdelscroll = limiteinfscroll - limitesupscroll;
var brusquedad = 1;
var num=0;
var brusq_salto = 20;
var lentitud = 20;
Netscape = (navigator.appName == "Netscape") ? true:false
Macintosh = (navigator.appVersion.indexOf("Macintosh",1) != -1) ? true:false

function scrollup()
{
if (listo) {
	if (nav=="ie") {
		if (texto.style.pixelTop < limitesuptexto) texto.style.pixelTop += brusquedad;
			num += brusquedad * longdelscroll / (texto.scrollHeight-205);
			if (num >= 1) {
				dragitem.ypos -= parseInt(num);
				num -= parseInt(num);
			}
			if (dragitem.ypos < limitesupscroll) dragitem.ypos = limitesupscroll;   
			else if (dragitem.ypos > limiteinfscroll) dragitem.ypos = limiteinfscroll;
			dragitem.pixelTop = dragitem.ypos;
			anty=dragitem.ypos
	}
	else {
		if (document.ventana.document.texto.top < limitesuptexto) document.ventana.document.texto.top += brusquedad;
		num += brusquedad * longdelscroll / (document.ventana.document.texto.document.height-205);
		if (num >= 1) {
			dragitem.ypos -= parseInt(num);
			num -= parseInt(num);
		}
		if (dragitem.ypos < limitesupscroll) dragitem.ypos = limitesupscroll;  
		else if (dragitem.ypos > limiteinfscroll) dragitem.ypos = limiteinfscroll;
		dragitem.top = dragitem.ypos;
		anty=dragitem.ypos
	}
	temps=setTimeout('scrollup()',lentitud);
}
}

function scrolldown()
{
if (listo) {
	if (nav=="ie") {
		if (texto.style.pixelTop > limiteinftexto-texto.scrollHeight) texto.style.pixelTop -= brusquedad;
			num += brusquedad * longdelscroll / (texto.scrollHeight-205);
			if (num >= 1) {
				dragitem.ypos += parseInt(num);
				num -= parseInt(num);
			}
			if (dragitem.ypos < limitesupscroll) dragitem.ypos = limitesupscroll; 
			else if (dragitem.ypos > limiteinfscroll) dragitem.ypos = limiteinfscroll;
			dragitem.pixelTop = dragitem.ypos;
			anty=dragitem.ypos
	}
	else {
		if (document.ventana.document.texto.top > -document.ventana.document.texto.document.height+limiteinftexto) document.ventana.document.texto.top -= brusquedad;
			num += brusquedad * longdelscroll / (document.ventana.document.texto.document.height-205);
			if (num >= 1) {
				dragitem.ypos += parseInt(num);
				num -= parseInt(num);
			}
			if (dragitem.ypos < limitesupscroll) dragitem.ypos = limitesupscroll;
			else if (dragitem.ypos > limiteinfscroll) dragitem.ypos = limiteinfscroll;
			dragitem.top = dragitem.ypos;
			anty=dragitem.ypos
	}
	temps=setTimeout('scrolldown()',lentitud);
}
}

function inidragndrop() {
	if (nav=="ns") {
		dragitem = document.dragcss;
		dragitem.xpos = dragitem.left;
		dragitem.ypos = dragitem.top;

	}
	else {
		dragitem = document.all.dragcss.style;
		dragitem.xpos = dragitem.pixelLeft;
		dragitem.ypos = dragitem.pixelTop;
	}
	dragndrop = false
	document.onmousedown = seleccion
	document.onmousemove = drag
	document.onmouseup = drop
	if (nav=="ns") document.captureEvents( Event.MOUSEMOVE| Event.MOUSEUP)// Event.MOUSEDOWN |
}





function moveDragcss()
{
	if (nav=="ns") 
	{
		dragitemy = 45-dragitem.ypos
		anty = dragitem.ypos
		dragndrop = true
		return false				
		if (x>=dragitem.left && x<=dragitem.left+dragitem.clip.width && y>=dragitem.top+dragitem.clip.height && y<=limiteinfscroll-2) 
		{
			for(i=0;i<brusq_salto;i++) { scrolldown(); clearTimeout(temps); }
			return false
		}
		else if (x>=dragitem.left && x<=dragitem.left+dragitem.clip.width && y>=limitesupscroll+2 && y<=dragitem.top) 
		{
			for(i=0;i<brusq_salto;i++) { scrollup(); clearTimeout(temps); }
			return false
		}
		else routeEvent(e);
	}
}




function seleccion(e) {
		if (nav=="ns") {
			var x=e.pageX; var y=e.pageY
			if (x>=dragitem.left && x<=dragitem.left+dragitem.clip.width && y>=dragitem.top && y<=dragitem.top+dragitem.clip.height) {
				dragitemy = y-dragitem.ypos
				anty = dragitem.ypos
				dragndrop = true
				return false				
			}
			else if (x>=dragitem.left && x<=dragitem.left+dragitem.clip.width && y>=dragitem.top+dragitem.clip.height && y<=limiteinfscroll-2) {
				for(i=0;i<brusq_salto;i++) { scrolldown(); clearTimeout(temps); }
				return false
			}
			else if (x>=dragitem.left && x<=dragitem.left+dragitem.clip.width && y>=limitesupscroll+2 && y<=dragitem.top) {
				for(i=0;i<brusq_salto;i++) { scrollup(); clearTimeout(temps); }
				return false
			}
			else routeEvent(e);
		}
		else {
			var x=event.x; var y=event.y
			if (x>=dragitem.pixelLeft && x<=dragitem.pixelLeft+dragitem.pixelWidth && y>=dragitem.pixelTop && y<=dragitem.pixelTop+dragitem.pixelHeight) {
				dragitemy = y-dragitem.ypos
				anty = dragitem.ypos
				dragndrop = true
				return false				
			}
			else if (x>=dragitem.pixelLeft && x<=dragitem.pixelLeft+dragitem.pixelWidth && y>=dragitem.pixelTop+dragitem.pixelHeight && y<=limiteinfscroll-2) {
				for(i=0;i<brusq_salto;i++) { scrolldown(); clearTimeout(temps); }
				return false
			}
			else if (x>=dragitem.pixelLeft && x<=dragitem.pixelLeft+dragitem.pixelWidth && y>=limitesupscroll+2 && y<=dragitem.pixelTop) {
				for(i=0;i<brusq_salto;i++) { scrollup(); clearTimeout(temps); }
				return false
			}
		}
return false;
}

function drag(e) {

	if (nav=="ns") {
		var x=e.pageX; var y=e.pageY
		if (dragndrop) {
			if (y < limitesupscroll || y-dragitemy < limitesupscroll) dragitem.ypos = limitesupscroll;             // Limites del scroller
			else if (y > limiteinfscroll+10 || y-dragitemy > limiteinfscroll) dragitem.ypos = limiteinfscroll;
			else dragitem.ypos = y-dragitemy
			dragitem.top = dragitem.ypos;
			if (dragitem.ypos == limitesupscroll) document.ventana.document.texto.top = 2;
			else if (dragitem.ypos == limiteinfscroll) document.ventana.document.texto.top = -document.ventana.document.texto.document.height+limiteinftexto-10;
			else {
				suma = (anty-dragitem.ypos)*(document.ventana.document.texto.document.height-limiteinftexto+10)/longdelscroll;
				if (suma<0 && suma>-1) suma = -1;
				if (suma>0 && suma<1) suma = 1;
				suma = parseInt(suma);
				document.ventana.document.texto.top += suma;
			}
			anty=dragitem.ypos
			return false
		}
	}
	else {
		var x=event.x; var y=event.y
		if (dragndrop) {
			if (y < limitesupscroll || y-dragitemy < limitesupscroll) dragitem.ypos = limitesupscroll;
			else if (y > limiteinfscroll+10 || y-dragitemy > limiteinfscroll) dragitem.ypos = limiteinfscroll;
			else dragitem.ypos = y-dragitemy
			dragitem.pixelTop = dragitem.ypos;
			if (dragitem.ypos == limitesupscroll) texto.style.pixelTop = 2;
			else if (dragitem.ypos == limiteinfscroll) texto.style.pixelTop = -texto.scrollHeight+limiteinftexto-10;
			else texto.style.pixelTop += parseInt((anty-dragitem.ypos)*(texto.scrollHeight-limiteinftexto+10)/longdelscroll);
			anty=dragitem.ypos
			return false
		}
	}
}

function drop(e) 
{  

	if (dragndrop)
	{
		if (nav=="ns") 
			{
				var x=e.pageX; 
				var y=e.pageY
			}
		else 
			{
				var x=event.x; 
				var y=event.y+document.body.scrollTop
			}
		dragndrop = false
	}
	if (nav=="ns") routeEvent(e);
}
function canvi(capa,antic,nou)
{ 
if (listo) {
	if (nav=='ie') {
		eval(antic+".src = "+nou+".src;");
	}
	else {
		eval("document."+capa+".document."+antic+".src = "+nou+".src;");
	}
}
}


