

// ==============================================================
// HANDLES SCROLLER/S
// Modified from Aaron Boodman http://webapp.youngpup.net/?request=/components/ypSimpleScroll.xml
// mixed ypSimpleScroll with dom-drag script and allowed multiple scrolelrs through array instances
// (c)2004 Sergi Meseguer (http://zigotica.com/), 04/2004:
// ==============================================================
var theHandle = []; var theRoot = []; var theThumb = []; var theScroll = []; var thumbTravel = []; var ratio = [];

function instantiateScroller(count, id, left, top, width, height, speed){
	if(document.getElementById ) {		
		theScroll[count] = new ypSimpleScroll(id, left, top, width, height, speed);
	}
}

function createDragger(count, handler, root, thumb, minX, maxX, minY, maxY){	/*el scroll verd*/
		var buttons = '<div class="up" id="up'+count+'"><a href="#" onmouseover="theScroll['+count+'].scrollNorth(\''+count+'\')" onmouseout="theScroll['+count+'].endScroll()" onclick="return false;"><img src="/disseny/templates/plantilla_palluc_morat/images/FLECHASCROLL-ARRIBA.gif" ></a></div><div class="dn"  id="dn'+count+'""><a href="#" onmouseover="theScroll['+count+'].scrollSouth(\''+count+'\')" onmouseout="theScroll['+count+'].endScroll()" onclick="return false;"><img src="/disseny/templates/plantilla_palluc_morat/images/FLECHASCROLL-ABAJO.gif"></a></div><div class="thumb" id="'+thumb+'" style="left: 0px; top: 0px;"><img src="/disseny/templates/plantilla_palluc_morat/images/BARRA-SCROLL.gif" ></div>';
		
	try{	
		document.getElementById(root).innerHTML = buttons + document.getElementById(root).innerHTML;        
        
     /*l1 és l'espai de respecte 2*/
		theRoot[count]   = document.getElementById(root);		
		theThumb[count]  = document.getElementById(thumb);
		var thisup = document.getElementById("up"+count);
		var thisdn = document.getElementById("dn"+count);
		/*Açò afecta a la barra del scroll*/
		theThumb[count].style.left = parseInt(minX+11) + "px"; /*minX+8*/
		thisup.style.left = parseInt(minX+11) + "px";  				/*Posicion de la imagen up hacia la derecha*/
		thisdn.style.left = parseInt(minX+11) + "px";  				/*Posicion de la imagen dn hacia la derecha*/
		theThumb[count].style.border =0;
		theThumb[count].style.top = 0+23+ parseInt(minY) + "px";     /*48 es la posicion inicial de la barra scroll*/
		thisup.style.top = parseInt(minY) + "px";                             /*Posició inicial on comença el botó de pujar"*/
		thisdn.style.top = parseInt(maxY-60) + "px";
		
		//thisdn.style.top = 15 + "px";

		theScroll[count].load();

		//Drag.init(theHandle[count], theRoot[count]); //not draggable on screen
		/*48 es la posicion inicial de la barra scroll y -7 es la posicion final del scroll */
		/*Drag.init(theThumb[count], null, minX+marge dreta, maxX+marge dreta, minY+posició on comença l'scroll, maxY-longitud de la barra del scroll); */
		Drag.init(theThumb[count], null, minX+11, maxX+11, minY+23, maxY-140);  
		
		// the number of pixels the thumb can travel vertically (max - min)
		thumbTravel[count] = theThumb[count].maxY - theThumb[count].minY;

		// the ratio between scroller movement and thumbMovement
		ratio[count] = theScroll[count].scrollH / thumbTravel[count];

		theThumb[count].onDrag = function(x, y) {
			theScroll[count].jumpTo(null, Math.round((y - theThumb[count].minY) * ratio[count]));
		}
	}
	catch(error){}
}

