﻿
var isiStartPosFinal;

$(document).ready(function () {

    //Start Pane
    var pane = $('#ISI');
    pane.jScrollPane(
		{
		    showArrows: true,
		    verticalDragMinHeight: 25
		});
    var api = pane.data('jsp');

    $('.jspPane').attr("id", "toControlStop");

    if (document.getElementById("toControlStop")) {
        var hoverElement1 = document.getElementById('toControlStop');

        if (window.addEventListener) hoverElement1.addEventListener('DOMMouseScroll', stopScroll, false);
        hoverElement1.onmousewheel = stopScroll;
    }

    if ($.browser.msie && $.browser.version == "6.0")
        $('.jspPane').bgiframe();


    //Top Sliding ISI
    $('#buttonISI').toggle(
    function () {

        //Stop Auto Scroll
        stopScroll();

        $(this).html("Collapse");

        $('#ISI, .jspContainer, .jspTrack').stop(0).animate({
            height: '470px'
        }, {
            duration: 1000,
            complete: function () {
                $('#ISI').jScrollPane({ showArrows: true });
                $('.jspDragTop, .jspDragBottom').css("overflow", 'hidden');

                $('.jspDragBottom').css("top", '110px');
                $('.spanish .jspDragBottom').css("top", '195px');

                if ($.browser.msie && $.browser.version == "6.0") {
                    $('.jspDragBottom').css("top", '105px');
                    $('.spanish .jspDragBottom').css("top", '187px');
                }
            }
        });
    },
    function () {

        $('.jspDragBottom').css("top", '110px');
        $('.spanish .jspDragBottom').css("top", '195px');

        if ($.browser.msie && $.browser.version == "6.0") {
            $('.jspDragBottom').css("top", '105px');
            $('.spanish .jspDragBottom').css("top", '187px');
        }

        $('#ISI, .jspContainer, .jspTrack').stop(0).animate({
            height: '116px'
        }, {
            duration: 1000,
            complete: function () {
                $('#ISI').jScrollPane({ showArrows: true, verticalDragMinHeight: 25 });
                $('#buttonISI').html("Click here to view more");
            }
        });
    });

    //Stop Animation when the scoller is clicked
    $('.jspTrack, .jspArrow').click(function () {
        stopScroll();
    });


});

function autoScroll() {
    $(document).ready(function () {
        //$('#ISI').data('jsp').scrollToElement('.isiEnd', true, true);

        var isiEndPos = $('.isiEnd').position();
        var isiEndPosFinal = isiEndPos.top - 114;
        isiStartPosFinal = isiEndPos.top;

        $('#toControlStop').delay(3000).animate({
            top: '-' + isiEndPosFinal + 'px'
        }, {
            easing: 'linear',
            duration: 240000,
            complete: function () {
                scrollToTop();
            }
        });


        $('.jspDrag').animate({
            top: '77px'
        }, {
            duration: 240000,
            complete: function () {

            }
        });


    });
}

function stopScroll(event) {
    $("div").stop();
}

function scrollToTop() {

    $('#toControlStop, .jspDrag').delay(3000).animate({
        top: '0px'
    }, {
        duration: 5000,
        complete: function () {

        }
    });

}
