
$(function(){
	var news=[];
	var studies=[];
	var current=0;
	var current_study=0;
	//get the news section
	$.post('news.php', {}, function(data){
		news=data;
		$("#news .date").html(news[current].data);
		$("#news .title").html(news[current].title);
		$("#news .body").html(news[current].body);
		current++;
		$("#news").everyTime(10*1000, 'news',function(){
			$("#news .date").html(news[current].data);
			$("#news .title").html(news[current].title);
			$("#news .body").html(news[current].body);
			current++;
			if (current>=news.length) current=0;
		});
	}, 'json');
	$.post('case_studies.php', {}, function(data){
		studies=data;
		$("#boxes li:first h2").html(studies[current_study].title);
		$("#boxes li:first p").html(studies[current_study].body);
		current_study++;
		$("#boxes li:first").everyTime(10*1000, 'studies',function(){
			$("#boxes li:first h2").html(studies[current_study].title);
			$("#boxes li:first p").html(studies[current_study].body);
			current_study++;
			if (current_study>=studies.length) current_study=0;
		});
	}, 'json');
	$("#boxes .next").click(function(event){
		current_study++;
		if (current_study>=studies.length) current_study=0;
		if (studies[current_study]){
			$("#boxes li:first h2").html(studies[current_study].title);
			$("#boxes li:first p").html(studies[current_study].body);
		}
	});
	$("#boxes .prev").click(function(event){
		current_study--;
		if (current_study<0)current_study+=studies.length;
		if (studies[current_study]){
			$("#boxes li:first h2").html(studies[current_study].title);
			$("#boxes li:first p").html(studies[current_study].body);
		}
	});
});
