// Easing equation, borrowed from jQuery easing plugin
// http://gsgd.co.uk/sandbox/jquery/easing/
jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
};
var scrollTime = 0;
var initDuration = 600;
var duration = initDuration;
var curPos = 0;
var reStart = 0;
jQuery(document).ready(function(){
	if (jQuery("#slider-nav").length != 0) {
		jQuery(function( $ ){
			if (!($("#wrapper2").length === 0)) {
				var slider = $('#wrapper2').serialScroll({
					target:'#sections',
					items:'li', // Selector to the items ( relative to the matched elements, '#sections' in this case )
					prev:'div.prev',// Selector to the 'prev' button (absolute!, meaning it's relative to the document)
					next:'div.next',// Selector to the 'next' button (absolute too)
					axis:'xy',// The default is 'y' scroll on both ways
					navigation:'#slider-nav a',
					lock: true,
					interval:5000, //auto scroll time limit ADDED MANUALLY
					duration:duration,// Length of the animation (if you scroll 2 axes and use queue, then each axis take half this time)
					force:true, // Force a scroll to the element specified by 'start' (some browsers don't reset on refreshes)
					onBefore:function( e, elem, $pane, $items, pos ){
						if((curPos == 0 && pos == 2) || (curPos = 2 && pos == 0))
							{
								duration = initDuration * 3;
							}
						else{
							duration = initDuration;
						}
						curPos = pos;
						e.preventDefault();
						scrollTime = new Date();
						scrollTime = scrollTime.getTime();
						if( this.blur )
							this.blur();
					},
					onAfter:function( elem ){
					}
				});
				$('#sections').hover(function(){
					reStart = 0;
					var currentTime = new Date();
					currentTime = currentTime.getTime();
					var diffTime = currentTime - scrollTime;
					//alert('difftime = ' + diffTime)
					if(diffTime > duration){
						$('#sections').stop().trigger('stop');
					}
					else{
						//('transitioning:' + diffTime);
						delayStopTime = duration + 100 - diffTime;
						setTimeout("delaySliderStop()", delayStopTime);

					}
				},function(){
					reStart = 1;
					setTimeout("delaySliderStart()", 2000);
				});
			};	
		});
	};
});

function delaySliderStart()
{
	if(reStart){		
		jQuery('#sections').stop().trigger('start');
	}
}
function delaySliderStop(){
	jQuery('#sections').stop().trigger('stop');
}
