

// ==============================================================
// 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 = []; var wyglad= [];

function instantiateScroller(count, id, left, top, width, height, speed, schemat){
	wyglad[count]=schemat;
	if(document.getElementById) {
		theScroll[count] = new ypSimpleScroll(id, left, top, width, height, speed);
	}
	
}

function createDragger(count, handler, root, thumb, minX, maxX, minY, maxY){
		//alert(wyglad[0]);
		//var buttons = '<div class="up" id="up'+count+'"><a href="#" onmouseover="theScroll['+count+'].scrollNorth(\''+count+'\')" onmouseout="theScroll['+count+'].endScroll()" onclick="return false;"><img src="/java/TextScrollWith/up.gif" width="15" height="15"></a></div><div class="dn"  id="dn'+count+'""><a href="#" onmouseover="theScroll['+count+'].scrollSouth(\''+count+'\')" onmouseout="theScroll['+count+'].endScroll()" onclick="return false;"><img src="/java/TextScrollWith/dn.gif" width="15" height="15"></a></div><div class="thumb" id="'+thumb+'" style="left: 135px; top: 15px;"><img src="/java/TextScrollWith/thumb.gif" width="15" height="15"></div>';
		if (wyglad[count]==0) // strzalki
			var buttons = '<div class="up" id="up'+count+'"><a href="#" onmouseover="theScroll['+count+'].scrollNorth(\''+count+'\')" onmouseout="theScroll['+count+'].endScroll()" onclick="return false;"><img src="/tpl/images/pl_scrool_trojkat_top.png" /></a></div><div class="dn"  id="dn'+count+'""><a href="#" onmouseover="theScroll['+count+'].scrollSouth(\''+count+'\')" onmouseout="theScroll['+count+'].endScroll()" onclick="return false;"><img src="/tpl/images/pl_scrool_trojkat_down.png" /></a></div><div class="thumb" id="'+thumb+'" style="left: 135px; top: 15px;"></div>';
		if (wyglad[count]==1) // green thumb
			var buttons = '<div class="up" id="up'+count+'"></div><div class="dn"  id="dn'+count+'""></div><div class="thumb" id="'+thumb+'" style="left: 135px; top: 15px;"><img src="/tpl/images/pl_scrool_green_light.png" /></div>';
		if (wyglad[count]==2) // news thumb
			var buttons = '<div class="up" id="up'+count+'"></div><div class="dn"  id="dn'+count+'""></div><div class="thumb" id="'+thumb+'" style="left: 135px; top: 15px;"><img src="/tpl/images/pl_scrool_green_light.png" /></div>';
		if (wyglad[count]==3) // news thumb
			var buttons = '<div class="up" id="up'+count+'"></div><div class="dn"  id="dn'+count+'""></div><div class="thumb" id="'+thumb+'" style="left: 135px; top: 15px;"><img src="/tpl/default/images/scrool_grey.png" /></div>';
		if (wyglad[count]==4) // news thumb
			var buttons = '<div class="up" id="up'+count+'"></div><div class="dn"  id="dn'+count+'""></div><div class="thumb" id="'+thumb+'" style="left: 135px; top: 15px;"><img src="/tpl/default/images/scrool_grey.png" /></div>';
		if (wyglad[count]==5) // green thumb
			var buttons = '<div class="up" id="up'+count+'"></div><div class="dn"  id="dn'+count+'""></div><div class="thumb" id="'+thumb+'" style="left: 135px; top: 15px;"><img src="/tpl/images/pl_scrool_green_light.png" /></div>';
		if (wyglad[count]==6) // green thumb CENNIK
			var buttons = '<div class="up" id="up'+count+'"></div><div class="dn"  id="dn'+count+'""></div><div class="thumb" id="'+thumb+'" style="left: 135px; top: 15px;"><img src="/tpl/default/images/scrool_cennik.png" /></div>';
		

		document.getElementById(root).innerHTML = buttons + document.getElementById(root).innerHTML;

		theRoot[count]   = document.getElementById(root);
		theThumb[count]  = document.getElementById(thumb);
		var thisup = document.getElementById("up"+count);
		var thisdn = document.getElementById("dn"+count);
		if (wyglad[count]==0) {// strzalki
			theThumb[count].style.left = parseInt(minX-150) + "px";
			thisup.style.left = parseInt(minX-150) + "px";
			thisdn.style.left = parseInt(minX-150) + "px";
		}
		if (wyglad[count]==1) {// pointery
			theThumb[count].style.left = parseInt(minX+8) + "px";
			thisup.style.left = parseInt(minX+8) + "px";
			thisdn.style.left = parseInt(minX+8) + "px";
		}
		if (wyglad[count]==2) {// pointery
			theThumb[count].style.left = parseInt(minX+8) + "px";
			thisup.style.left = parseInt(minX+8) + "px";
			thisdn.style.left = parseInt(minX+8) + "px";
		}
		if (wyglad[count]==3) {// pointery
			theThumb[count].style.left = parseInt(minX+8) + "px";
			thisup.style.left = parseInt(minX+8) + "px";
			thisdn.style.left = parseInt(minX+8) + "px";
		}
		if (wyglad[count]==4) {// pointery
			theThumb[count].style.left = parseInt(minX-1) + "px";
			thisup.style.left = parseInt(minX-1) + "px";
			thisdn.style.left = parseInt(minX-1) + "px";
		}
		if (wyglad[count]==5) {// pointery
			theThumb[count].style.left = parseInt(minX-6) + "px";
			thisup.style.left = parseInt(minX-6) + "px";
			thisdn.style.left = parseInt(minX-6) + "px";
		}
		if (wyglad[count]==6) {// pointery
			theThumb[count].style.left = parseInt(minX-6) + "px";
			thisup.style.left = parseInt(minX-6) + "px";
			thisdn.style.left = parseInt(minX-6) + "px";
		}
		theThumb[count].style.border =0;
		theThumb[count].style.top = parseInt(minY) + "px";
		thisup.style.top = 0 + "px";
		thisdn.style.top = parseInt(minY+maxY) + "px";
		//thisdn.style.top = 15 + "px";

		theScroll[count].load();

		//Drag.init(theHandle[count], theRoot[count]); //not draggable on screen
		// ed: Drag.init(theThumb[count], null, minX+15, maxX+15, minY, maxY);
		if (wyglad[count]==0)
			Drag.init(theThumb[count], null, minX-150, maxX-150, minY, maxY);
		if (wyglad[count]==1)
			Drag.init(theThumb[count], null, minX+8, maxX+8, minY, maxY);
		if (wyglad[count]==2)
			Drag.init(theThumb[count], null, minX+8, maxX+8, minY, maxY);
		if (wyglad[count]==3)
			Drag.init(theThumb[count], null, minX+8, maxX+8, minY, maxY);
		if (wyglad[count]==4)
			Drag.init(theThumb[count], null, minX-1, maxX-1, minY, maxY);
		if (wyglad[count]==5)
			Drag.init(theThumb[count], null, minX-6, maxX-6, minY, maxY);
		if (wyglad[count]==6)
			Drag.init(theThumb[count], null, minX-6, maxX-6, minY, maxY);
		
		// 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]));
		}
}	

// 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) {
		for(var i=0;i<theScroll.length;i++){
			createDragger(i, "handle"+i, "root"+i, "thumb"+i, theScroll[i].clipW, theScroll[i].clipW, 15, theScroll[i].clipH-30);
		}
	}
}) 