/********************************************************************/
//** 
    core.loadUnit("animate");
    core.loadUnit("listbox");
    core.loadUnit("color");


  
 

/********************************************************************/
//** 

SLDwidth			= 310;					// ancho del plugin
SLDheight			= 85;					// alto del plugin
SLDspeed			= 10 ;					// velocidad
SLDbgcolor			= "#FFF9F1";			// color de fondo
SLDstartDirection 	= 'right' 			//direccion en la que se mueve inicialmente el banner
SLDDelay 			= 10;			//retardo entre un desplazamiento y el siguiente (100 brusco, 1 suave)
SLDmode				= 'pause'   // modo de funcionamiento 
									// continuous: el banner se desplaza continuamente con control de velocidad por el raton
  									//             en este modo SLDpauseEvery, SLDpauseDelay son ignorados
									// pause: el banner se desplaza parando SLDpauseDelay miliseg cada SLDpauseEvery pixeles
									//        en este modo SLDspeedControl se pone a false (no hay control por raton)
SLDspeedControl 	= true;			//habilita/desabilita el control de velocidad con el cursor
SLDshowArrows		= false;		// habilita/deshabilita que se vean las flechas del control de velocidad
									// si SLDspeedControl=false entonces tampoco se ven las flechas

SLDshowFade		= true;		// habilita/deshabilita los extremos degradados
									//  es totalmente compatible con SLDspeedControl y con SLDshowArrows

SLDpauseEvery		= 310 ;			//el slider se para cada este numero de pixeles (si es 0 no se para)
									// si es <>0 se desactiva automaticamente el control de velocidad
SLDpauseDelay		= 4000			//miliseg que se para el slide cada SLDpauseEvery numero de pixeles
 
//**********************************************************************/

SLDelementsSrc		= '';
var finalslide		= '';
var lastmove 		= -1;
var stepspeed 		= new Array(9,9,3,2,2,1,1,2,3,5,9,9); 
var NSTEPS 			= stepspeed.length;
var SLDKheight		= 5;
var SLDimgbase		= '/iconos/';
var lefttime		= null;
var fSTOP 			= false;
var fcurDir			= SLDstartDirection;

var actualheight 	= 0;
var slide1, ns_slide;




gg=0;
/********************************************************************/
//** 
//* <descripcion>
//* @param <name> -> <valor>
//* ...
//* @param <name> -> <valor>
//* @return <retorno>
/********************************************************************/

//DEBE INCLUIRSE ESTA FUNCION PARA INICIALIZAR EL PLUGIN
// EN EL ONLOAD DE LA PAGINA



