﻿var ebloc = function ()
{
}

ebloc.pageLoad = function ()
{
    ebloc.insertExternalLinks();
    ebloc.insertTitleAttributes();
    ebloc.insertBoxLinks();
    ebloc.insertBoxLinkSiblings();
};

ebloc.insertExternalLinks = function ()
{
    $("a[rel=external]").attr("target", "_blank");
};

ebloc.insertTitleAttributes = function ()
{
    $("img[alt]").each
    (
        function (index, element)
        {
            element.setAttribute("title", element.getAttribute("alt"));
        }
    );
};

ebloc.insertBoxLinks = function (parent)
{
    if (!parent)
    {
        parent = $("body");
    }
    else
    {
        parent = $(parent);
    }    

    var boxLinks = $(".boxLink", parent[0]);

    boxLinks.each
    (
        function (index, element)
        {
            if ($("a[href]", element).length > 0)
            {
                element.style.cursor = "pointer";
            }
        }
    );

    boxLinks.click
    (
        function ()
        {
            if (this.tagName.toLowerCase() != "a")
            {
                var link = $("a[href]", this)[0];
                var linkUrl = link.getAttribute("href");

                if (link.getAttribute("rel") == "external")
                {
                    window.open(linkUrl);
                }
                else
                {
                    window.location = linkUrl;
                }

                return false;
            }
        }
    );
}

ebloc.insertBoxLinkSiblings = function (parent)
{
    if (!parent)
    {
        parent = $("body");
    }
    else
    {
        parent = $(parent);
    }    

    var boxLinks = $(".boxLinkSibling", parent[0]);

    boxLinks.each
    (
        function (index, element)
        {
            if ($("a[href]", element.parentNode).length > 0)
            {
                element.style.cursor = "pointer";
            }
        }
    );

    boxLinks.click
    (
        function ()
        {
            if (this.tagName.toLowerCase() != "a")
            {
                var link = $("a[href]", this.parentNode)[0];
                var linkUrl = link.getAttribute("href");

                if (link.getAttribute("rel") == "external")
                {
                    window.open(linkUrl);
                }
                else
                {
                    window.location = linkUrl;
                }

                return false;
            }
        }
    );
}

ebloc.initJsonReaders = function (numberOfItems)
{
    $("*[json]").each
    (
        function (index, element)
        {
            var jsonUrl = element.getAttribute("json");

            if (jsonUrl.indexOf("?") == -1)
            {
                jsonUrl += "?";
            }
            else
            {
                jsonUrl += "&";
            }

            jsonUrl += "callback=?";

            var template = $(".template", element)[0].cloneNode(true);

            $.ajax
		    (
                {
                    url: jsonUrl,
                    crossDomain: true,
                    dataType: "json",
                    success: function (data)
                    {
                        $(element).animate
                        (
                            {
                                opacity: 0.0
                            },
                            250,
                            "swing",
                            function ()
                            {
                                while (element.childNodes.length > 0)
                                {
                                    element.removeChild(element.childNodes[0]);
                                }
                                
                                for (var index = 0; index < data.length && index < numberOfItems; ++index)
                                {
                                    var text = data[index].text;
                                    var date = data[index].created_at;
                                    var name = data[index].user.name;

                                    date = ebloc.convert.twitterDateToLongDate(date, ".", ":", " ")

                                    var item = template.cloneNode(true);

                                    element.appendChild(item);
                                    item = element.childNodes[element.childNodes.length - 1];

                                    item.innerHTML = item.innerHTML.replace("-index-", index);
                                    item.innerHTML = item.innerHTML.replace("-date-", date);
                                    item.innerHTML = item.innerHTML.replace("-text-", ebloc.insertAnchorLinks(text, false));
                                    item.innerHTML = item.innerHTML.replace("-name-", name);

                                    item.style.display = "block";
                                    
                                    var links = $("a[href]", item);
                                    
                                    if (links.length > 0)
                                    {
                                        item.innerHTML = item.innerHTML.replace("-link-", links[0].getAttribute("href"));
                                    }
                                    else
                                    {
                                        item.innerHTML = item.innerHTML.replace("-linkstyle-", "display: none;");
                                    }
                                }

                                $(element).animate
                                (
                                    {
                                        opacity: 1.0,
                                    },
                                    250,
                                    "swing"
                                );
                            }
                        );
                    }
                }
		    );
        }
    );
}