function createDragger1(count, handler, root, thumb, minX, maxX, minY, maxY){	/*el scroll morat*/
		var buttons = '<div class="up" id="up'+count+'"><a href="#" onmouseover="theScroll['+count+'].scrollNorth(\''+count+'\')" onmouseout="theScroll['+count+'].endScroll()" onclick="return false;"><img src="/disseny/templates/plantilla_palluc_morat/images/FLECHASCROLL-ARRIBA.gif" ></a></div><div class="dn"  id="dn'+count+'""><a href="#" onmouseover="theScroll['+count+'].scrollSouth(\''+count+'\')" onmouseout="theScroll['+count+'].endScroll()" onclick="return false;"><img src="/disseny/templates/plantilla_palluc_morat/images/FLECHASCROLL-ABAJO.gif"></a></div><div class="thumb" id="'+thumb+'" style="left: 0px; top: 0px;"><img src="/disseny/templates/plantilla_palluc_morat/images/BARRA-SCROLL.gif" ></div>';
		
	try{	
		document.getElementById(root).innerHTML = buttons + document.getElementById(root).innerHTML;        
        
     /*l1 és l'espai de respecte 2*/
		theRoot[count]   = document.getElementById(root);		
		theThumb[count]  = document.getElementById(thumb);
		var thisup = document.getElementById("up"+count);
		var thisdn = document.getElementById("dn"+count);
		/*Açò afecta a la barra del scroll*/
		theThumb[count].style.left = parseInt(minX+11) + "px"; /*minX+8*/
		thisup.style.left = parseInt(minX+11) + "px";  				/*Posicion de la imagen up hacia la derecha*/
		thisdn.style.left = parseInt(minX+11) + "px";  				/*Posicion de la imagen dn hacia la derecha*/
		theThumb[count].style.border =0;
		theThumb[count].style.top = 0+23+ parseInt(minY) + "px";     /*48 es la posicion inicial de la barra scroll*/
		thisup.style.top = parseInt(minY) + "px";                             /*Posició inicial on comença el botó de pujar"*/
		thisdn.style.top = parseInt(maxY-60) + "px";
		
		//thisdn.style.top = 15 + "px";

		theScroll[count].load();

		//Drag.init(theHandle[count], theRoot[count]); //not draggable on screen
		/*48 es la posicion inicial de la barra scroll y -7 es la posicion final del scroll */
		/*Drag.init(theThumb[count], null, minX+marge dreta, maxX+marge dreta, minY+posició on comença l'scroll, maxY-longitud de la barra del scroll); */
		Drag.init(theThumb[count], null, minX+11, maxX+11, minY+23, maxY-140);  
		
		// the number of pixels the thumb can travel vertically (max - min)
		thumbTravel[count] = theThumb[count].maxY - theThumb[count].minY;

		// the ratio between scroller movement and thumbMovement
		ratio[count] = theScroll[count].scrollH / thumbTravel[count];

		theThumb[count].onDrag = function(x, y) {
			theScroll[count].jumpTo(null, Math.round((y - theThumb[count].minY) * ratio[count]));
		}
	}
	catch(error){}
}