function SLD_initSlider() 
{

	copyspeed = SLDspeed;
	
	if (SLDmode=='pause')  
			SLDspeedControl = false;

	if (SLDmode=='continous') 
		{ SLDpauseDelay=0; SLDpauseEvery=0; }
	

		

	i=0;
	while (  document.getElementById('SLDEL'+i)!=null ) 
	{
		lm  = document.getElementById('SLDEL'+i);

		actualheight += lm.offsetHeight;

		SLDelementsSrc += '<TR><TD align=top valign=top>'+ lm.innerHTML +'</TD></TR>';
		lm.style.visibility = "hidden";
		i++;
	}



	elm_SLDCONTAINER = document.getElementById('SLDCONTAINER')
	containerTop = document.getElementById('SLDCONTAINER').offsetTop;
	containerLeft = document.getElementById('SLDCONTAINER').offsetLeft;



	SLDelementsSrc = '<TABLE BORDER=0  heigth=' + actualheight + ' CELLSPACING=0 CELLPADDING=0>' + SLDelementsSrc + '</TABLE>';


	Uarrow = core.createElm(null,containerLeft + SLDwidth/2-20, containerTop );

	if (SLDspeedControl && SLDshowArrows )
			Uarrow.setText('<img src="' + SLDimgbase + 'arrow_arr.gif" BORDER="0" width=100% height=100%>');
	else
			Uarrow.setText('');
			
	Uarrow.setZ(3);
	Uarrow.setAlpha(60);
	if (SLDshowArrows)  Uarrow.show();
	


	Darrow = core.createElm(null, containerLeft + SLDwidth/2-20, containerTop + SLDheight-20)

	if (SLDspeedControl  && SLDshowArrows )
			Darrow.setText('<img src="' + SLDimgbase + 'arrow_aba.gif" BORDER="0" width=100% height=100%>');
	else
			Darrow.setText('');

	Darrow.setAlpha(60);
	Darrow.setZ(3);
	if (SLDshowArrows)  Darrow.show();


	Saux = core.createElm(null, 0,200);
	Saux.hide();

	if (SLDshowFade)
	{

		Ufade = core.createElm(elm_SLDCONTAINER,containerLeft, containerTop, SLDwidth, 60 );
				Ufade.setText('<img src="' + SLDimgbase + 'fade_arr.png" BORDER="0" width=100% height=100%>');
				Ufade.onmouseover = function (e){if (typeof e=='undefined') e=event; SLD_mouseIsOver(e)};
				Ufade.onmouseout = function  (e){if (typeof e=='undefined') e=event; SLD_mouseIsOut(e)};
				Ufade.onmousemove = function (e){if (typeof e=='undefined') e=event; SLD_mouseIsMoved(e)};
				Ufade.show();
		Dfade = core.createElm(elm_SLDCONTAINER, containerLeft , containerTop + SLDheight-60, SLDwidth, 60)
				Dfade.setText('<img src="' + SLDimgbase + 'fade_aba.png" BORDER="0" width=100% height=100%>');
				Dfade.onmouseover = function (e){if (typeof e=='undefined') e=event; SLD_mouseIsOver(e)};
				Dfade.onmouseout = function  (e){if (typeof e=='undefined') e=event; SLD_mouseIsOut(e)};
				Dfade.onmousemove = function (e){if (typeof e=='undefined') e=event; SLD_mouseIsMoved(e)};
				Dfade.show();
	}

	SLD_fillup();



}



/********************************************************************/
//** 
//* <descripcion>
//* @param <name> -> <valor>
//* ...
//* @param <name> -> <valor>
//* @return <retorno>
/********************************************************************/



function SLD_fillup()
{
	slide1= document.getElementById("SLDstrip1") 
	slide2= document.getElementById("SLDstrip2") 

	slide1.innerHTML   	= SLDelementsSrc ;
	slide2.innerHTML	= SLDelementsSrc ;
	

	slide2.style.top = actualheight  + "px"

	sldinc = 0;

		

	if (SLDstartDirection=='down')
	{
		lefttime=setInterval("SLD_slidedown_" + SLDmode + "()",SLDDelay);
		slide1.style.top = "0px";
		slide2.style.top = actualheight  + "px"

	}
	else
	{
		lefttime=setInterval("SLD_slideup_" + SLDmode + "()",SLDDelay);
		slide1.style.top = (parseInt(slide1.style.top)) + "px";
		slide2.style.top = (actualheight  ) + "px"
	}


}




/********************************************************************/
//** 
//* <descripcion>
//* @param <name> -> <valor>
//* ...
//* @param <name> -> <valor>
//* @return <retorno>
/********************************************************************/

function SLD_slideup_continuous()
{


	if (fSTOP)
		return;
	

	if (SLDshowArrows) Uarrow.show();
	Uarrow.setSize(copyspeed*SLDKheight,copyspeed*SLDKheight)
	Uarrow.setX(containerLeft+ SLDwidth/2-copyspeed*SLDKheight/2);
	Uarrow.setY(containerTop )

	Darrow.hide();


	if (parseInt(slide1.style.top)>(actualheight*(-1)+copyspeed))
		slide1.style.top=parseInt(slide1.style.top)-copyspeed+"px";
	else
		slide1.style.top=parseInt(slide2.style.top)+actualheight+"px";

	if (parseInt(slide2.style.top)>(actualheight*(-1)+copyspeed))
		slide2.style.top=parseInt(slide2.style.top)-copyspeed+"px";
	else
		slide2.style.top=parseInt(slide1.style.top)+actualheight+"px";


	if (SLDmode=='pause' && 1*slide1.style.top.slice(0,-2)%SLDpauseEvery==0 )
	{
		SLDstopSlider();
		setTimeout('SLDstartSlider()',SLDpauseDelay);
	}
	

	fcurDir = 'up';

//window.status="slide1//slide2.top="+slide1.style.top + "//"+slide2.style.top + '--actualheight=' + actualheight;

}