ebloc.insertAnchorLinks = function (value, internal)
{
    if (!internal)
    {
        var internal = false;
    }

    value = value.replace(/(http:\/\/[^ ]+)/g, "<a href=\"$1\"" + (internal ? "" : " target=\"_blank\"") + ">$1</a>/");
    value = value.replace(/(\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,6})/g, "<a href=\"mailto:$1\">$1</a>/");

    return value;
}

ebloc.convert = {};

ebloc.convert.twitterDateToLongDate = function (twitterDate, dateSeperator, timeSeperator, dateTimeSeperator)
{
    var dateParts = twitterDate.split(/[\s:]+/);

    var date = "";

    date += dateParts[2];
    date += dateSeperator;

    switch (dateParts[1].toLowerCase())
    {
        case "jan":
            date += "01";
            break;
        case "feb":
            date += "02";
            break;
        case "mar":
            date += "03";
            break;
        case "apr":
            date += "04";
            break;
        case "may":
            date += "05";
            break;
        case "jun":
            date += "06";
            break;
        case "jul":
            date += "07";
            break;
        case "aug":
            date += "08";
            break;
        case "sep":
            date += "09";
            break;
        case "oct":
            date += "10";
            break;
        case "nov":
            date += "11";
            break;
        case "dec":
            date += "12";
            break;
    }
    date += dateSeperator;

    date += dateParts[7];

    date += dateTimeSeperator;

    date += dateParts[3];
    date += timeSeperator;

    date += dateParts[4];
    date += timeSeperator;

    date += dateParts[5];

    return date;
}

ebloc.fader = function (target, delay)
{
    var target = $(target);

    if (!delay)
    {
        var delay = 10.0;
    }

    var targetChildren = $("> *", target[0]);

    var maxHeight = 0;

    targetChildren.each
    (
        function (index, element)
        {
            element.style.position = "absolute";

            if (index > 0)
            {
                element.style.display = "none";
            }

            maxHeight = Math.max(maxHeight, $(element).height());
        }
    );

    target.css("height", maxHeight + "px");

    currentIndex = 0;
    maxIndex = targetChildren.length;

    window.setInterval
    (
        function ()
        {
            $(targetChildren[currentIndex]).animate
            (
                {
                    opacity: 0.0
                },
                ebloc.fader.speed * 1000,
                "swing",
                function ()
                {
                    targetChildren[currentIndex].style.display = "none";

                    ++currentIndex;
                    currentIndex %= maxIndex;

                    targetChildren[currentIndex].style.display = "block";
                    targetChildren[currentIndex].style.opacity = "0.0";

                    $(targetChildren[currentIndex]).animate
                    (
                        {
                            opacity: 1.0
                        },
                        ebloc.fader.speed * 1000,
                        "swing"
                    );
                }
            );
        },
        (delay + ebloc.fader.speed) * 1000
    );
}

ebloc.fader.speed = 0.5;

