var slides  = new Array();
var animating = false;
var currentSlide = null;
var timerId = null;

$(document).ready(function() {
	$(".side-info").each(function(i) { 
		slides[i] = $(this).attr("id");
	}); 
	if(slides) {
		$("#"+slides[0]).parent().addClass("billboard-active");
	}
	$(".side-img").each(function(i, e) { 
		$(e).click( function(event) { 
			go(i, slides);
		});
	});   

	var i = 0
	currentSlide = i;
	i++;

	if(!slides[i]) { i=0; }
	window.timerId = setTimeout(function(){go(i, slides)}, 5000);    
});

function go(i, slides) {
	if(window.animating) {
		return false;
	}

	if(i == window.currentSlide) {
		return false;
	}
	window.currentSlide = i;
	$(".billboard-active").removeClass("billboard-active");
	slide = $("#"+slides[i]);
	var html = slide.children(".desc").html();
	var html_img = slide.children(".image").html();

	window.animating = true;

	$("#billboard-image-big").html(html_img);

	$("#billboard-desc-big").animate({'height' : '0px', 'padding-top' : '0px', 'padding-bottom' : '0px'}, 600);
		$("#billboard-desc-big").queue(function() {
		$("#billboard-desc-big").html(html);
		$("#billboard-image-big").html(html_img);


		$("#billboard-desc-big").animate({'height' : '58px', 'padding-top' : '10px', 'padding-bottom' : '10px'}, 600);
		
		slide.parent().addClass("billboard-active");
		
		window.animating = false;
		$(this).dequeue();
	});
	i++;

	clearTimeout(window.timerId);

	if(!slides[i]) { i=0; }
	window.timerId = setTimeout(function(){go(i, slides)}, 5000);
}

