var timeoutID = 0;
var scrollclick = 0;
var newsIntervalId =0;
var maxnews = 0;
var currentnews = 1;
var nextnews = 1;
$(function(){
	//news ticker
	$("ul.latest-item li").each(function(i) {
  		var id = i+1
	  $(this).attr('id', "newsitem"+id) ;
      if(i != 0) {
          $(this).hide();
      }
	  maxnews = i+1;
  });
	newsIntervalId = setInterval ( "newsTicker()", 6000 );
	
	//sliders
	$('.press-me').animate({right:0}, 600, function(){ timeoutID = window.setTimeout(animateNext, 1000); });
	$("#browsable").scrollable({size: 2, onSeek:function(){scrollclick = 1;}}).navigator();
	$("#browsable2").scrollable({size: 1}).navigator();
	$("#browsable3").scrollable({size: 1}).navigator();
	$("#browsable4").scrollable({size: 1}).navigator();
	
	//tabs
	$("ul.tabs").tabs("div.panes > div");
	
});

//animate button to draw attention to feature
function animateNext() {
	window.clearTimeout(timeoutID);
	if (scrollclick ==0) {
		$('.press-me').animate({right:10}, 1000).animate({right:0}, 600, function(){ timeoutID = window.setTimeout(animateNext, 1500); });
	}
}

//news ticker
function newsTicker() {
		if (currentnews + 1 <= maxnews) {
			nextnews += 1;
		} else {
			nextnews = 1;
		}
		$('#newsitem'+currentnews).fadeOut(600, function(){
			$('#newsitem'+nextnews).fadeIn(372, function(){
				 currentnews = nextnews;
			});
		});
};