ebloc.lightBox = function (element, stopAutoHide, hideCallback, popupClassName, backgroundClassName)
{
    element = $(element);

    if (!stopAutoHide)
    {
        var stopAutoHide = false;
    }

    if (hideCallback)
    {
        this._hideCallback = hideCallback;
    }
    else
    {
        this._hideCallback = null;
    }

    if (!popupClassName)
    {
        var popupClassName = "lightBox";
    }

    if (!backgroundClassName)
    {
        var backgroundClassName = "lightBoxBackground";
    }

    var body = $("body")[0];

    this._popup = document.createElement("div");
    body.appendChild(this._popup);
    this._popup = $(body.childNodes[body.childNodes.length - 1]);

    this._popup.addClass(popupClassName);

    this._popup.css("display", "none");
    this._popup.css("position", "fixed");

    this._background = document.createElement("div");
    body.appendChild(this._background);
    this._background = $(body.childNodes[body.childNodes.length - 1]);

    this._background.addClass(backgroundClassName);

    this._background.css("display", "none");
    this._background.css("position", "fixed");
    this._background.css("width", "100%");
    this._background.css("top", "0px");
    this._background.css("left", "0px");

    var self = this;

    if (!stopAutoHide)
    {
        this._background.click
        (
            function ()
            {
                self.hide();
            }
        );
    }

    this._setSize();

    $(window).resize
    (
        function ()
        {
            self._setSize();
        }
    );

    while (this._popup[0].childNodes.length > 0)
    {
        this._popup[0].removeChild(this._popup[0].childNodes[0]);
    }

    element.css("display", "block");
    element.appendTo(this._popup);

    this._popup.css("left", (($(window).width() - this._popup.width()) / 2) + "px");
    this._popup.css("top", (($(window).height() - this._popup.height()) / 2) + "px");

    this._background.css("display", "none");
    this._popup.css("display", "none");

    var _userAgent = navigator.userAgent.toLowerCase();

    this._platformIsIos = false;

    if (_userAgent.indexOf("ipad") != -1 || _userAgent.indexOf("ipod") != -1 || _userAgent.indexOf("iphone") != -1 || _userAgent.indexOf("ios") != -1)
    {
        this._platformIsIos = true;
    }
}

ebloc.lightBox._visibleCount= 0;

ebloc.lightBox.prototype =
{
    show: function (callback)
    {
        ++ebloc.lightBox._visibleCount;

        this._background.css("opacity", "0.0");
        this._background.css("display", "block");
        this._popup.css("opacity", "0.0");
        this._popup.css("display", "block");
        
        this._background.css("z-index", parseInt(this._background.css("z-index")) * ebloc.lightBox._visibleCount);
        this._popup.css("z-index", parseInt(this._popup.css("z-index")) * ebloc.lightBox._visibleCount);

        this._background.animate
        (
            {
                "opacity": 0.3
            },
            500,
            "swing"
        );

        this._popup.animate
        (
            {
                "opacity": 1.0
            },
            500,
            "swing",
            function ()
            {
                if (callback)
                {
                    callback();
                }
            }
        );

        if (this._platformIsIos)
        {
            var scrollTop = document.body.scrollTop;
            if (scrollTop == 0)
            {
                if (window.pageYOffset)
                {
                    scrollTop = window.pageYOffset;
                } 
                else
                {
                    scrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
                } 
            }

            this._popup.css("top", (scrollTop + 50) + "px");
        }
    },

    _setSize: function ()
    {
        var _userAgent = navigator.userAgent.toLowerCase();

        if (_userAgent.indexOf("ipad") != -1 || _userAgent.indexOf("ipod") != -1 || _userAgent.indexOf("iphone") != -1 || _userAgent.indexOf("ios") != -1)
        {
            this._background.css("height", Math.max($(window).height(), $("body").height()) + "px");
        }
        else
        {
            this._background.css("width", $(window).width() + "px");
            this._background.css("height", $(window).height() + "px");
        }
    },

    hide: function ()
    {
        var self = this;

        this._background.animate
        (
            {
                "opacity": 0.0
            },
            500,
            "swing",
            function ()
            {
                self._background.css("display", "none");
            }
        );

        this._popup.animate
        (
            {
                "opacity": 0.0
            },
            500,
            "swing",
            function ()
            {
                self._popup.css("display", "none");

                if (self._hideCallback != null)
                {
                    self._hideCallback();
                }
            }
        );

        --ebloc.lightBox._visibleCount;
    }
}

