var slideTimer = 0;
var headlineTimer = 0;
var curSlide = 1;
var curHeadline = 1;

$(document).ready(function(){
	$("#tabs a").live('click', function(){
		var reqId = $(this).attr('id');
		selectSlide(reqId);
	});
	
	setInterval(function () {
		slideTimer++;
		headlineTimer++;
		
		if (slideTimer == 10)
		{
			curSlide++;
			
			if (curSlide == 7)
				curSlide = 1;
			
			selectSlide(curSlide);
		}
		
		if (headlineTimer == 7)
		{
			curHeadline++;
			headlineTimer = 0;
			selectHeadline(curHeadline);
		}
	}, 1000);
});

function selectSlide(reqId)
{
	var slide = false;
	var tabs  = false;

	$.get("/welcome/tabs/"+reqId, null, function(data){
		tabs = data;
		changeSlide(slide, tabs);
	});
	$.get("/welcome/slide/"+reqId, null, function(data){
		slide = data;
		changeSlide(slide, tabs);
	});
	
	curSlide = reqId;
	slideTimer = 0;
}
function selectHeadline(id)
{
	$.get("/welcome/headlines/"+id, null, function(data){
		$("#newsbar").html(data);
	});
}
function changeSlide(slide, tabs)
{
	if (slide && tabs)
	{
		$("#tabs").html(tabs);
		$("#slide").html(slide);
	}
}