function SLD_slideup_pause()
{


	if (fSTOP)
		return;
	

	if (SLDshowArrows) Uarrow.show();
	Uarrow.setSize(copyspeed*SLDKheight,copyspeed*SLDKheight)
	Uarrow.setX(containerLeft+ SLDwidth/2-copyspeed*SLDKheight/2);
	Uarrow.setY(containerTop )

	Darrow.hide();


	if (parseInt(slide1.style.top)>=(actualheight*(-1)+copyspeed))
		slide1.style.top=parseInt(slide1.style.top)-copyspeed+"px";

	if (parseInt(slide2.style.top)>=(actualheight*(-1)+copyspeed))
		slide2.style.top=parseInt(slide2.style.top)-copyspeed+"px";



	if (parseInt(slide1.style.top)+actualheight<=0)
		slide1.style.top=parseInt(slide2.style.top)+actualheight+"px";

	if (parseInt(slide2.style.top)+actualheight<=0)
		slide2.style.top=parseInt(slide1.style.top)+actualheight+"px";

	sldinc += copyspeed;

	if (SLDmode=='pause' && (sldinc%SLDpauseEvery==0 ))
	{
		SLDstopSlider();
		setTimeout('SLDstartSlider()',SLDpauseDelay);
	}
	

	fcurDir = 'up';

//document.forms.valor.valores.value = "slide1="+slide1.style.top + "//slide2="+slide2.style.top + '--sldinc%SLDpauseEvery=' + sldinc%SLDpauseEvery + '--actualheight=' + actualheight;

}









function SLD_slidedown_continuous()
{

	if (fSTOP)
		return;


	if (SLDshowArrows) Darrow.show();
	Darrow.setSize(copyspeed*SLDKheight,copyspeed*SLDKheight)
	Darrow.setX(containerLeft+ SLDwidth/2-copyspeed*SLDKheight/2);
	Darrow.setY(containerTop + SLDheight-copyspeed*SLDKheight);

	
		//Uarrow.setX(containerLeft+ SLDwidth/2-copyspeed*SLDKheight);
		//Uarrow.setY(containerTop )

	Uarrow.hide()


	if (parseInt(slide1.style.top)<parseInt(SLDheight)-copyspeed)
		slide1.style.top=parseInt(slide1.style.top)+copyspeed+"px";
	else
		slide1.style.top=parseInt(slide2.style.top)-actualheight-copyspeed+"px";

	if (parseInt(slide2.style.top)<parseInt(SLDheight)-copyspeed)
		slide2.style.top=parseInt(slide2.style.top)+copyspeed+"px";
	else
		slide2.style.top=parseInt(slide1.style.top)-actualheight-copyspeed+"px";



	if (SLDmode=='pause' && 1*slide1.style.top.slice(0,-2)%SLDpauseEvery==0 )
	{
		SLDstopSlider();
		setTimeout('SLDstartSlider()',SLDpauseDelay);
	}
	
	fcurDir = 'down';

//window.status="slide1//slide2.top="+slide1.style.top + "//"+slide2.style.top + '--actualheight=' + actualheight;


}


 