ebloc.tabList = function (header, activeClass)
{
    this._header = $(header);

    if (!activeClass)
    {
        this._activeClass = "active";
    }
    else
    {
        this._activeClass = activeClass;
    }

    this._currentTab = null;

    var self = this;
    
    $("*[targetid]", this._header[0]).each
    (
        function (index, element)
        {
            var tab = $("#" + element.getAttribute("targetid"))[0];

            if (index == 0)
            {
                self._currentTab = tab;
                element.className = self._activeClass;
            }
            else
            {
                tab.style.display = "none";
            }

            $(element).click
            (
                function ()
                {
                    self.setCurrent(this);
                }
            );
        }
    );
}

ebloc.tabList.prototype = 
{
    setCurrent: function (tabHeader)
    {
        tabHeader = $(tabHeader);

        var tab = $("#" + tabHeader[0].getAttribute("targetid"))[0];

        if (this._currentTab != tab)
        {
            this._currentTab.style.display = "none";
            this._currentTab = tab;
            this._currentTab.style.display = "block";
        }

        $("." + this._activeClass, this._header[0]).removeClass(this._activeClass);

        tabHeader.addClass(this._activeClass);
    }
};

ebloc.cookieManager = function ()
{
}

ebloc.cookieManager.set = function (name, value, days)
{
    var expires;

	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
		expires = "; expires=" + date.toGMTString();
	}
	else
    {
        expires = "";
    }

	document.cookie = name + "=" + value + expires + "; path=/";
}

ebloc.cookieManager.get = function (name)
{
	var nameEquals = name + "=";

	var cookies = document.cookie.split(";");

	for(var index = 0; index < cookies.length; ++index)
	{
		var cookie = cookies[index];

		while (cookie.charAt(0) == " ")
        {
            cookie = cookie.substring(1, cookie.length);
        }

		if (cookie.indexOf(nameEquals) == 0)
        {
            return cookie.substring(nameEquals.length, cookie.length);
        }
	}

	return null;
}

ebloc.cookieManager.remove = function (name)
{
    ebloc.cookieManager.create(name, "", -1);
}

ebloc.expansionList = function (headerElement)
{
    headerElement = $(headerElement);
    var targetElement = $("#" + headerElement.attr("targetid"));

    targetElement.attr("fullheight", targetElement.height());

    if (targetElement.attr("active") != "1")
    {
        targetElement.css("height", "0px");
        targetElement.attr("active", "0");
    }

    targetElement.attr("animating", "0");

    headerElement.css("cursor", "pointer");

    headerElement.click
    (
        function ()
        {
            if (targetElement.attr("animating") == "0")
            {
                var newHeight;

                if (targetElement.attr("active") == "1")
                {
                    newHeight = 0;
                    targetElement.attr("active", "0");
                }
                else
                {
                    newHeight = parseInt(targetElement.attr("fullheight"));
                    targetElement.attr("active", "1");
                }

                targetElement.attr("animating", "1");

                targetElement.animate
                (
                    {
                        height: newHeight
                    },
                    500,
                    "swing",
                    function ()
                    {
                        targetElement.attr("animating", "0");
                    }
                );
            }
        }
    );
}

ebloc.validation = function (formFields, requiredRegExs, errorMessages, errorCallback)
{
    this._formFields = ebloc._makeArray(formFields);
    this._requiredRegExs = ebloc._makeArray(requiredRegExs);
    this._errorMessages = ebloc._makeArray(errorMessages);

    if (errorCallback)
    {
        this._errorCallback = errorCallback;
    }
    else
    {
        this._errorCallback = null;
    }

    if (this._formFields.length != this._requiredRegExs.length || this._formFields.length != this._errorMessages.length)
    {
        alert("Array lengths do not match");
    }

    for (var index = 0; index < this._formFields.length; ++index)
    {
        this._formFields[index] = $(this._formFields[index]);
    }
}

