﻿// divScroll() makes a HTML element scrollable, in the event that the parent element is a DIV or similar container

jQuery.fn.divScroll = function(options) {

    var defaults = {
        maxHeight: 180,
        scrollPace: 50,
        margin: 5,
        speed: 100
    };

    options = $.extend(defaults, options);

    if ($(this).height() > options.maxHeight) {
        var div = $(this).parent();

        div.height(options.maxHeight).css("overflow", "hidden");

        div.append("<div class='scrollup mouseover_up'><a href='javascript:;'></a></div><div class='scrolldown mouseover_down'><a href='javascript:;'></a></div>");
        var upDiv = div.find(".scrollup");
        upDiv.css({
            position: "absolute",
            top: options.margin + "px",
            right: options.margin + "px"
        });
        upDiv.bind("click", function() {
            div.scrollTo({ top: "-=" + options.scrollPace + "px", left: "+=0px" }, options.speed);
            $(this).parent().parent().find("ul li:first").mouseover();
            return false;
        });


        var downDiv = div.find(".scrolldown");
        downDiv.css({
            position: "absolute",
            bottom: options.margin + "px",
            right: options.margin + "px",
            border: 1
        });
        var presingDown = false;
        downDiv.bind("click", function() {
            div.scrollTo({ top: "+=" + options.scrollPace + "px", left: "+=0px" }, options.speed);
            $(this).parent().parent().find("ul li:first").mouseover();
            return false;
        });
    }
};