function SLD_slidedown_pause()
{

	if (fSTOP)
		return;


	if (SLDshowArrows)  Darrow.show();
	Darrow.setSize(copyspeed*SLDKheight,copyspeed*SLDKheight)
	Darrow.setX(containerLeft+ SLDwidth/2-copyspeed*SLDKheight);
	Darrow.setY(containerTop + SLDheight-copyspeed*SLDKheight/2);
	
	Uarrow.hide()



	if (parseInt(slide1.style.top)<=parseInt(SLDheight))
		slide1.style.top=parseInt(slide1.style.top)+copyspeed+"px";

	if (parseInt(slide2.style.top)<=parseInt(SLDheight))
		slide2.style.top=parseInt(slide2.style.top)+copyspeed+"px";


	if (parseInt(slide1.style.top)>=parseInt(SLDheight))
		slide1.style.top=parseInt(slide2.style.top)-actualheight+"px";
	if (parseInt(slide2.style.top)>=parseInt(SLDheight))
		slide2.style.top=parseInt(slide1.style.top)-actualheight+"px";


	sldinc += copyspeed;

	if (SLDmode=='pause' && (sldinc%SLDpauseEvery==0 ))
	{

		SLDstopSlider();
		setTimeout('SLDstartSlider()',SLDpauseDelay);
	}
	
	fcurDir = 'down';

//window.status = "slide1="+slide1.style.top + "//slide2="+slide2.style.top + '--sldinc%SLDpauseEvery=' + sldinc%SLDpauseEvery + '--actualheight=' + actualheight;

}



/********************************************************************/
//** 
//* <descripcion>
//* @param <name> -> <valor>
//* ...
//* @param <name> -> <valor>
//* @return <retorno>
/********************************************************************/

function SLD_mouseIsOver(evnt)
{

	//window.status = evnt.clientX;
	//copyspeed=0;


}



function SLD_mouseIsOut(evnt)
{


	copyspeed=SLDspeed;


}




function SLD_mouseIsMoved(evnt)
{

	if (!SLDspeedControl)
		return;

	dist = evnt.clientY-parseInt(SLDheight)/2;
	step = Math.floor(evnt.clientY/(parseInt(SLDheight)/NSTEPS))

	if ( dist/Math.abs(dist)!=lastmove )
		 if (dist<0 )
		 {
			if ( lefttime!=null)
				clearTimeout(lefttime);
			lefttime=setInterval("SLD_slidedown_" + SLDmode + "()",SLDDelay);
		 }
		 else
		 {
			if ( lefttime!=null)
				clearTimeout(lefttime);
			lefttime=setInterval("SLD_slideup_" + SLDmode + "()",SLDDelay);

		 }

	lastmove = dist/Math.abs(dist);
	

	step = step<1 ? 1 :  (step>stepspeed.length-1 ? stepspeed.length : step)


	copyspeed = stepspeed[step-1];

//window.status = "step=" + step + "---stepspeed[" + (1*step-1) + "]=" + stepspeed[step-1] + "---copyspeed=" + copyspeed + "";


}

function SLDstartSlider()
{
	
	fSTOP = false;
	
	if (fcurDir=='down')
		lefttime=setInterval("SLD_slidedown_" + SLDmode + "()",SLDDelay);
	else
		lefttime=setInterval("SLD_slideup_" + SLDmode + "()",SLDDelay);

}


function SLDstopSlider()
{

	fSTOP = true;
	clearInterval(lefttime);

	
}


/********************************************************************/
//** 
//* <descripcion>
//* @param <name> -> <valor>
//* ...
//* @param <name> -> <valor>
//* @return <retorno>
/********************************************************************/


function SLD_genSlider()
{

	

	with (document){

		write  (' <TABLE BORDER=0   CELLSPACING=0 CELLPADDING=0 >  ');
		  writeln  (' <tr>  ');
		  writeln  (' <td valign="top">  ');

		write('<table border="0" cellspacing="0" cellpadding="0"><td>')
			write('<div id=SLDCONTAINER style="position:relative;width:'+SLDwidth+';height:'+SLDheight+';overflow:hidden">')
			write('<div style="position:absolute;width:'+SLDwidth+';height:'+SLDheight+';background-color:'+SLDbgcolor+'" onMouseover="SLD_mouseIsOver(event)" onMouseout="SLD_mouseIsOut(event)" onMouseMove="SLD_mouseIsMoved(event);">')
			write('<div id="SLDstrip1" style="position:absolute;left:0px;top:0px"></div>')
			write('<div id="SLDstrip2" style="position:absolute;left:0px;top:-1000px"></div>')
			write('</div></div>')

		write('</td></table>')

		writeln  (' </td></tr></table>  ');
	}


	
	
	
}







