function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


function gaMMa_preloadImages(nlist) {
 var d=document; if (!d.gMMp) d.gMMp=new Array(); g=d.gMMp;
 eval('(g[g.length]=new Image()).src="' + nlist.replace(/,/g,'"; (g[g.length]=new Image()).src="') + '";');
}

function myX(me) {
 if (me.offsetX == null)
	me.offsetX=me.offsetParent?myX(me.offsetParent)+me.offsetLeft:0;
 return me.offsetX;
}

function myY(me) {
 if (me.offsetY == null)
 	me.offsetY=me.offsetParent?myY(me.offsetParent)+me.offsetTop:0;
 return me.offsetY;
}
          
var btnoffset=0;

function AdjustButtons() {
 if (!btnoffset) btnoffset=368;

 if (!(layer=document.getElementById('buttons'))) layer=document.layers['buttons'];

 var newPos=parseInt((document.all?document.body.clientWidth+16:window.innerWidth)/2)-btnoffset;
// alert(newPos);
 layer.style.left=newPos>=0?newPos:0;
 layer.style.visibility=(document.layers?'show':'visible');
}

function GetLayerObject(name) {
 var layer;
 if (document.getElementById)
	layer=document.getElementById(name);
 else if (document.layers)
	layer=document.layers[name];
 else if (document.all)
	layer=document.all[name];
 if (!layer.style) layer.style=layer;
 if (!layer.cliparea) {
		layer.cliparea={top:0, right:0, bottom:0, left:0};
		layer.cliparea.right=GetWidth(name); layer.cliparea.bottom=GetHeight(name);
		UpdateClipArea(name);
 }
 return layer;
}

function GetWindowWidth() { return (document.all?document.body.clientWidth:window.innerWidth); }

function GetWindowHeight() { return (document.all?document.body.clientHeight:window.innerHeight); }

function GetHeight(name) {
 var layer=GetLayerObject(name);
 return document.layers?layer.document.height:layer.offsetHeight;
}

function GetWidth(name) {
 var layer=GetLayerObject(name);
 return document.layers?layer.document.height:layer.offsetHeight;
}

function UpdateClipArea(name) {
 var layer=GetLayerObject(name);

 if (document.layers) // 100% Optimized for Netscape & Mozilla !!
	with (layer) { clip.left=cliparea.left; clip.top=cliparea.top; clip.right=cliparea.right; clip.bottom=cliparea.bottom; } 
 else	// OK for MSIE & DOM
	with (layer.cliparea) layer.style.clip="rect(" + top + "px " + right + "px " + bottom + "px " + left + "px)";
}

function SetClipArea(name,x1,y1,x2,y2) {

 var layer=GetLayerObject(name);

 if (document.all) var undefined; // ..para la mierda del Explorer, que no reconoce "undefined"

 if (x1===undefined) x1=0;
 if (y1===undefined) y1=0;
 if (x2===undefined) x2=GetWidth(name);
 if (y2===undefined) y2=GetHeight(name);
  
 with (layer.cliparea) { left=x1; top=y1; right=x2; bottom=y2; }
//  with(layer.cliparea) alert(left+','+top+','+right+','+bottom);
 UpdateClipArea(name);
}

function IncreaseClipBorder(name,prop,delta,NoUpdate) {
 var layer=GetLayerObject(name);
 layer.cliparea[prop]+=delta;
 if (!NoUpdate) UpdateClipArea(name);
}

function SetClipBorder(name,prop,delta,NoUpdate) { 
 var layer=GetLayerObject(name);
 layer.cliparea[prop]=delta;
 if (!NoUpdate) UpdateClipArea(name);
}

function getWindowWidth() { return document.all?document.body.clientWidth:window.innerWidth; }

function getWindowHeight() { return document.all?document.body.clientHeight:window.innerHeight; }

var MAINPOS_X, MAINPOS_Y;
function AdjustMain(name, btnoffset, btnoffsetY) {
 if (!btnoffset) btnoffset=368;

 var layer=GetLayerObject(name);

 var newPos=parseInt( (getWindowWidth()-btnoffset)/2);
 var newPosY=parseInt( (getWindowHeight()-btnoffsetY)/2)+16;
 layer.style.left=MAINPOS_X=newPos>=0?newPos:0;
 layer.style.top=MAINPOS_Y=newPosY>=0?newPosY:0;
 layer.style.visibility=(document.layers?'show':'visible');
}

function SetLayerYPos(name,pos) {
 var layer=GetLayerObject(name);
 layer.style.top=pos;
}

function MoveDown(name,top) {
 if (!top) top=GetWindowHeight()-36;
 var layer=GetLayerObject(name);
 var current=parseInt(layer.style.top);
 if (current<top) {
	if (current+10>top) current=top-10;
	layer.moving='down';
	layer.style.top=current+10;
	IncreaseClipBorder(name,'bottom',-10);
	layer.movingTimer=setTimeout('MoveDown("'+name+'",'+top+')',2);
	return true;
 }
 layer.moving='none';
 return false;
}

function MoveUp(name,top) {
 var layer=GetLayerObject(name);
 if (!top) top=GetWindowHeight()-GetHeight(name)-30;
 var current=parseInt(layer.style.top);
 if (layer.movingTimer) clearTimeout(layer.movingTimer);
 if (current>top) {
	if (current-20<top) current=top+20;
	layer.style.top=current-20;
	IncreaseClipBorder(name,'bottom',20);
	layer.movingTimer=setTimeout('MoveUp("'+name+'",'+top+')',1);
	return true;
 }
 layer.movingTimer=setTimeout('MoveDown("'+name+'",GetWindowHeight()-36)',9000);
 return false;
}

function StartAnimations() {
 SetLayerYPos('noticiasdiv',GetWindowHeight()-36);
 SetLayerYPos('avisosdiv',GetWindowHeight()-36);
 SetClipArea('noticiasdiv',0,0,300,36);
 SetClipArea('avisosdiv',0,0,300,36);
 setTimeout("MoveUp('avisosdiv')",1500);
 setTimeout("MoveUp('noticiasdiv')",5000);
}
