//alert(navigator.userAgent);
var steps = 0;
var slider = {};
var mxScroll = new Class({
						 
	initialize: function(div, div_content, horizontal){
		$("scrollbar").style.display = "none";
		this.createScroll(div, div_content, horizontal);
		this.onResize(div, div_content, horizontal);
	},
	onResize: function(div, div_content, horizontal){
		window.addEvent("resize", function(){
			if(window.ie6){
				$(div).style.height = ($(div_content).offsetHeight*0.97)+"px";
			}else{
				$(div).style.height = ($(div_content).offsetHeight)+"px";
			}
			$("scrollbar").style.height = $(div).offsetHeight+"px";
			
			if(($(div).scrollHeight - $(div).offsetHeight) > 0){
				slider.set(0);
				$('handle').style.top="0px";
				steps = (horizontal?($(div).scrollWidth.x - $(div).offsetWidth):($(div).scrollHeight - $(div).offsetHeight));
				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);
						$(div).scrollTo(x,y);
					}
				}).set(0);
			}
		});
	},
	createScroll: function(div, div_content, horizontal){
		if(window.ie6){
			$(div).style.height = ($(div_content).offsetHeight*0.97)+"px";
		}else{
			$(div).style.height = ($(div_content).offsetHeight)+"px";
		}
		$("scrollbar").style.height = $(div).offsetHeight+"px";
		
		if(($(div).scrollHeight - $(div).offsetHeight) > 0){
			$('scrollbar').style.display = "";
			$('handle').style.display = "";
			steps = (horizontal?($(div).scrollWidth.x - $(div).offsetWidth):($(div).scrollHeight - $(div).offsetHeight));
			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);
					$(div).scrollTo(x,y);
				}
			}).set(0);
			$$("scrollbar").addEvent('mousewheel', function(e){	
					e = new Event(e).stop();
					var step = slider.step - e.wheel * 30;	
					slider.set(step);					
			});
			$(div).addEvent('mousewheel', function(e){															   
					e = new Event(e).stop();
					var step = slider.step - e.wheel * 30;	
					
					slider.set(step);					
			});
			$(div_content).addEvent('mousewheel', function(e){															   
					e = new Event(e).stop();
					var step = slider.step - e.wheel * 30;	
					
					slider.set(step);					
			});
			$(document.body).addEvent('mouseleave',function(){slider.drag.stop()});
		}else{
			$('scrollbar').style.display = "none";
			$('handle').style.display = "none";
		}
	}
});