ebloc.validation.prototype.validate = function ()
{
    var isAllValid = true;
    var errorIndex = 0;
    var focusSet = false;

    for (var index = 0; index < this._formFields.length; ++index)
    {
        var formField = this._formFields[index];
        var requiredRegEx = this._requiredRegExs[index];
        var errorMessage = this._errorMessages[index];

        var isValid;

        if (requiredRegEx == "")
        {
            switch (formField.attr("type"))
            {
                case "radio":
                case "checkbox":
                    isValid = formField[0].checked;
                    break;
                default:
                    isValid = jQuery.trim(formField.val()) != "";
                    break;
            }
        }
        else if(requiredRegEx.charAt)
        {
            switch (requiredRegEx.charAt(0) )
            {
                case "<":
                    var maxLength = parseInt(requiredRegEx.substring(1));
                    isValid = formField.val().length < maxLength;
                    break;
            }
        }
        else
        {
            var regEx = new RegExp(requiredRegEx);
            isValid = regEx.test(jQuery.trim(formField.val()));
        }

        if (!isValid)
        {
            if (this._errorCallback != null)
            {
                this._errorCallback(formField, errorMessage, errorIndex);
                ++errorIndex;
            }

            if (!focusSet)
            {
                try
                {
                    formField.focus();
                    focusSet = true;
                }
                catch(ex)
                {
                }
            }

            isAllValid = false;
        }
    }

    return isAllValid;
}

ebloc._makeArray = function (value)
{
    if (value.constructor != (new Array).constructor)
    {
        var valueTemp = [];
        valueTemp.push(value);
        value = valueTemp;
    }

    return value;
}

ebloc.alertBubble = function (target, className)
{
    if (target)
    {
        this._target = $(target);
    }
    else
    {
        this._target = null;
    }

    if (!className)
    {
        var className = "alertBubble";
    }

    var body = $("body")[0];

    var bubble = document.createElement("div");
    body.appendChild(bubble);
    this._bubble = $(body.childNodes[body.childNodes.length - 1]);

    this._bubble.css("display", "none");
    this._bubble.css("opacity", "0.0");
    this._bubble.css("position", "absolute");

    this._bubble[0].className = className;

    this._addElement("p", "alertBubbleHeader");
    this._messagePElement = this._addElement("p", "alertBubbleContet");
    this._addElement("p", "alertBubbleFooter");

    this._isVisible = false;

    this._timeout = null;

    var self = this;

    $(window).resize
    (
        function ()
        {
            if (self._isVisible)
            {
                self._position();
            }
        }
    );
}

