/********************************************************************/
//** 
    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


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 SLDKwidth		= 5;
var SLDimgbase		= '/iconos/';
var lefttime		= null;
var fSTOP 			= false;
var fcurDir			= SLDstartDirection;

var actualwidth 	= 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);

		actualwidth += lm.offsetWidth;

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



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



	SLDelementsSrc = '<TABLE BORDER=0  width=' + actualwidth + ' CELLSPACING=0 CELLPADDING=0><TR>' + SLDelementsSrc + '</TR></TABLE>';


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

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


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

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

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


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





	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.left = actualwidth  + "px"

	sldinc = 0;

	if (SLDstartDirection=='right')
		lefttime=setInterval("SLD_slideright_" + SLDmode + "()",SLDDelay);
	else
		lefttime=setInterval("SLD_slideleft_" + SLDmode + "()",SLDDelay);
		
}




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

function SLD_slideleft_continuous()
{


	if (fSTOP)
		return;
	

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

	Rarrow.hide();


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

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


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

	fcurDir = 'left';

//window.status="slide1//slide2.left="+slide1.style.left + "//"+slide2.style.left + '--actualwidth=' + actualwidth;

}

function SLD_slideleft_pause()
{


	if (fSTOP)
		return;
	

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

	Rarrow.hide();


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

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



	if (parseInt(slide1.style.left)+actualwidth<=0)
		slide1.style.left=parseInt(slide2.style.left)+actualwidth+"px";

	if (parseInt(slide2.style.left)+actualwidth<=0)
		slide2.style.left=parseInt(slide1.style.left)+actualwidth+"px";

	sldinc += copyspeed;

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

	fcurDir = 'left';

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

}









function SLD_slideright_continuous()
{

	if (fSTOP)
		return;


	if (SLDshowArrows) Rarrow.show();
	Rarrow.setSize(copyspeed*SLDKwidth,copyspeed*SLDKwidth)
	Rarrow.setX(containerLeft+ SLDwidth-copyspeed*SLDKwidth);
	Rarrow.setY(containerTop + SLDheight/2-copyspeed*SLDKwidth/2);
	
	Larrow.hide()


	if (parseInt(slide1.style.left)<parseInt(SLDwidth)-copyspeed)
		slide1.style.left=parseInt(slide1.style.left)+copyspeed+"px";
	else
		slide1.style.left=parseInt(slide2.style.left)-actualwidth-copyspeed+"px";

	if (parseInt(slide2.style.left)<parseInt(SLDwidth)-copyspeed)
		slide2.style.left=parseInt(slide2.style.left)+copyspeed+"px";
	else
		slide2.style.left=parseInt(slide1.style.left)-actualwidth-copyspeed+"px";



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

//window.status="slide1//slide2.left="+slide1.style.left + "//"+slide2.style.left + '--actualwidth=' + actualwidth;


}


 





function SLD_slideright_pause()
{

	if (fSTOP)
		return;


	if (SLDshowArrows)  Rarrow.show();
	Rarrow.setSize(copyspeed*SLDKwidth,copyspeed*SLDKwidth)
	Rarrow.setX(containerLeft+ SLDwidth-copyspeed*SLDKwidth);
	Rarrow.setY(containerTop + SLDheight/2-copyspeed*SLDKwidth/2);
	
	Larrow.hide()



	if (parseInt(slide1.style.left)<=parseInt(SLDwidth))
		slide1.style.left=parseInt(slide1.style.left)+copyspeed+"px";

	if (parseInt(slide2.style.left)<=parseInt(SLDwidth))
		slide2.style.left=parseInt(slide2.style.left)+copyspeed+"px";


	if (parseInt(slide1.style.left)>=parseInt(SLDwidth))
		slide1.style.left=parseInt(slide2.style.left)-actualwidth+"px";
	if (parseInt(slide2.style.left)>=parseInt(SLDwidth))
		slide2.style.left=parseInt(slide1.style.left)-actualwidth+"px";


	sldinc += copyspeed;

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

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

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

}



/********************************************************************/
//** 
//* <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.clientX-parseInt(SLDwidth)/2;
	step = Math.floor(evnt.clientX/(parseInt(SLDwidth)/NSTEPS))

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

		 }

	lastmove = dist/Math.abs(dist);
	

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


	copyspeed = stepspeed[step-1];



}

function SLDstartSlider()
{
	
	fSTOP = false;
	
	if (fcurDir=='right')
		lefttime=setInterval("SLD_slideright_" + SLDmode + "()",SLDDelay);
	else
		lefttime=setInterval("SLD_slideleft_" + 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:-1000px;top:0px"></div>')
			write('</div></div>')

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

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


	
	
	
}






