	
	/*
		Purpose: Scroll through panes by either autoscroll, arrow buttons or pane indicator buttons
		Date: 3/19/06
	*/
	
	 // ******************************** Setup Variables ********************************
	 var ie4 = (document.all && !document.getElementById &&!window.opera) ? true:false;
	 var ie5 = (document.all && document.getElementById &&!window.opera) ? true:false;
	 var ns6 = (!document.all && document.getElementById &&!window.opera) ? true:false;
	 var viewerId = document.getElementById("mascara");		// block that displays current pane
	 var scrollContainer = "contenedor";									// wrapper that contains all panes
	 var indiContainer = "ynindcont";									// wrapper for indicator buttons
	 var currentPane = 1; 												// current pane viewed (this syncs up the arrow button and indicator button on/off states
	 var currentSL = 0;													// set current scrollLeft of div
	 var autoScroll;													// create autoScroll global var
	 var autoScrollOn = true; 											// set autoScroll to true upon load
	 
	 /* Setup ID/Class Names */
	 var sclBtnLft = "scrollLeft";										// name/id of left scroll button
	 var sclBtnRgt = "scrollRight";										// name/id of right scroll button	
	 var sclBtnClassOff = "buttonOff";									// scroll button class off												
	 var sclBtnClassOn  = "buttonOn";									// scroll button class on	
	 var indicatorClassOff = "off";										// indicator button class off
	 var indicatorClassOn = "on";										// indicator button class on

	 var w = viewerId.offsetWidth;										// set width								
	 var delayTime = 10000;												// time to wait between pane animation 1000 = 1 second	 
	 
	 /*
	 // Preload scroll button images
	  if (document.images)
	   {
	     var pic1on = new Image(29,108);
	     pic1on.src = "img/flechaizqover.gif";  
		 var pic2on = new Image(29,108);
	     pic2on.src = "img/flechaderover.gif";
	   }	 
	 */
	
	// ********************* Count DIVs and assign a Global Value of Panes ******************
	var gettabs = document.getElementById(scrollContainer);
	var getdiv = gettabs.getElementsByTagName("div"); 			
	
	var countPanes = 0;
	for (var x=0; x < getdiv.length; x++) {
		var classkey = getdiv[x].getAttribute("name");					// find the name attribute	
		
		if ((x === 0) && (classkey == "container")) { 					// gets the first pane in the container for duplication
			var getFirst = getdiv[x]; 
		}
			
        if (classkey == "container") {									// count DIVs where name = "container"
  	    	var idstring = getdiv[x].id;
			countPanes++;  
      	 }				
	}
	var tps_max = countPanes;											// max panes equals number of divs in container
    var max_width = w * tps_max;										// var to stop scrolling past last pane	
	//var max_panes = idstring.charAt(idstring.length-1);
	
	
	// ************************  Duplicate 1st Pane and append to end of ynscroll ****************************
	/*var duplicate = getFirst.cloneNode(true);
	duplicate.removeAttribute("id");
	duplicate.setAttribute("name", "duplicate");
	document.getElementById(scrollContainer).appendChild(duplicate);*/
	
	
	// ******************************** Reset Ticker and Create Event Listeners ********************************
	   
	viewerId.scrollLeft = '0px';   
	//animate(0);															// Reset Ticker back to first pane	  	
																		// If the total number of panes is over 1, then initialize autoStart
	//if (tps_max != 1) {YAHOO.util.Event.addListener(window, 'load', autoStart);	}			
	//YAHOO.util.Event.addListener(window, 'load', getHooks);				/* Wait until page loads to intialize scroll 
																			//buttons and indicator hooks */
	if (tps_max != 1) {YAHOO.util.Event.onAvailable(scrollContainer, autoStart, this);	}
	YAHOO.util.Event.onAvailable(scrollContainer, getHooks, this);		
	  
	 // ****************** Attach Click Hooks for Arrowa and Indicators ******************
	 function getHooks() {	
		 																// Attach width and direction to move, decrement/increment 
																		// the pane state
		  if (document.getElementById(sclBtnLft) && document.getElementById(sclBtnRgt)) {
			  var getLeft = document.getElementById(sclBtnLft);
			  getLeft.s = -w;
			  getLeft.d = "l";
			  getLeft.c = -1;
			  YAHOO.util.Event.addListener(getLeft, 'click', doAnimation, getLeft);
	
			  var getRight = document.getElementById(sclBtnRgt);
			  getRight.s = w;
			  getRight.d = "r";
			  getRight.c = 1;
			  YAHOO.util.Event.addListener(getRight, 'click', doAnimation, getRight);			  
		  }

		
		  // ******************  Setup Indicator Button Links *****************
		  																// loop through anchor tags, attach ID, width to move
																		// then wait for onclick event
		  var x = 0;
		  var getcont = document.getElementById(indiContainer);
		  var getAnchor = getcont.getElementsByTagName('a'); 
		  for (var n = 0; n < getAnchor.length; n++) {		  	
		  	    getAnchor[n].indi = getAnchor[n].id;
				getAnchor[n].num = x * w;  
				YAHOO.util.Event.addListener(getAnchor[n], 'click', setupIndicators, getAnchor[n]);					
				x++;
		  }
		  
	 }
	 
	// ******************************** Setup Indicators ********************************
																		// After indicator anchor is clicked, move scroller to
																		// width, change indicator state and stop autoScroll
	  function setupIndicators(e,obj) {
	   
	   if (tps_max != 1) {
		   // Start Animation
		   animate(obj.num);
		   // Setup Indicator
		   setIndicatorState(obj.indi);
		   // Clear autoScroll
	 	   stopInterval(); 
	   }
		
	   YAHOO.util.Event.preventDefault(e);	
	   return false;
	  }
 
	
	 // ******************************** Set Indicator State ******************************** 
	 function setIndicatorState(id) {
																		// If current pane is not 0 or over max panes
		 if ((currentPane >= 1) && (currentPane <= tps_max)) {
			var count =  1;
		 
		 																// Turn off indicator buttons state
		    while (count <= tps_max) {
			   var setIndiOff = document.getElementById(count);
			   setIndiOff.className = indicatorClassOff;
			   setIndiOff.setAttribute("class", indicatorClassOff);
			   count++;
		    }
																		// Turn on the "clicked" indicator button state
		    var setIndiOn = document.getElementById(id);
		    setIndiOn.className = indicatorClassOn;
		    setIndiOn.setAttribute("class", indicatorClassOn);
			
																		// Change Indicator Button from Scroll Buttons
			currentPane = id; 											// set currentPane to current indicator button
			currentSL = w * (id-1); 									// set currentSL to indicator button
		
																		// Check indicator ID and see which on/off state
																		// applies for the scroll buttons
			var check = (currentPane == 1)  ? changeButtons('f') : changeButtons('m');
			if (currentPane > 1) { changeButtons('m'); }
			if (currentPane == tps_max) { changeButtons('l'); }
			
		 } else if (currentPane < 1) { currentPane = 1;				// if currentPane is less than 1, make it 1
		 } else if ((currentPane > tps_max) && (autoScrollOn === false)) { currentPane = tps_max; }
																		// if currentPane is greater than max pane
																		// and autoScroll is off, make currentPane = to max
	 }
	
	
	// ******************************** Change Arrows ********************************
	   
	function changeButtons(m) {											// Change left and right scroll buttons according
		switch (m) {													//	to given parameter.
			case "f":
				bgPos(sclBtnLft,"off");									//	f (first): turns off left / turns on right buttons
				bgPos(sclBtnRgt,"on");									//	m (middle): turns on both scroll buttons 
			break;														//	l (last): turns on left / turns off right buttons
			case "m":
				bgPos(sclBtnLft,"on");									//	defaults to first scroll buttons
				bgPos(sclBtnRgt,"on");
			break;
			case "l":
				bgPos(sclBtnLft,"on");	
				bgPos(sclBtnRgt,"off");
			break;
			default: 
				bgPos(sclBtnLft,"off");
				bgPos(sclBtnRgt,"on");	
		}
	}
	
	 // ******************************** Indicator Image ********************************
	 function bgPos(id,state) {											// Takes the ID of the scroller button and 
		var button = document.getElementById(id);						// the state and changes the style either off or on	
		if (state == "off") { 
			button.className = sclBtnClassOff;
			button.setAttribute("class", sclBtnClassOff); 
		} else if  (state == "on") {
			button.className = sclBtnClassOn;
			button.setAttribute("class", sclBtnClassOn);
		}
	 }		
	   
	  
	 // ******************************** Animate ********************************
	 function animate(s,d) {
	 	//alert("s="+s);
		//alert("currentSL="+currentSL);
																		// Move according to which scroll button clicked
																		// Increment/decrement currentPane tracker and
																		// set indicator state
	   	  if (d == "l" && currentSL < 0) { 
		  	currentSL = 0;
			currentPane--; 
			setIndicatorState(currentPane);			
		  } else if (d == "l" && currentSL > 0) {
		    var move = s + currentSL; 
			currentSL = move; 
			currentPane--; 
			setIndicatorState(currentPane);
		  } else if (d == "r") { 
		  	move = s + currentSL; 
			currentSL = move; 
			currentPane++; 
			setIndicatorState(currentPane);
		  } else if (!d) { move = s; }								// If no direction, then was click from indi button
		  																// move directly to specified amount
	 		
	  	  var attributes = {
		  	scroll: { to: [move, 0] }									// Scroll the container
	   	  };
	   	  var anim = new YAHOO.util.Scroll(viewerId, attributes, 0.5, YAHOO.util.Easing.easeOut);
		  																
		  if ((autoScrollOn === true) && (currentPane > tps_max)) {		// If Max pane reached and autoScroll is on
	        	stopInterval(autoScroll);								// wait for animation to complete then turn
				currentPane = 1;										// off autoScroll, reset currentPane to 1,
				anim.onComplete.subscribe(setToZero);					// set current indicator to the first one
	        	setIndicatorState("1");
		  }
		  anim.animate();			  
		  
	 	  return false;		
	 }
	 
  
 	 // ******************************** Reset Scroller to Zero ********************************	  
	 var setToZero = function() {
	      var el = this.getEl();
	      el.scrollLeft = 0;	
	 };
	  
	  
	 
	 // ******************************** Start Animation ********************************
	 function doAnimation(e,obj) {										// If scroll button clicked, run this function
		
		 var limit = obj.s * currentPane;	
		  
		  	  if (limit != max_width) {									// limit is not greater than the max width
		   	   // Start Animation										// run the animation and stop autoScroll
			   animate(obj.s,obj.d);
				
			   // Clear autoScroll
		 	   stopInterval(); 
		
		 }
		 YAHOO.util.Event.preventDefault(e);
		 return false;
	 }		  
	 
 
	// ********************************  Autostart ********************************
	function autoStart() {												// After page loads, start autoScroll function
		autoScroll = setInterval("animate(w,'r')",delayTime);	
	}		
	
	// ********************************  Stop Autostart ********************************
	function stopInterval() {											// if autoScrollOn is true, then turn off autoScroll
		if (autoScrollOn === true) {
			clearInterval(autoScroll);
			autoScrollOn = false;
		}
	}
