
function centerVElement(centerDiv) {
	centerDiv.css('top', $(window).height()/2-centerDiv.height()/2); 
}

function getLatest() {
	$.ajax({
		  url: deliveriesUrl,
		  success: function(data) {
		    startLoop(data);
		  }
		});	

}
var data = new Array();
var counter = 0;

function startLoop(d) {
    data = d;
    setInterval("nextLoop()",6000);
    nextLoop();
}

function nextLoop() {
    var a = data.shift(); // get first
    setLink(a);
    data.push(a); // push a last
}
function prevLoop() {
    var a = data.pop(); // get last
    setLink(a);
    data.unshift(a); // push a last
}


function setLink(obj) {
    var title = obj['title'];
    var link = obj['link'];

    $('#latest').html('<a href="'+link+'" title="read further on the blog about: '+title+'">' + title + '</a>');
}

$(document).ready(function() {
	centerVElement($('#splash'));
	timePassed = true;
	$('#splash').mousewheel(function(event, delta) {
		event.preventDefault();
		if (!timePassed)
			return;
		iId = setInterval(function() {timePassed=true;clearInterval(iId);},250);
		timePassed = false;
		if (delta < 0)
			nextLoop();
		else if (delta > 0)
			prevLoop();
	});
	
	getLatest();
});

$(window).resize(function() {
	centerVElement($('#splash'));
});