function createDragger2(count, handler, root, thumb, minX, maxX, minY, maxY){	/*el scroll morat*/
		var buttons = '<div class="up" id="up'+count+'"><a href="#" onmouseover="theScroll['+count+'].scrollNorth(\''+count+'\')" onmouseout="theScroll['+count+'].endScroll()" onclick="return false;"><img src="/disseny/templates/plantilla_palluc_morat/images/FLECHASCROLL-ARRIBA.gif" ></a></div><div class="dn"  id="dn'+count+'""><a href="#" onmouseover="theScroll['+count+'].scrollSouth(\''+count+'\')" onmouseout="theScroll['+count+'].endScroll()" onclick="return false;"><img src="/disseny/templates/plantilla_palluc_morat/images/FLECHASCROLL-ABAJO.gif"></a></div><div class="thumb" id="'+thumb+'" style="left: 0px; top: 0px;"><img src="/disseny/templates/plantilla_palluc_morat/images/BARRA-SCROLL.gif" ></div>';
		
	try{	
		document.getElementById(root).innerHTML = buttons + document.getElementById(root).innerHTML;        
        
     /*l1 és l'espai de respecte 2*/
		theRoot[count]   = document.getElementById(root);		
		theThumb[count]  = document.getElementById(thumb);
		var thisup = document.getElementById("up"+count);
		var thisdn = document.getElementById("dn"+count);
		/*Açò afecta a la barra del scroll*/
		theThumb[count].style.left = parseInt(minX+11) + "px"; /*minX+8*/
		thisup.style.left = parseInt(minX+11) + "px";  				/*Posicion de la imagen up hacia la derecha*/
		thisdn.style.left = parseInt(minX+11) + "px";  				/*Posicion de la imagen dn hacia la derecha*/
		theThumb[count].style.border =0;
		theThumb[count].style.top = 0+23+ parseInt(minY) + "px";     /*48 es la posicion inicial de la barra scroll*/
		thisup.style.top = parseInt(minY) + "px";                             /*Posició inicial on comença el botó de pujar"*/
		thisdn.style.top = parseInt(maxY-60) + "px";
		
		//thisdn.style.top = 15 + "px";

		theScroll[count].load();

		//Drag.init(theHandle[count], theRoot[count]); //not draggable on screen
		/*48 es la posicion inicial de la barra scroll y -7 es la posicion final del scroll */
		/*Drag.init(theThumb[count], null, minX+marge dreta, maxX+marge dreta, minY+posició on comença l'scroll, maxY-longitud de la barra del scroll); */
		Drag.init(theThumb[count], null, minX+11, maxX+11, minY+23, maxY-140);  
		
		// the number of pixels the thumb can travel vertically (max - min)
		thumbTravel[count] = theThumb[count].maxY - theThumb[count].minY;

		// the ratio between scroller movement and thumbMovement
		ratio[count] = theScroll[count].scrollH / thumbTravel[count];

		theThumb[count].onDrag = function(x, y) {
			theScroll[count].jumpTo(null, Math.round((y - theThumb[count].minY) * ratio[count]));
		}
	}
	catch(error){}
}
function createDragger3(count, handler, root, thumb, minX, maxX, minY, maxY){	/*el scroll morat*/
		var buttons = '<div class="up" id="up'+count+'"><a href="#" onmouseover="theScroll['+count+'].scrollNorth(\''+count+'\')" onmouseout="theScroll['+count+'].endScroll()" onclick="return false;"><img src="/disseny/templates/plantilla_palluc_morat/images/FLECHASCROLL-ARRIBA.gif" ></a></div><div class="dn"  id="dn'+count+'""><a href="#" onmouseover="theScroll['+count+'].scrollSouth(\''+count+'\')" onmouseout="theScroll['+count+'].endScroll()" onclick="return false;"><img src="/disseny/templates/plantilla_palluc_morat/images/FLECHASCROLL-ABAJO.gif"></a></div><div class="thumb" id="'+thumb+'" style="left: 0px; top: 0px;"><img src="/disseny/templates/plantilla_palluc_morat/images/BARRA-SCROLL.gif" ></div>';
		
	try{	
		document.getElementById(root).innerHTML = buttons + document.getElementById(root).innerHTML;        
        
     /*l1 és l'espai de respecte 2*/
		theRoot[count]   = document.getElementById(root);		
		theThumb[count]  = document.getElementById(thumb);
		var thisup = document.getElementById("up"+count);
		var thisdn = document.getElementById("dn"+count);
		/*Açò afecta a la barra del scroll*/
		theThumb[count].style.left = parseInt(minX+11) + "px"; /*minX+8*/
		thisup.style.left = parseInt(minX+11) + "px";  				/*Posicion de la imagen up hacia la derecha*/
		thisdn.style.left = parseInt(minX+11) + "px";  				/*Posicion de la imagen dn hacia la derecha*/
		theThumb[count].style.border =0;
		theThumb[count].style.top = 0+23+ parseInt(minY) + "px";     /*48 es la posicion inicial de la barra scroll*/
		thisup.style.top = parseInt(minY) + "px";                             /*Posició inicial on comença el botó de pujar"*/
		thisdn.style.top = parseInt(maxY-60) + "px";
		
		//thisdn.style.top = 15 + "px";

		theScroll[count].load();

		//Drag.init(theHandle[count], theRoot[count]); //not draggable on screen
		/*48 es la posicion inicial de la barra scroll y -7 es la posicion final del scroll */
		/*Drag.init(theThumb[count], null, minX+marge dreta, maxX+marge dreta, minY+posició on comença l'scroll, maxY-longitud de la barra del scroll); */
		Drag.init(theThumb[count], null, minX+11, maxX+11, minY+23, maxY-140);  
		
		// the number of pixels the thumb can travel vertically (max - min)
		thumbTravel[count] = theThumb[count].maxY - theThumb[count].minY;

		// the ratio between scroller movement and thumbMovement
		ratio[count] = theScroll[count].scrollH / thumbTravel[count];

		theThumb[count].onDrag = function(x, y) {
			theScroll[count].jumpTo(null, Math.round((y - theThumb[count].minY) * ratio[count]));
		}
	}
	catch(error){}
}



