	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 present() {
// 		submenuSlider.options.link = 'chain';

// 		submenuSlider.slideIn();
		submenuSlider.slideOut();
// 		submenuSlider.addEvent('complete', function(e) {
// 			ssCounter ++;
// 			if (ssCounter == 2) submenuSlider.options.link = 'cancel';
// 		});
}

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) {
		scrollbarfull.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()});
}

function onShowContent(e) {
	e.stop();
	if (timer) clearTimeout(timer);
	timer = setTimeout("$('content').fade(1);timer=0;", 100);
}

function onHideContent(e) {
	e.stop();
	if (timer) clearTimeout(timer);
	timer = setTimeout("$('content').fade(0);timer=0;", 500);
}

function onShowSubMenu(e) {
	e.stop();
	if(timer) { clearTimeout(timer); timer = 0; }
	submenuSlider.slideIn();
}

function onHideSubMenu(e) {
	e.stop();
	if(timer) { clearTimeout(timer); timer = 0; }
	submenuSlider.slideOut();
}

window.addEvent('domready', function() {
	if ($('submenu')) {
		submenuSlider = new Fx.Slide('submenu', {mode: 'horizontal', offOffset: 35, duration: 2000, link: 'cancel'}); 

		$('submenu').addEvent('mouseenter', onShowSubMenu);
		
		$('submenu').addEvent('mouseleave', onHideSubMenu);

		$('submenu').setStyle('display', 'block'); 
// 		submenuSlider.element.setStyle('margin-left', -(submenuSlider.element.offsetWidth - 35)+'px');
// 		submenuSlider.wrapper.setStyle('width', '35px');
		submenuSlider.wrapper.setStyle('z-index', '10');
		setTimeout('present()', 2000);
	}

	if ($('contentin') && $('contenthandle')) {
		makeScrollbar( $('contentin'), $('scrollbar') );

		$('content').setStyle('visibility', 'hidden');
		$('content').setStyle('opacity', '0');
		
		var timer = 0;
		$('contenthandle').addEvent('mouseenter', onShowContent);
		$('contenthandle').addEvent('mouseleave', onHideContent);
		$('content').addEvent('mouseenter', onShowContent);
		$('content').addEvent('mouseleave', onHideContent);
		$('contentmock').addEvent('mouseenter', onShowContent);
	}

});



// Fx.Slide = new Class({
// 
// 	Extends: Fx,
// 
// 	options: {
// 		mode: 'vertical',
// 		offOffset: 0
// 	},
// 
// 	initialize: function(element, options){
// 		this.addEvent('complete', function(){
// 			this.open = (this.wrapper['offset' + this.layout.capitalize()] != 0);
// 			if (this.open && Browser.Engine.webkit419) this.element.dispose().inject(this.wrapper);
// 		}, true);
// 		this.element = this.subject = $(element);
// 		this.parent(options);
// 		var wrapper = this.element.retrieve('wrapper');
// 		this.wrapper = wrapper || new Element('div', {
// 			styles: $extend(this.element.getStyles('margin', 'position'), {overflow: 'hidden'})
// 		}).wraps(this.element);
// 		this.element.store('wrapper', this.wrapper).setStyle('margin', 0);
// 		this.now = [];
// 		this.open = true;
// 	},
// 
// 	vertical: function(){
// 		this.margin = 'margin-top';
// 		this.layout = 'height';
// 		this.offset = this.element.offsetHeight-this.options.offOffset;
// 	},
// 
// 	horizontal: function(){
// 		this.margin = 'margin-left';
// 		this.layout = 'width';
// 		this.offset = this.element.offsetWidth-this.options.offOffset;
// 	},
// 
// 	set: function(now){
// 		this.element.setStyle(this.margin, now[0]);
// 		this.wrapper.setStyle(this.layout, now[1]);
// 		return this;
// 	},
// 
// 	compute: function(from, to, delta){
// 		return [0, 1].map(function(i){
// 			return Fx.compute(from[i], to[i], delta);
// 		});
// 	},
// 
// 	start: function(how, mode){
// 		if (!this.check(how, mode)) return this;
// 		this[mode || this.options.mode]();
// 		var margin = this.element.getStyle(this.margin).toInt();
// 		var layout = this.wrapper.getStyle(this.layout).toInt();
// 		var caseIn = [[margin, layout], [0, this.offset+this.options.offOffset]];
// 		var caseOut = [[margin, layout], [-this.offset, this.options.offOffset]];
// 		var start;
// 		switch (how){
// 			case 'in': start = caseIn; break;
// 			case 'out': start = caseOut; break;
// 			case 'toggle': start = (layout == this.options.offOffset) ? caseIn : caseOut;
// 		}
// 		return this.parent(start[0], start[1]);
// 	},
// 
// 	slideIn: function(mode){
// 		return this.start('in', mode);
// 	},
// 
// 	slideOut: function(mode){
// 		return this.start('out', mode);
// 	},
// 
// 	hide: function(mode){
// 		this[mode || this.options.mode]();
// 		this.open = false;
// 		return this.set([-this.offset, 0]);
// 	},
// 
// 	show: function(mode){
// 		this[mode || this.options.mode]();
// 		this.open = true;
// 		return this.set([0, this.offset]);
// 	},
// 
// 	toggle: function(mode){
// 		return this.start('toggle', mode);
// 	}
// 
// });




