var _seconds = 8; // Timeout
var _last_right_pane_img = "";

$(function() {
	if(!/WebKit/i.test(navigator.userAgent)) { $(document).ready(sliding); }
	else { $(window).load(sliding); } 
});

function sliding()
{
	var _secondsToChange = _seconds;

	$($('#scrollable-text div')[0]).css('left','0');

	if( $('#scrollable-text div#st-0 img').length > 0 ) 
		_last_right_pane_img = $('#scrollable-text div#st-0 img')[0].src;

//	var api = $('#slides').scrollable({size:1,clickable:false}).circular().navigator().mousewheel().autoscroll({autoplay:true,autopause:true,interval:5000,api:true});
	var api = $('#slides').scrollable({size:1,speed:400,clickable:false}).circular().navigator().mousewheel({api:true});

	if( api ) 
	{
		api.onSeek(function() {
			var gi = this.getPageIndex();
	
			_secondsToChange = _seconds;
	
	
			var new_img = $('#scrollable-text div#st-'+[gi] + ' img')[0].src;
	
			if( _last_right_pane_img != new_img )
			{
				_last_right_pane_img = new_img;
	
				$('#st-0,#st-1,#st-2,#st-3,#st-4,#st-5,#st-6,#st-7').css('left','-9999px');
				$($('#scrollable-text div#st-'+[gi])).hide();
				$($('#scrollable-text div#st-'+[gi])).css('left','0');
				if (! $.browser.msie) { $($('#scrollable-text div#st-'+[gi])).fadeIn(); }
				else { $($('#scrollable-text div#st-'+[gi])).show(); }
			}
		});
	
		//api.hover(function(){api.stop();});
		//api.click(function(){api.stop();});
		//console.log("Test: "+_secondsToChange);
	
		setInterval(function() {		
			_secondsToChange--;
			if (_secondsToChange < 1) {
				_secondsToChange = _seconds;
				api.next();
			}
		}, 1000);
	}
}

