// funciones javascript para menu

var actual=-1;
var oact,cal;

var NS4,NS6,IE4,IE5,vis,invis
var c_altura,c_cont,c_pos,c_desp,c_velo,funciona_scroll

  NS4 = (document.layers) ? true : false;
  IE4 = (document.all && !document.getElementById) ? true : false;
  IE5 = (document.all && document.getElementById) ? true : false;
  NS6 = (!document.all && document.getElementById) ? true : false;

if(NS4){vis="shown";invis="hide";}else{vis="visible";invis="hidden";}

document.onmousedown=click;
if (NS6){document.addEventListener("mouseup",alerta,false);}

//function alerta(e){
//if (e.which == 3) {alert("Novaindes");return false;}
//}

//function click(e) {
  //NS4 = (document.layers) ? true : false;
  //if (NS4) {if (e.which == 3) {alert("Novaindes");return false;}} else {if(NS6){}else{if (event.button == 2) {alert("Novaindes");return false;}}}
//}

function scroll(dir){   //  dir==0 --> flecha arriba, osea, bajar la capa
 if(funciona_scroll){
  if(IE4){capa=document.all.contenedor;}else{capa=document.getElementById("contenedor");}
  if((dir&&(c_pos<c_cont))||(!dir&&(c_pos>0))){
   if(c_velo==1 || (c_velo>1 && ((dir&&(c_pos<c_cont-(c_velo-1)))||(!dir&&(c_pos>(c_velo-1)))))){
     if(dir){prox=c_pos+c_velo;}else{prox=(c_pos-c_velo);}
     c_pos=prox;     
     capa.style.clip="rect("+String((c_pos*c_desp))+" 492 "+String(250+(c_pos*c_desp))+" 0)";
     capa.style.top=65-(c_pos*c_desp);
   }
  }   
  setTimeout("scroll("+dir+")",100);
 }
}

function inicia_scroll(){
  funciona_scroll=0;
  if(IE4){capa=document.all.contenedor;capa2=document.all.cargando;}else{capa=document.getElementById("contenedor");capa2=document.getElementById("cargando");}
  c_desp=10;
  c_velo=1;
  c_altura=capa.offsetHeight;
  if(c_altura>250){
   if(IE4){document.all.elscroll.style.visibility="visible";}else{document.getElementById("elscroll").style.visibility="visible";}
   c_cont=(c_altura-250)/c_desp;
   c_mod=(c_altura-250)%c_desp;
   if(c_mod>0){c_cont=(c_cont-(c_mod*0.1))+1;}
   c_pos=0;
   capa.style.pixelTop=60;
  }
  capa2.style.visibility="hidden";
  capa.style.visibility="visible";
}

function ini_scroll(d){
  if(d==-1){funciona_scroll=0;c_velo=1;}else{funciona_scroll=1;scroll(d);}
}

function velocidad(n){
  c_velo=n+1;
}

// funciones javascript para home


function cambia(o,x,arg){
/* -----------------------------------------------------------------------

en arg tendremos los argumentos necesarios (posicion 0 y 1, menu y submenu), salto a una noticia o a una convocatoria en especial, etc...

----------------------------------------------------------------------- */
 n=(eval(o.id))-1;
 colores=["#ffffff","#D9EDFF"];
 if(x!=2){
    if(n!=actual){
     document.getElementById(String(n+1)+"1").style.backgroundColor=colores[x];
     document.getElementById(String(n+1)+"2").style.backgroundColor=colores[x];
     o.style.backgroundColor=colores[x];
    }
 }else{
   switch(arg.length){
     case 1:abre_aviso(arg[0]);break;
     case 5:miv6=window.open("docs/"+arg[3], "noticia");miv6.focus();break;
     case 2:
  	parent.menu.posicion=[arg[0],arg[1]];
	cc=parent.menu.document.getElementById(String(arg[0]+1));
     	parent.menu.cambia('',cc,2,arg[1],-1);
     	break;
     case 3:
        if(arg=="1,5,-1"){abre_cal();}else{
	if(arg[2]!="-1"){ela=arg[1]-1;}else{ela=arg[1];}
  	parent.menu.posicion=[arg[0],ela,arg[2]];
	cc=parent.menu.document.getElementById(String(arg[0]+1));
     	parent.menu.cambia('',cc,2,ela,arg[2]);
	}
     	break;
   }
 }
}

function abre_cal(){
  cal=window.open("convocatorias/convocatorias.php","CAL");
  cal.focus();
}

function abre_aviso(nn){
  alto=screen.height;ancho=screen.width;ancho2=471;alto2=220;
  izda=(ancho/2)-(ancho2/2);arriba=(alto/2)-(alto2/2);
  miv6=window.open("aviso.php?num="+String(nn), "AVISO", "left="+izda+",top="+arriba+",toolbar=no,titlebar=yes,scrollbars=1,Resizable=1,copyhistory=0,width="+ancho2+",height="+alto2);
  miv6.focus()  
}