// INITIALIZER:
// ==============================================================
// ala Simon Willison http://simon.incutio.com/archive/2004/05/26/addLoadEvent
function addLoadEvent(fn) {
      var old = window.onload;
      if (typeof window.onload != 'function') {
         window.onload = fn;
      }
      else {
         window.onload = function() {
         //old();
         fn();
         }
      }
}
addLoadEvent(function(){
		
		if(theScroll.length>0) {
		//alert('longitud de theScroll '+theScroll.length);
		for(var i=theScroll.length-1;i>=0;i--){
			//alert('i= '+i);
			/*13--- tope de baix on comença la imatge supose que té 10 per defecte més 13*/
			
			switch(i)
			{
				case 1:{
					//alert('el morat inicial');
					//alert('the Scroll['+i+']= '+theScroll[i].clipW);
					if(theScroll[i]==null)
					{
						theScroll[i]=theScroll[2];
					}
					
					createDragger1(i, "handle"+i, "root"+i, "thumb"+i, theScroll[i].clipW, theScroll[i].clipW, 0, theScroll[i].clipH-23);
						}break;
				case 2:{
					//alert('el morat Impiva');
					//alert('the Scroll['+i+']= '+theScroll[i].clipW);
					if(theScroll[2]!=null)
					{
					createDragger2(i, "handle"+i, "root"+i, "thumb"+i, theScroll[i].clipW, theScroll[i].clipW, 0, theScroll[i].clipH-23);}
						}break;
				case 3:{//alert('el vert del buscador');
				
					createDragger3(i, "handle"+i, "root"+i, "thumb"+i, theScroll[i].clipW, theScroll[i].clipW, 0, theScroll[i].clipH-23);}
					break;
				case 4:{createDragger(i, "handle"+i, "root"+i, "thumb"+i, theScroll[i].clipW, theScroll[i].clipW, 0, theScroll[i].clipH-23);}
					break;
				case 5:{createDragger(i, "handle"+i, "root"+i, "thumb"+i, theScroll[i].clipW, theScroll[i].clipW, 0, theScroll[i].clipH-23);}
					break;
				case 0:{
					//alert('el vert');
					//alert('the Scroll['+i+']= '+theScroll[i].clipW);
					if(theScroll[i]==null)
					{
						theScroll[i]=theScroll[2];
					}
					
					createDragger(i, "handle"+i, "root"+i, "thumb"+i, theScroll[i].clipW, theScroll[i].clipW, 0, theScroll[i].clipH-23);
					}break;
			}						
		}
		
	}
	
}) 