// ==============================================================
// 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 str_savecount;
var str_saveid;
var str_saveleft;
var str_savetop;
var str_savewidth;
var str_saveheight;
var str_savespeed;




function instantiateScroller(count, id, left, top, width, height, speed){
	str_savecount=count
	str_saveid=id
	str_saveleft=left
	str_savetop=top
	str_savewidth=width
	str_saveheight=height
	str_savespeed=speed

	if(document.getElementById) {		
	
		theScroll[count] = new ypSimpleScroll(id, left, top, width, height, speed);
	}
}

function reinstantiateScroller(){
	
	count = str_savecount;
	id= str_saveid;
	left= str_saveleft;
	top= str_savetop;
	width= str_savewidth;
	height= str_saveheight;
	speed= str_savespeed;

	if(document.getElementById) {		
	
		theHandle = []; 
		theRoot = []; 
		theThumb = []; 
		theScroll = []; 
		thumbTravel = []; 
		ratio = [];	
		
		theScroll[count] = new ypSimpleScroll(id, left, top, width, height, speed);
		
		
	}
}

function createDragger(count, handler, root, thumb, minX, maxX, minY, maxY){
		
		if (!bln_draggersinitted){
				
			var buttons = '<div class="content'+count+'scrollbar"></div>'+
						  '<div class="up" id="up'+count+'">'+
						  '<a href="#" onmouseover="theScroll['+count+'].scrollNorth(\''+count+'\')" '+
						  'onmouseout="theScroll['+count+'].endScroll()" onclick="return false;">'+
						  '<img src="'+href+'images/scrollUp1.gif" width="10" height="9"></a></div>'+
						  '<div class="dn"  id="dn'+count+'"">'+
						  '<a href="#" onmouseover="theScroll['+count+'].scrollSouth(\''+count+'\')" '+
						  'onmouseout="theScroll['+count+'].endScroll()" onclick="return false;">'+
						  '<img src="'+href+'images/scrollDn1.gif" width="10" height="9" style="margin-top: 13px;"></a></div>'+
						  '<div class="thumb" id="'+thumb+'" style="left: 135px; top: 15px;">'+
						  '<img src="'+href+'images/thumb1.gif" width="10" height="14"></div>';
			
			
			var str_inner = document.getElementById(root).innerHTML;
			str_inner = str_inner.split("src=\"http://three.mettromagic.com/GUI").join("__giusrc__");
			str_inner = str_inner.split("src=\"").join("src=\"" + href);
			str_inner = str_inner.split("__giusrc__").join("src=\"http://three.mettromagic.com/GUI");
			document.getElementById(root).innerHTML = buttons + str_inner;
	
	
			
	
			theRoot[count]   = document.getElementById(root);
			theThumb[count]  = document.getElementById(thumb);
			
			
			
		
		
			var thisup = document.getElementById("up"+count);
			var thisdn = document.getElementById("dn"+count);
			theThumb[count].style.left = parseInt(minX+15) + "px";
			thisup.style.left = parseInt(minX+15) + "px";
			thisdn.style.left = parseInt(minX+15) + "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";
			
			
			
		}	

		theScroll[count].load();
		Drag.init(theThumb[count], null, minX+15, maxX+15, minY, maxY+8);
		thumbTravel[count] = theThumb[count].maxY - theThumb[count].minY;
		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]));
		}
		if (bln_draggersinitted){
			theScroll[count].scroll(0,count)
		}
		bln_draggersinitted = true; 
		
}	


function e(id){return document.getElementById(id);}
var bln_draggersinitted = false;


function addDraggers(){
	
	if(theScroll.length>0) {
		for(var i=0;i<theScroll.length;i++){
			var clipH = 0;   

				var contentHeight = Math.max(e("scroll"+i+"Content").offsetHeight, clipH);
				var containerHeight = Math.max(e("scroll"+i+"Container").offsetHeight, clipH);
	
				if (contentHeight > containerHeight) {
					
					if (e("content0scrollbar")) {
						e("content0scrollbar").style.visibility="visible";
					}
					if (e("up0")) {
						e("up0").style.visibility="visible";	
					}
					if (e("dn0")) {
						e("dn0").style.visibility="visible";	
					}
					if (e("thumb0")) {
						e("thumb0").style.visibility="visible";	
					}
					
					//bln_draggersinitted = true;
					createDragger(i, "handle"+i, "root"+i, "thumb"+i, theScroll[i].clipW, theScroll[i].clipW, 9, theScroll[i].clipH-30);
				}
				else {
					
					if (e("scrollContainer-expand")) {
						if (e("content0scrollbar")) {
							e("content0scrollbar").style.visibility="hidden";
						}
						if (e("up0")) {
							e("up0").style.visibility="hidden";	
						}
						if (e("dn0")) {
							e("dn0").style.visibility="hidden";	
						}
						if (e("thumb0")) {
							e("thumb0").style.visibility="hidden";	
						}
					}
				}
		}
		theScroll[0].scrollNorth(0, 16000 * 16000)
			
	} 
}