ebloc.alertBubble.prototype = 
{
    _addElement: function (type, className)
    {
        var element = document.createElement(type);
        this._bubble[0].appendChild(element);
        element = this._bubble[0].childNodes[this._bubble[0].childNodes.length - 1];

        element.className = className;

        return $(element);
    },

    show: function (message, hideCount, target, offsetLeft)
    {
        if (!message)
        {
            var message = "Alert";
        }

        if (!hideCount)
        {
            var hideCount = 0;
        }
        else if (hideCount < 0)
        {
            hideCount = 0;
        }

        if (!target)
        {
            if (!this._target)
            {
                alert("No target set");
                return false;
            }

            this._currentTarget = this._target;
        }
        else
        {
            this._currentTarget = $(target);
        }

        if (!offsetLeft)
        {
            var offsetLeft = 0;
        }

        this._isVisible = true;

        this._messagePElement[0].innerHTML = message;
        
        this._position(offsetLeft);
        
        this._bubble.css("display", "block");
        this._bubble.animate
        (
            {
                opacity: 1.0
            },
            500,
            "swing"
        );

        var self = this;

        if (hideCount > 0)
        {
            if( this._timeout != null)
            {
                window.clearTimeout(this._timeout);
            }

            this._timeout = window.setTimeout
            (
                function ()
                {
                    self.timeout = null;
                    self.hide();
                },
                hideCount
            );
        }
    },

    _position: function (offsetLeft)
    {
        if (!offsetLeft)
        {
            var offsetLeft = 0;
        }

        var width = null;
        var height = null;
        var position = null;

        var currentTarget = this._currentTarget;

        var positionNotFound = true;

        while (positionNotFound)
        {
            width = currentTarget.outerWidth(true);
            height = currentTarget.outerHeight(true);
            position = currentTarget.offset();

            if (position != null)
            {
                positionNotFound = false;
            }
            else
            {
                currentTarget = currentTarget.prev("input");

                if (currentTarget.length == 0)
                {
                    return;
                }
                else
                {
                    currentTarget = $(currentTarget[currentTarget.length - 1]);
                }
            }
        }

        this._bubble.css("left", (position.left + width + offsetLeft) + "px");
        this._bubble.css("top", (position.top) + "px");
    },

    hide: function ()
    {
        if (this._isVisible)
        {
            this._isVisible = false;

            var self = this;

            this._bubble.animate
            (
                {
                    opacity: 0.0
                },
                500,
                "swing",
                function ()
                {
                    self._bubble.css("display", "none");

                    self._isVisible = false;
                }
            );
        }
    }
};

ebloc.hoverScroller = function (scrollElement, leftElement, rightElement)
{
    scrollElement = $(scrollElement);
    if (leftElement)
    {
        leftElement = $(leftElement);
    }
    if (rightElement)
    {
        rightElement = $(rightElement);
    }

    if (!actionOnMouseOver)
    {
        var actionOnMouseOver = false;
    }

    this._scollContainer = document.createElement("div");
    scrollElement[0].appendChild(this._scollContainer)
    this._scollContainer = $(scrollElement[0].childNodes[scrollElement[0].childNodes.length - 1]);

    var self = this;

    this._setSize(scrollElement);

    var scrollElementWidth = scrollElement.width();

    if (this._totalWidth > scrollElementWidth)
    {
        if (leftElement)
        {
            leftElement.css("cursor", "pointer");

            leftElement.hover
            (
                function ()
                {
                    self._beginScroll(-1);
                },
                function ()
                {
                    self._endScroll();
                }
            );
        }

        if (rightElement)
        {
            rightElement.css("cursor", "pointer");

            rightElement.hover
            (
                function ()
                {
                    self._beginScroll(1);
                },
                function ()
                {
                    self._endScroll();
                }
            );
        }
    }

    this._currentVelocity = 0.0;
    this._currentAcceleration = 0.0;
    this._isAccelerating = false;
    this._frameInterval = null;
    this._currentDirection = 0;
    this._currentOffset = 0;

    this._totalWidth = this._totalWidth - scrollElementWidth;

    this._autoMove = ebloc.hoverScroller.defaultSpeed > 0.0;
    this._autoMoveDirection = 1;

    if (this._autoMove)
    {
        this._frameInterval = window.setInterval
        (
            function ()
            {
                self._doAutoMove();
            },
            1000 / ebloc.hoverScroller.frameRate
        );
    }
};

ebloc.hoverScroller.acceleration = 1;
ebloc.hoverScroller.deceleration = 1;
ebloc.hoverScroller.maximumSpeed = 50.0;
ebloc.hoverScroller.frameRate = 20;
ebloc.hoverScroller.defaultSpeed = 1.5;

