// You may specify partial version numbers, such as "1" or "1.3",
//  with the same result. Doing so will automatically load the 
//  latest version matching that partial revision pattern 
//  (i.e. both 1 and 1.3 would load 1.3.2 today).
google.load("jquery", "1.3.2");
google.load("jqueryui", "1.7.2");

var timeout;

google.setOnLoadCallback(function() {

	jQuery("#content-slider").slider({
		animate: false,
		change: handleSliderChange,
		slide: handleSliderSlide
	});
	
	jQuery("#arrow_left").mousedown( scrollLeft);
	
	jQuery("#arrow_left").mouseup( function(){
		clearTimeout(timeout);
	});
	
	jQuery("#arrow_right").mousedown( scrollRight);
	
	jQuery("#arrow_right").mouseup( function(){
		clearTimeout(timeout);
	});
});

function scrollLeft(){
		timeout = setTimeout( function(){
			var val=jQuery("#content-slider").slider('value');
			
			jQuery("#content-slider").slider('value',val-1);
			
			scrollLeft();
		},50);
}

function scrollRight(){
		timeout = setTimeout( function(){
			var val=jQuery("#content-slider").slider('value');
			
			jQuery("#content-slider").slider('value',val+1);
			
			scrollRight();
		},50);
}

function handleSliderChange(e, ui)
{
	var maxScroll = jQuery("#content-scroll").attr("scrollWidth") - 
				  jQuery("#content-scroll").width();
	jQuery("#content-scroll").animate({scrollLeft: ui.value * 
	 (maxScroll / 100) }, 0);
}

function handleSliderSlide(e, ui)
{
	var maxScroll = jQuery("#content-scroll").attr("scrollWidth") - 
				  jQuery("#content-scroll").width();
	jQuery("#content-scroll").attr({scrollLeft: ui.value * (maxScroll / 100) });
}

