/*
 * Copyright (c) 2008, Aleajecta
 * All rights reserved.
 * 
 * The Service and any necessary software used in connection with the 
 * Service ("Software") contain proprietary and confidential information 
 * that is protected by applicable intellectual property and other laws.
 * You agree not to modify, rent, lease, loan, sell, distribute or create
 * derivative works based on the Service or the Software, in whole or in part.
 */
/**
 * @author Greenseed
 */
function Scroll(){}(function()
{
    Scroll.eleUp = null;
    Scroll.eleDown = null;

    var ScrollMe = "";
    var TimeOutID = 0;
    var Handle = function(delta)
    {
    	if(ScrollMe)
        {
            ScrollMe.scrollTop = ScrollMe.scrollTop + delta * 20;
            return;
        }
        delta *= 50;
    	if (delta > 0)
    		window.scrollBy(0,delta);
    	else
    		window.scrollBy(0,delta);
    };
    Scroll.autoScrollTarget = null;
    Scroll.autoScroll = function()
    {
        if(!ScrollMe)
    		return;
        
    	var speed = Mouse.offSetHeight(this)/400;
        //alert(speed)
        if(this.id == 'scrollUp') 
    	{
    		speed = 0.25 - speed;
            speed = speed < 0 ? 0 : speed;
    		Handle(-speed);
    	}
    	else 
    		Handle(speed);

        if(!this.mouseReallyOut(7))
        {
            if(moronIE)
            {
               var ieScrapmemoryLost = this;
               TimeOutID = setTimeout(function(){ieScrapmemoryLost.onmouseover()},10); 
            }
            else
            {
                TimeOutID = setTimeout(function(owner){owner.onmouseover()},10,this);
            }
        }
    };
    Scroll.wheel = function(event)
    {
    	var delta = 0;

    	if(!event) //Fix For Moron
    		event = window.event;

    	if (event.wheelDelta)  //Opera
    		delta = -(event.wheelDelta/120);
    	else if (event.detail) //Mozilla case.
    		delta = event.detail/3;

    	if(delta < 0)
    	{
    		Scroll.eleUp.className = "scrollActive";
    		TimeOutID[0] = setTimeout("Scroll.eleUp.className = ''",200);
    		Handle(delta);
    	}
    	else if( delta > 0)
    	{
    		Scroll.eleDown.className = "scrollActive";
    		TimeOutID[1] = setTimeout("Scroll.eleDown.className = ''",200);
    		Handle(delta);
    	}

    	//Disable Normal Scroll Function
    	//if(owner.preventDefault)
    		//owner.preventDefault();
    
    	//owner.returnValue = false;
    }
    Scroll.setScrollMe = function(owner)
    {
        if(owner != ScrollMe)
            ScrollMe = owner;
    };
    Scroll.unSetScrollMe = function()
    {
        ScrollMe = "";
    };
})();

userInit.push
(
	function()
	{
		Scroll.eleDown = GetElementById('scrollDown');
		Scroll.eleUp = GetElementById('scrollUp');

        Scroll.eleDown.onmouseover = Scroll.autoScroll;
        Scroll.eleUp.onmouseover = Scroll.autoScroll;

		if(window.addEventListener) //Only Firefox,Netscape
		{
			window.addEventListener('DOMMouseScroll', Scroll.wheel, false);
			//parent.window.addEventListener('DOMMouseScroll', wheel, false);
		}
		//Moron, Opera 
		window.onmousewheel = document.onmousewheel = Scroll.wheel;
		
        //parent.window.onmousewheel = parent.document.onmousewheel = Scroll.wheel;
	}
);