ebloc.hoverScroller.prototype = 
{
    _setSize: function (scrollElement)
    {
        this._totalWidth = 0;
        var maxHeight = 0;

        var elements = $("> *", scrollElement[0]);
        var elementsLength = elements.length;

        var self = this;

        elements.each
        (
            function (index, element)
            {
                if (index < elementsLength - 1)
                {
                    element = $(element);
                    self._totalWidth += element.outerWidth() + 31; //????

                    maxHeight = Math.max(maxHeight, element.outerHeight());

                    element.appendTo(self._scollContainer);
                }
            }
        );

        scrollElement.css("height", maxHeight + "px");
        scrollElement.css("overflow", "hidden");
        scrollElement.css("position", "relative");

        this._scollContainer.css("width", this._totalWidth + "px");
        this._scollContainer.css("height", maxHeight + "px");
        this._scollContainer.css("position", "relative");
    },

    _doAutoMove: function ()
    {
        this._currentOffset += this._autoMoveDirection * ebloc.hoverScroller.defaultSpeed;

        if (this._currentOffset > this._totalWidth)
        {
            this._currentOffset = this._totalWidth;
            this._autoMoveDirection = -1 * this._autoMoveDirection;
        }
        else if (this._currentOffset < 0.0)
        {
            this._currentOffset = 0.0;
            this._autoMoveDirection = -1 * this._autoMoveDirection;
        }

        this._scollContainer.css("marginLeft", "-" + Math.round(this._currentOffset) + "px");
    },

    _beginScroll: function (direction)
    {
        if (this._autoMove && this._frameInterval != null)
        {
            window.clearInterval(this._frameInterval);
            this._frameInterval = null;
        }

        this._currentDirection = direction;
        this._currentAcceleration = ebloc.hoverScroller.acceleration * (this._currentDirection > 0 ? 1 : -1);
        this._isAccelerating = true;

        if (this._frameInterval == null)
        {
            var self = this;
            this._frameInterval = window.setInterval
            (
                function ()
                {
                    self._update();
                },
                1000 / ebloc.hoverScroller.frameRate
            )
        }
    },

    _endScroll: function ()
    {
        this._currentAcceleration = ebloc.hoverScroller.deceleration * (this._currentDirection > 0 ? -1 : 1);
        this._isAccelerating = false;
    },

    _update: function ()
    {
        if (this._currentAcceleration != 0)
        {
            this._currentVelocity += this._currentAcceleration;

            if (this._isAccelerating)
            {
                if (this._currentVelocity >= ebloc.hoverScroller.maximumSpeed && this._currentAcceleration > 0 && this._currentDirection > 0)
                {
                    this._currentVelocity = ebloc.hoverScroller.maximumSpeed;
                    this._currentAcceleration = 0.0;
                }
                else if (this._currentVelocity <= -1 * ebloc.hoverScroller.maximumSpeed && this._currentAcceleration < 0  && this._currentDirection < 0)
                {
                    this._currentVelocity = -1 * ebloc.hoverScroller.maximumSpeed;
                    this._currentAcceleration = 0.0;
                }
            }
            else
            {
                if (this._currentVelocity < 0 && this._currentAcceleration < 0 && this._currentDirection > 0)
                {
                    this._currentVelocity = 0;
                    this._currentAcceleration = 0.0;
                }
                else if (this._currentVelocity > 0 && this._currentAcceleration > 0 && this._currentDirection < 0)
                {
                    this._currentVelocity = 0;
                    this._currentAcceleration = 0.0;
                }
            }
        }

        if (this._currentVelocity == 0 && this._currentAcceleration && this._frameInterval != null)
        {
            window.clearInterval(this._frameInterval);

            this._frameInterval = null;
        }

        this._currentOffset += this._currentVelocity;

        if (this._currentOffset > this._totalWidth)
        {
            this._currentOffset = this._totalWidth;
            this._currentAcceleration = 0;
            this._currentVelocity = 0;
        }
        else if (this._currentOffset < 0)
        {
            this._currentOffset = 0;
            this._currentAcceleration = 0;
            this._currentVelocity = 0;
        }

        this._scollContainer.css("marginLeft", "-" + Math.round(this._currentOffset) + "px");
    }
};

