function Es() {
    agent  = navigator.userAgent.toLowerCase();
    this.major = parseInt(navigator.appVersion);
    this.minor = parseFloat(navigator.appVersion);
    this.ns    = ((agent.indexOf('mozilla')   !=   -1) &&
                 ((agent.indexOf('spoofer')   ==   -1) &&
                 (agent.indexOf('compatible') ==   -1)));
    this.ns2   = (this.ns && (this.major      ==    3));
    this.ns3   = (this.ns && (this.major      ==    3));
    this.ns4b  = (this.ns && (this.major      ==    4) &&
                 (this.minor                  <= 4.03));
    this.ns4   = (this.ns && (this.major      >=    4));
    this.ns6    = (this.ns && (this.major     >=    5));
    this.ie    = (agent.indexOf("msie")       !=   -1);
    this.ie3   = (this.ie && (this.major      <     4));
    this.ie4   = (this.ie && (this.major      ==    4) &&
                 (agent.indexOf("msie 5.0")   ==   -1));
    this.ie5   = (this.ie && (this.major      ==    4) &&
                 (agent.indexOf("msie 5.0")   !=   -1));
    this.ie55  = (this.ie && (this.major      ==    4) &&
                 (agent.indexOf("msie 5.5")   !=   -1));
}

function DirCapa(nombre){
var obj;
	if(es.ns) {
   		 if (es.ns6){
        		 obj = document.getElementById(nombre);
    		 } else {
         		obj = document.layers[nombre];
    		 }
	} else if(es.ie) {
    		obj = document.all[nombre];
	}
	return obj;
}

function ColorFondo(capa, color) {
var obj = capa.style?capa.style:capa;

 if (es.ns && !es.ns6)
   obj.bgColor = color;
 if (es.ie || es.ns6)
    obj.backgroundColor = color;
}

function VisibilidadCapa(capa, estado) {
var obj = capa.style?capa.style:capa;

    obj.visibility = estado;
}

function PosicionarCapa (capa, x, y) {
var obj = capa.style?capa.style:capa;

  if (es.ns)
	if (es.ns6) {
		obj.left = x + "px";
    		obj.top  = y + "px";
	} else
    		obj.moveTo(x, y);
  if (es.ie) {
	obj.pixelLeft = x;
	obj.pixelTop  = y;
  }
}

function MoverCapa(capa, dx, dy) {
var obj = capa.style?capa.style:capa;

  if (es.ns)
	if (es.ns6) {
		obj.left = parseInt(obj.left) + dx + "px";
    		obj.top  = parseInt(obj.top) + dy + "px";
	} else
    		obj.moveBy(dx, dy);
  if (es.ie) {
	obj.pixelLeft += dx;
	obj.pixelTop  += dy;
  }
}

function RecortarCapa(capa, top, right, bottom, left){
var obj = capa.style?capa.style:capa;
  
  if (es.ns){
	if (es.ns6) {
		obj.clip = 'rect(' + top + 'px ' + right + 'px ' + bottom + 'px ' + left + 'px)';
	} else {
		obj.clip.top = top;
		obj.clip.right = right;
		obj.clip.bottom = bottom;
		obj.clip.left = left;
 	 }
  }
  if (es.ie) {
		obj.clip = 'rect(' + top + ' ' + right + ' ' + bottom + ' ' + left + ')';
  }
}

function Carrega(ruta, pagina) {
	if ( data != parent.frames["MENU"].data){
      	parent.frames["MENU"].location.href = "/avui/diari/" + ruta + "/menu/menu.htm";
      }
	parent.frames["PRINCIPAL"].location.href = "/avui/diari/" + ruta + "/" + pagina;
}

function Carrega_home() {
	parent.frames["PRINCIPAL"].location.href = "/avui/diari/" + parent.frames["MENU"].data + "/menu/home.htm";
}

// INICIALITZACIÓ CAPAS

function InitCapas(lineas) {
	if(es.ns) {
		if (es.ns6)
  	   		ample=self.innerWidth;
		else
  	   		ample=self.innerWidth+4;
	} else
      	ample=document.body.clientWidth;
	

     max_pos = lineas*16;
     pos = 16;
     titularsObj = DirCapa("titularsCapa");
     PosicionarCapa(titularsObj, 58, 19);	
     RecortarCapa(titularsObj, 0+pos, ample-65, 16+pos, 0);	

     ColorFondo(titularsObj, '#dddddd');
     VisibilidadCapa(titularsObj, "visible");
     setTimeout("scroll()", 6000);

}	

function scroll() {
      if (incr < 16){
	    incr += 1;
          pos += 1;
          MoverCapa(titularsObj, 0, -1);
	    RecortarCapa(titularsObj, 0+pos, ample-65, 16+pos, 0);	
          setTimeout("scroll()", 50);
	} else {
		incr = 0;
		if (pos < max_pos) {
	             setTimeout("scroll()", 6000);	
		} else {
			pos = 0;
			PosicionarCapa(titularsObj, 58, 35);
                  RecortarCapa(titularsObj, 0+pos, ample-65, 16+pos, 0)
                  scroll();			
            }
	}
}
	
var es = new Es();
var pos;
var max_pos;
var incr = 0;
var ample=0;
var titularsObj;

