	function clearText(thefield){if (thefield.defaultValue== thefield.value)	thefield.value = ""} 						
	function insertText(thefield){if ( thefield.value == "" )	thefield.value = thefield.defaultValue} 						

var submenuSlider;
var ssCounter = 0;
var timer     = 0;



function makeScrollbar(content, scrollbarfull, horizontal, ignoreMouse){
	var scrollbar = scrollbarfull.getElements('.handle-space').getLast();
	var handle = scrollbar.getElements('.handle').getLast();
	var handle1 = scrollbarfull.getElements('.handle-up').getLast();
	var handle2 = scrollbarfull.getElements('.handle-down').getLast();
	
	
	if (!scrollbar || !handle) return false;
	
	var steps, handleSize;
	if (horizontal) {
		steps = content.getScrollSize().x - content.getSize().x;
		handleSize = (content.getSize().x / content.getScrollSize().x) * scrollbar.getSize().x;
		style = 'width';
	} else {
		steps = content.getScrollSize().y - content.getSize().y;
		handleSize = (content.getSize().y / content.getScrollSize().y) * scrollbar.getSize().y;
		style = 'height';
	}
	
	if (steps<5) {
 		handle.setStyle('display', 'none');
		return;
	}

	handle.setStyle(style, (handleSize < 10 ? 10:handleSize)+'px');
	var interval = 0;
	
	
	var slider = new Slider(scrollbar, handle, {	
		steps: steps,
		mode: (horizontal?'horizontal':'vertical'),
		onChange: function(step){
			// Scrolls the content element in x or y direction.
			var x = (horizontal?step:0);
			var y = (horizontal?0:step);
			content.scrollTo(x,y);
		}
	}).set(0);
	if( !(ignoreMouse) ){
		// Scroll the content element when the mousewheel is used within the 
		// content or the scrollbar element.
		$$(content, scrollbar).addEvent('mousewheel', function(e){	
			e = new Event(e).stop();
			var step = slider.step - e.wheel * 30;	
			slider.set(step);					
		});
		
		if (handle1) {
			handle1.addEvent('mousedown', function(e) {
				e.stop(); interval = setInterval(function(){slider.set(slider.step - 15)}, 50);
			});
			handle1.addEvent('mouseup', function(e) {
				e.stop(); clearInterval(interval);
			});
		}
		
		if (handle2) {
			handle2.addEvent('mousedown', function(e) {
				e.stop(); interval = setInterval(function(){slider.set(slider.step + 15)}, 50);
			});
			handle2.addEvent('mouseup', function(e) {
				e.stop(); clearInterval(interval);
			});
		}
	}
	// Stops the handle dragging process when the mouse leaves the document body.
	$(document.body).addEvent('mouseleave',function(){slider.drag.stop()});
}


window.addEvent('domready', function() {

	var main, scrollb;
	
	
	if (typeof jQuery != 'undefined') {
		main = $('#main')[0];
		scrollb = $('#scrollbar')[0];
	} else {
		main = $('main');
		scrollb = $('scrollbar');
	}
	
	var x = new Element(main);
	var y = new Element(scrollb);

	if (main && scrollb && scrollb.nodeName && scrollb.nodeName.toUpperCase()=='DIV') {
		makeScrollbar( main, scrollb );
	}

});





