/* Website Script - Custom ScrollBars
   Site.js - www.king-hamad.net
   Coded by: Monir Kh. Abu Hilal
             http://www.monirabuhilal.com/
			 monirabuhilal[at]gmail.com
			 monir_best[at]hotmail.com
 */




var slider;
var old_x = 0;
var old_y = 0;
			
function createScrollbar(content, scrollbar, handle, horizontal, ignoreMouse) {
	
	try {
	//change the opacity of scrollbars to transparent
		scrollbar.effect('opacity').set(0);
		handle.effect('opacity').set(0);
		
	//change the display of scrollbars.. visible
		scrollbar.setStyle("display", "");
		
		var sbEffect = scrollbar.effects({duration: 700, transition: Fx.Transitions.Sine.easeInOut});
		var sbHandleEffect = handle.effects({duration: 700, transition: Fx.Transitions.Sine.easeInOut});
		
		if (content.getSize().scrollSize.y - content.getSize().size.y > 0) {

			
			slider = new Slider(scrollbar, handle, {
				steps: 100,
				mode: (horizontal ? 'horizontal': 'vertical'),
				onChange: function(step) {
					//content.scrollTo(old_x, old_y);
					// Scrolls the content element in x or y direction.
					var x = (horizontal ? (((content.getScrollSize().x - content.getSize().x) / 100) * step) : 0);
					var y = (horizontal ? 0 : (((content.getSize().scrollSize.y - content.getSize().size.y) / 100) * step));
					content.scrollTo(x, y);
					old_x = x;
					old_y = 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) {
					//content.scrollTo(old_x, old_y);
					e = new Event(e).stop();
					var step = slider.step - e.wheel * 2;
					slider.set(step);
				});
			}
			// Stops the handle dragging process when the mouse leaves the document body.
			$(document.body).addEvent('mouseleave',
			function() {
				slider.drag.stop()
			});
			
			sbEffect.start({'opacity': 1});
			sbHandleEffect.start({'opacity': 1});
			
		} else{
			//sbEffect.start({'opacity': 1});
			//sbEffect.start({'opacity': 0});
		}
		
	} catch (e) {
		// Throw new exepition....
	}

}

window.addEvent('domready', function(){			
	try{
		createScrollbar( $('divScrollPage'), $('divScrollBar'), $('divScrollBarHandle'));
		//createScrollbar( $('divScrollPage'), $('divScrollBar'), $('divScrollBarHandle'),false ,true);
	} catch (e) {
		// Throw new exepition....
	}

});



