NS4=(document.layers);IE4=(document.all);isDOM=((document.getElementById)&&(!IE4))?true:false;
isOP=(navigator.userAgent.indexOf('Opera') != -1)?true:false;
if((NS4||IE4||isDOM)&&(!isOP)){

interval=30;
increment=2;
pause=5000;
pause_ini=10;
leftPadding=1;
topPadding=5;
maxLoops=99;

// Parametros de configuracion del texto de la noticia
align=' ALIGN="justify" '
align_news=' ALIGN="left" '
target=' TARGET="_top" '
classid=' CLASS="textonoticias" '
numheadlines=10;
isMac=(navigator.userAgent.indexOf('Mac') != -1)?true:false;

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


function InicializarVectores()
{
  prefix='';

  arURL =  new Array(
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
''
);
/*arURL = new Array( 
'noticias/noticia82.html',
'noticias/noticia81.html',
'noticias/noticia80.html',
'noticias/noticia79.html',
'noticias/noticia78.html',
'pdf/JORN_INFOR_AYUDAS_PROY08.pdf',
'noticias/noticia73.html',
'noticias/noticia74.html',
'noticias/noticia75.html',
'noticias/noticia76.html',
'noticias/noticia77.html'

);

  arTXT =  new Array(
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
''
);
/*  arTXT =  new Array(
'La Agencia Valenciana de la Energía recibe un total de 43 proyectos de ahorro energético del sector azulejero',
'La Generalitat impulsa el desarrollo de un sistema de control inteligente de iluminación para reducir el consumo energético',
'Infraestructuras autoriza un nuevo parque eólico en la comarca de Los Serranos',
'Cejalvo: “El huerto solar de Tuéjar podrá abastecer a una población de 3.000 habitantes”',
'Infraestructuras destina más de tres millones de euros para respaldar proyectos de energías renovables',
'Jornada Informativa "AYUDAS a PROYECTOS", 3 de Abril de 2008',
'Infraestructuras destina 180.000 euros  para ampliar en 240 bicicletas el sistema de préstamo de Castellón',
'Infraestructuras pone en marcha el Plan Valenciano de Electrificación Rural 2008',
'Flores: “La celebración de Egética consolidará a la Comunitat como referente internacional en eficiencia energética”',
'Infraestructuras prevé sustituir 1.800 semáforos de la Comunitat por otros de “bajo consumo energético”',
'Un total de 22 municipios de Alicante solicitan ayudas a la AVEN para renovar el alumbrado público'
);*/

   
  arFEC = new Array(
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
''
);

}

function reDo(){window.location.reload();}

function getObj(i){
   if (isDOM) {
      obj=document.getElementById("msg"+i).style;
   }else{
      obj=eval("msg"+i+((IE4)?".style":""));
   }
   return obj;
}

function showMsg(n,show){
   var theEl=getObj(n);
   theEl.visibility=(show)?"visible":"hidden";
}

function nextMsg(){
   var fm=current;
   current=(fm==ar.length-1)?0:fm+1;
   if(current==1)loopCount++;
   if(finite&&(loopCount>=maxLoops))return;
   scrollBnr(fm,current);
}

// mouseover/out new 010222 - abk

function SCRLmouseover() {
	clearInterval(intervalID);
	clearTimeout(timeoutID);
}

function SCRLmouseout() {
	intervalID=setInterval("moveUp()",interval);
}

function moveUp(){
   if (isDOM) {
      var inttoeltopdec = parseInt(toEl.top)-increment;
      fmEl.top=parseInt(fmEl.top) - increment; 
      if(inttoeltopdec<=toElTarget){
         toEl.top=toElTarget;
         clearInterval(intervalID);
        fmEl.visibility="hidden";
         timeoutID=setTimeout("nextMsg()",pause);
      }else{
         toEl.top=inttoeltopdec; // no px
      }
   }else{
      if(NS4){
         var inttoeltopdec = toEl.top-increment;
         fmEl.top-=increment;
         if(inttoeltopdec<=toElTarget){
            toEl.top=toElTarget;
            clearInterval(intervalID);
            fmEl.visibility="hidden";
            timeoutID=setTimeout("nextMsg()",pause);
         }else{
            toEl.top=inttoeltopdec;
         }
      }else{
         var inttoeltopdec = toEl.pixelTop-increment;
         fmEl.pixelTop-=increment;
         if(inttoeltopdec<=toElTarget){
            toEl.pixelTop=toElTarget;
            clearInterval(intervalID);
            fmEl.visibility="hidden";
            timeoutID=setTimeout("nextMsg()",pause);
         }else{
            toEl.pixelTop=inttoeltopdec;
         }
      }
   }
}

function scrollBnr(fm,to){
   fmEl=getObj(fm);
   toEl=getObj(to);
   if (isDOM) {
	toElTarget=parseInt(fmEl.top);        // save one parseInt 010224
	toEl.top=(toElTarget+bnrHit) + "px"; 
//      toEl.top=(parseInt(fmEl.top)+bnrHit) + "px";
//      toElTarget=parseInt(fmEl.top);
   }else{
      if(NS4){
         toEl.top=fmEl.top+bnrHit;
         toElTarget=fmEl.top;
      }else{
         toEl.pixelTop=fmEl.pixelTop+bnrHit;
         toElTarget=fmEl.pixelTop;
      }
   }
   showMsg(to,true);
   intervalID=setInterval("moveUp()",interval);
	// can use setTimeout for evengreater speed - abk 010227
}

function moveIE(lPos,tPos){this.style.pixelLeft=lPos;this.style.pixelTop=tPos;}
function moveDOM(lPos,tPos){this.style.left=lPos+"px";this.style.top=tPos+"px";}

function makeIE(){
	var text='<DIV ID="bnr" STYLE="position:absolute;overflow:hidden;top:'+bnrTop+';left:'+bnrLft +';width:'+bnrWid+';height:'+bnrHit+'">';
	msgWid=bnrWid-leftPadding;
	for(var i=ar.length-1;i>=0;i--){
		text+='<DIV ID="msg'+i+'" STYLE="position:absolute;overflow:hidden;visibility:hidden;top:'+ topPadding +';left:'+leftPadding+';width:'+msgWid+'"><\/DIV>';
	}
	text+='<\/DIV>';	
	document.body.insertAdjacentHTML("BeforeEnd",text);
	
//	bnr.onmouseover=SCRLmouseover;
//	bnr.onmouseout=SCRLmouseout;

	for(i=0;i<ar.length;i++){
		var scroller = eval("msg"+i);
		scroller.moveTo=moveIE;
	}
}

function makeDOM(){
	var elmParentDiv;
   
	elmParentDiv = document.createElement('div');
	elmParentDiv.id = 'bnr';
	elmParentDiv.style.position = 'absolute';
	elmParentDiv.style.overflow = 'hidden';
	elmParentDiv.style.top = bnrTop + 'px';
	elmParentDiv.style.left = bnrLft + 'px';
	elmParentDiv.style.width = bnrWid + 'px';
	elmParentDiv.style.height = bnrHit + 'px';
	
	elmParentDiv.onmouseover = SCRLmouseover;
	elmParentDiv.onmouseout  = SCRLmouseout;

	var elmChildDiv;
	var i;

	msgWid=bnrWid-leftPadding;

   for (i = ar.length - 1; i >= 0; i--)
   {
       elmChildDiv = document.createElement('div');
       elmChildDiv.id = 'msg' + i;
       elmChildDiv.style.position = 'absolute';
       elmChildDiv.style.visibility = 'hidden';
       elmChildDiv.style.overflow = 'hidden';
       elmChildDiv.style.top = topPadding + 'px';
       elmChildDiv.style.left = leftPadding + 'px';
       elmChildDiv.style.width = msgWid + 'px';

       elmParentDiv.appendChild(elmChildDiv);
       
       elmChildDiv.moveTo=moveDOM;
   }
   
   document.body.appendChild(elmParentDiv);
}

function makeNS(){
   bnr=new Layer(bnrWid);
   with(bnr){
      clip.right=bnrWid;
      clip.bottom=bnrHit;
      moveTo(bnrLft,bnrTop);
      visibility="show";
   }	
//	bnr.onmouseover = SCRLmouseover;
//	bnr.onmouseout  = SCRLmouseout;

   for(var i=0;i<ar.length;i++){
      eval("msg"+i+"="+"new Layer(bnrWid-leftPadding,bnr)");
      with(eval("msg"+i)){
         moveTo(leftPadding,topPadding);
      }
   }
}


function fillBnr(){
   var theEl;
   for(i=0;i<ar.length;i++){
      if (isDOM){
         theEl=document.getElementById("msg"+i);
      }else{
         theEl=eval("msg"+i);
      }
      // Monta la referencia
      newsStr="<div "+align_news+classid+">"+ar[newsCount][2]+"</div>"+
              "<div "+align+"><A "+target+classid+
              "HREF=\"#\" onClick=\"MM_openBrWindow(\'"+
              ar[newsCount][0]+
              "\',\'\',\'width=530,height=420\')\">"+
              ar[newsCount][1]+"<\/A></div>";

      if(NS4){
         with(theEl.document){write(newsStr);close();}
      }else{
         theEl.innerHTML=newsStr;
      }
      newsCount++;if(newsCount==ar.length)newsCount=0;
  
   }
}

function startBnr(){
   if (isDOM){makeDOM();}
      else{(NS4)?makeNS():makeIE();}
   fillBnr();
   showMsg(0,true);
   current=0;
   window.onresize=reDo;
   timeoutID=setTimeout("nextMsg()",pause);
}

function initScroller() {
   InicializarVectores();
   finite=(maxLoops>0);
   ar=[];
   if(!window.arURL)return;
   if(arURL.length==0)return;
   if(arURL.length<numheadlines){numheadlines=arURL.length;}
   for(i=0;i<numheadlines;i++){ar[i]=[prefix+arURL[i],arTXT[i],arFEC[i]];}
   newsCount=0;
   if(finite){loopCount=0;}
   ispaused=0;
   bnrWid=125 // parseInt(pHT.width)-20;
   bnrHit=60 //parseInt(pHT.height)-20;
   bnrTop=bnrLft=0;

   if (document.getElementById){
      pHT=document.getElementById('ph1');
   }else{pHT=document.images['ph1'];}
   if(pHT){
   // Tamaño de la caja de noticias
      bnrWid=200 // parseInt(pHT.width)-20;
      bnrHit=75 //parseInt(pHT.height)-20;
      bnrOffsetLeft=(parseInt(pHT.width)-bnrWid) / 2;
      bnrOffsetTop=(parseInt(pHT.height)-bnrHit) / 2;
      if(document.getElementById){
         bnrTop=((isMac)&&(IE4))?pHT.clientTop:pHT.offsetTop;
         bnrLft=((isMac)&&(IE4))?pHT.clientLeft:pHT.offsetLeft;
         tEl=pHT;
         while(tEl.offsetParent != null) {
            tEl=tEl.offsetParent;
            bnrTop+=((isMac)&&(IE4))?tEl.clientTop:tEl.offsetTop;
            bnrLft+=((isMac)&&(IE4))?tEl.clientLeft:tEl.offsetLeft;
         }
      }else{
         if (IE4) {
            arPH=[level1,level2,level3,level4,level5];
            bnrTop=bnrLft=0;
            for(i=0;i<arPH.length;i++){
               tEl = arPH[i];
               bnrTop+=tEl.offsetTop;
               bnrLft+=tEl.offsetLeft;
            }
         }else{
            bnrTop = pHT.y;
            bnrLft = pHT.x;
         }
      }
      bnrLft+=bnrOffsetLeft;
      bnrTop+=bnrOffsetTop;
      startBnr();
   }
}

}
