var scrolling=0;

function getState(which) {
	if (document.getElementById(which).style.display == "block") {
		return 0;
	} else {
		return 1;
	}
}
var initList = new Array();
function toggleMenu(img, imgName, which) {
	if (document.getElementById('scrollObject'+which).style.display == "block") {
		img.src =  imgName + "_of.gif";
		document.getElementById('scrollObject'+which).style.display = "none";
		document.getElementById('subnav').style.display = "block";
	} else {
		img.src = imgName + ".gif";
		document.getElementById('scrollObject'+which).style.display = "block";
		document.getElementById('subnav').style.display = "none";
		if(!initList[which])
		{
			initList[which] = true;
			scroller.init(which);
		}
	}
}
			
function hideMenu(img, imgName, which) {
	if (document.getElementById('scrollObject'+which).style.display == "block") {
		document.getElementById('scrollObject'+which).style.display = "none";
		img.src = imgName + "_of.gif";
	}
}
			
var scroller = {
	obj : null,
	init: function(which) {
	    //collect the variables
		scroller.docH = document.getElementById("scrollContent"+which).offsetHeight;
		if(scroller.docH <= 190) {
			document.getElementById("scrollWrap"+which).style.visibility = "hidden";
		}
		
		// fixed height
		scroller.scrollDist = 150;
		scroller.contH = 180;
		scroller.scrollAreaH = 115;
		
	    //make the scroller div draggable
	    Drag.init(document.getElementById("scroller"+which),null,0,0,-1,scroller.scrollDist);
	    
	    //add ondrag function
	    document.getElementById("scroller"+which).onDrag = function (x,y) {
			docH  = document.getElementById("scrollContent"+which).offsetHeight;
			var scrollY = parseInt(document.getElementById("scroller"+which).style.top);
			var docY = 0 - (scrollY * (docH - scroller.contH) / scroller.scrollDist);
			document.getElementById("scrollContent"+which).style.top = docY + "px";
		}
    },
		
	//Smooth scrolling
	scrollIt: function (which, sc) {
		if (scrolling==1) {
			var scrollY = parseInt(document.getElementById("scroller"+which).style.top);
			if (sc < 0 ) { 
				if (scrollY >= -1 && scrollY < scroller.scrollDist ) {
					scrollY -= sc;
				}
			} else {
				if (scrollY >= 1) {
					scrollY -= sc; 
				}
			}
			
			docH = document.getElementById("scrollContent"+which).offsetHeight
			
			var docY = 0 - (scrollY * (docH - scroller.contH) / scroller.scrollDist);
			document.getElementById("scrollContent" + which).style.top = docY + "px";
			document.getElementById("scroller" + which).style.top = scrollY + "px";
			//setTimeout("document.getElementById('scroller" + which + "').scrollIt("+ sc +");", 30);
			setTimeout("scroller.scrollIt('"+ which + "'," +  sc +");", 30);
			
			
		}
	}
};


