﻿var isiStartPosFinal;
var currentPage;

$(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();

	$('.jspDrag').mousedown(function () {
		stopScroll();
	});

	//Top Sliding ISI
	$('#buttonISI').toggle(
    function () {

    	//Stop Auto Scroll
    	stopScroll();

    	$(this).html("Collapse");
    	$(this).css({ 'background': 'none', 'backgroundColor': '#ffffff' });
    	$('#ISIcontainer h2').css({ 'background': 'none', 'backgroundColor': '#ffffff' }); //ADDED
    	$('.jspPane').css('backgroundColor', '#ffffff');

    	$('#ISI, .jspContainer, .jspTrack').stop(0).animate({
    		height: '470px'
    	}, {
    		duration: 1000,
    		complete: function () {
    			$('#ISI').jScrollPane({ showArrows: true });
    			$('.jspDragTop, .jspDragBottom').css("overflow", 'hidden');

    			$('.jspDragBottom').css("top", '210px');
    			$('.spanish .jspDragBottom').css("top", '195px');

    			if ($.browser.msie && $.browser.version == "6.0") {
    				$('.jspDragBottom').css("top", '203px');
    				$('.spanish .jspDragBottom').css("top", '187px');
    			}
    		}
    	});
    },
    function () {

    	$('.jspDragBottom').css("top", '210px');
    	$('.spanish .jspDragBottom').css("top", '195px');

    	if ($.browser.msie && $.browser.version == "6.0") {
    		$('.jspDragBottom').css("top", '203px');
    		$('.spanish .jspDragBottom').css("top", '187px');
    	}

    	$('#ISI, .jspContainer, .jspTrack').stop(0).animate({
    		height: '116px'
    	}, {
    		duration: 1000,
    		complete: function () {
    			$('#ISI').jScrollPane({ showArrows: true, verticalDragMinHeight: 25 });
    			$('.jspPane').css("background", 'none');
    			$('#buttonISI').html("");
    			$('#buttonISI').css("background", 'url(/PublishingImages/common/btnViewAll.gif) no-repeat top right');
    			$('#ISIcontainer h2').css({ 'background': 'url(/PublishingImages/common/bkndSlice.gif) repeat-x 0 -22px' }); //ADDED
    		}
    	});
    });

	//Stop Animation when the scoller is clicked
	$('.jspTrack, .jspArrow').click(function () {
		stopScroll();
	});
});

function autoScroll() {
	$(document).ready(function () {
		var isiEndPos = $('.isiEnd').position();
		var isiEndPosFinal = isiEndPos.top - 114;
		isiStartPosFinal = isiEndPos.top;

		$('#toControlStop').delay(3000).animate({
			top: '-' + isiEndPosFinal + 'px'
		}, {
		    easing: 'linear',
        	duration: 40000,
			complete: function () {
				scrollToTop();
			}
		});

		$('.jspDrag').animate({
			top: '77px'
		}, {
			duration: 40000,
			complete: function () {
			}
		});
	});
}

function stopScroll(event) {
	$("div").stop();
}

function scrollToTop() {

	$('#toControlStop, .jspDrag').delay(3000).animate({
		top: '0px'
	}, {
		duration: 5000,
		complete: function () {
		}
	});
}
