	function addEvent(obj, ev, fn)
	{
		try
		{
			if (obj.attachEvent)
				obj.attachEvent('on'+ev, fn);
			else
				obj.addEventListener(ev, fn, true);
		}
		catch(ex)
		{
	//		alert(ex);
		}
	}	

	function moveup()
	{
		isScrolling = true;
		move(moveBy);
	}
	
	function movedown()
	{
		isScrolling = true;
		move(-moveBy);
	}

	function wheelup()
	{
		isScrolling = false;
		move(moveBy);
	}
	
	function wheeldown()
	{
		isScrolling = false;
		move(-moveBy);
	}
	
	function stopmove()
	{
		isScrolling = false;
	}
	
	function move(val)
	{
		newPos = currentPos + val;
		//alert(maxheight);
		//$('txtOutput').innerHTML = maxheight + ':' +currentPos+ ':' +newPos;
		if ((newPos > (maxheight - Math.abs(val))) && (newPos <= 0)) 
		{
			currentPos = newPos;
			$(innerElement).style.top = currentPos + 'px';
			//$('txtOutput').innerHTML = maxheight + ':' +currentPos;
			//$('txtOutput').innerHTML += '*'; 
		}
		
		if (isScrolling)
		{
			setTimeout('move('+ val + ')', 50);
		}
	}

	var maxheight;
	var inHeight, outHeight;
	var innerElement = 'pnlContent';
	var outerElement = 'contentHtml';
	var scrollbarElement = 'scrollbar';
	var moveBy = 10;
	var currentPos = 0;
	var isScrolling = false;

	function getHeight(element)
	{
		var o = Element.getStyle(element, 'height');
		if (o == null)
		{
			return $(element).offsetHeight;			
		}
		else
		{
			return parseInt(o.match(/^\d*/i));
		}
		return null;
	}
	
	function getWidth(element)
	{
		var o = Element.getStyle(element, 'width');
		if (o == null)
		{
			return $(element).offsetWidth;			
		}
		else
		{
			return parseInt(o.match(/^\d*/i));
		}
		return null;
	}

	function getLeft(element)
	{
		var o = Element.getStyle(element, 'left');
		if (o == null)
		{
			return $(element).offsetLeft;			
		}
		else
		{
			return parseInt(o.match(/^\d*/i));
		}
		return null;
	}

	function getTop(element)
	{
		var o = Element.getStyle(element, 'top');
		if (o == null)
		{
			return $(element).offsetTop;			
		}
		else
		{
			return parseInt(o.match(/^\d*/i));
		}
		return null;
	}

	function SetStyleElement(element, attr, value)
	{
		var head = document.getElementsByTagName('head')[0];
		var style = document.createElement('style');
		style.media = 'screen';
		head.appendChild(style);
		var ns = document.styleSheets[document.styleSheets.length - 1];
		if (typeof(ns.addRule) == "undefined")
		{
			style.innerHTML = '#'+element.id+' {'+attr+': '+value+';}'; 
		}
		else
		{
			ns.addRule('#'+element.id, attr+': '+value);
		}
	}

	function init()
	{
		//addEvent($('btn'), 'click', move);
		
		//var elm = window.Element;
		//alert(elm);
		/*var bg = Element.getStyle('main', 'position');
		if ((bg != 'absolute'))
			return;*/
		//alert(innerElement);

		addEvent(window, 'DOMMouseScroll', wheel);
		window.onmousewheel = document.onmousewheel = wheel;

		var outHeight = getHeight(outerElement);
		var outTop = getTop(outerElement);
		
		var scrollbar = $(scrollbarElement);
		if (scrollbar != null)
		{
			SetStyleElement(scrollbar, 'height', outHeight + 'px');
			SetStyleElement(scrollbar, 'top', outTop + 'px');
			//scrollbar.style.height = outHeight + 'px';
			outWidth = getWidth(outerElement);
			scrollWidth = getWidth(scrollbarElement);
			if ((outWidth != null) && (scrollWidth != null))
			{
				//alert(scrollWidth);
				SetStyleElement($(outerElement), 'width', (outWidth - scrollWidth) + 'px');
				//$(outerElement).style.width = (outWidth - scrollWidth) + 'px';

				oleft = getLeft(outerElement);
				//scrollbar.style.left = (oleft + outWidth - scrollWidth) + 'px';
				SetStyleElement(scrollbar, 'left', (oleft + outWidth - scrollWidth) + 'px');
//				scrollbar.style.left = (oleft + outWidth - scrollWidth) + 'px';
				//scrollbar.style.left = (oleft) + 'px';
				//alert(oleft);
				//$(outerElement).style.clip = 'rect(0px '+outWidth+'px '+outHeight+'px 0px);';
			}
			
		}

		var inHeight = getHeight(innerElement);
		if (inHeight <= outHeight)
			return;

		addEvent($('arrowup'), 'mousedown', moveup );
		addEvent($('arrowdown'), 'mousedown', movedown);
		addEvent($('arrowup'), 'mouseup', stopmove);
		addEvent($('arrowdown'), 'mouseup', stopmove);
		addEvent($('arrowdown'), 'mouseout', stopmove);
		addEvent($('arrowdown'), 'mouseout', stopmove);

		if (scrollbar != null)
			SetStyleElement(scrollbar, 'visibility', 'visible');
			//scrollbar.style.visibility = 'visible';
		maxheight = outHeight - inHeight;
		SetStyleElement($(outerElement), 'overflow', 'hidden');
//		$(outerElement).style.overflow = 'hidden';
	}
	
	function handle(obj, delta)
	{
		if (obj.id != innerElement)
		{
			obj = findParentElement(obj, innerElement);
		}

		if (obj != null)
		{ 
		
			if (obj.id == innerElement)
			{
		        if (delta < 0)
		        {
		        	wheeldown();
		        }
		        else
		        {
					wheelup();
				}
				return true;
			}
		}
		
		return false;
	}
	
	function findParentElement(obj, idToFind)
	{
		//alert(idToFind);
		while(obj.id != idToFind)
		{
			obj = obj.parentNode;
			
			if (obj.tagName.toLowerCase() == 'body')
				return null;
		}

		return obj;
	}
	
	function wheel(event)
	{
		var delta = 0;
        if (!event) /* For IE. */
			event = window.event;
        if (event.wheelDelta)
		{ /* IE/Opera. */
			delta = event.wheelDelta/120;
			/** In Opera 9, delta differs in sign as compared to IE.
			 */
			if (window.opera)
			        delta = -delta;
        }
		else if (event.detail)/** Mozilla case. */
		{ 
                /** In Mozilla, sign of delta is different than in IE.
                 * Also, delta is multiple of 3.
                 */
			delta = -event.detail/3;
        }
        /** If delta is nonzero, handle it.
         * Basically, delta is now positive if wheel was scrolled up,
         * and negative, if wheel was scrolled down.
         */
		var target = (typeof(event.target) == 'undefined') ? event.srcElement :  event.target;

         
        if ((typeof(delta) != 'undefined') && (handle(getElement(target), delta)))
        {
	        /** Prevent default actions caused by mouse wheel.
	         * That might be ugly, but we handle scrolls somehow
	         * anyway, so don't bother here..
	         */
	        if (event.preventDefault)
    	    	event.preventDefault();
		
			event.returnValue = false;
		}
	}
	
	function getElement(node)
	{
		if (typeof(node.nodeType) != 'undefined')
		{
			while (node.nodeType != 1)//ELEMENT_NODE
			{
				node = node.parentNode;
			}
			//alert(node.parentNode.nodeType);
		}
		return node;
	}

	addEvent(window, 'load', init);
	
	//alert('finidh');

