function overlayUpcoming(idx, nexit) {
	$(".overlay").remove();
	
	$(".upcoming-photo").each(function (i) {
		$(this).unbind('click').unbind('hover');
		
		$(this).css('cursor', 'pointer');
		
		var overlay = document.createElement("div");
		if (i != idx) {
			$(overlay).css('opacity', '0.7').addClass("overlay");
		} else {
			$(overlay).css('opacity', '0.7');
		}
		$(this).append(overlay);
		
		$(this).click(function (e) {
			window.location.href = nexit[i].uri;
		});
		
		$(this).hover(
			function() {
				$(".upcoming-photo:not(:eq(" + i + "))").children('div').css('opacity', '0.7').addClass('overlay');
				$(this).children('div').removeClass('overlay');
				
				var titleimg = document.createElement("img");
				var dateimg = document.createElement("img");
				
				if (nexit[i].naziv != "" && nexit[i].datum != "" && nexit[i].sat != "") {
					$(titleimg).attr('src', '/umbraco/imageGen.ashx?text=' + escape(nexit[i].naziv) + '&Fontsize=31&Font=/font/Jigsaw-Stencil-CE.ttf&FontColor=%23cc001d&FontStyle=Regular&BgColor=%23272727&Width=570');
					$(dateimg).attr('src', '/umbraco/imageGen.ashx?text=' + escape(nexit[i].datum + " u " + nexit[i].sat) + '&Fontsize=29&Font=/font/Jigsaw-Stencil-CE.ttf&FontColor=%23FFFFFF&FontStyle=Regular&BgColor=%23272727&Width=570');
				
					$("#nexit-title").empty().append(titleimg);
					$("#nexit-date").empty().append(dateimg);
					$("#nexit-link").empty().html(nexit[i].url);
				}
				
				//overlayUpcoming(i, nexit);
			}, function () {
				$(".upcoming-photo:not(:eq(" + i + "))").children('div').css('opacity', '0.7').addClass('overlay');
			}
		);
	});
}

$(function() {
	var nexit = "";
	
	$(".upcoming-date").css('opacity', '0.8');
	
	$("#nexit h2").unbind('hover');
	$("#nexit h3").unbind('hover');
	
	$.get('/NexitJSON.aspx', {}, function(data) {
		nexit = data;
		
		var titleimg = document.createElement("img");
		var dateimg = document.createElement("img");
		
		$(titleimg).attr('src', '/umbraco/imageGen.ashx?text=' + escape(data[0].naziv) + '&Fontsize=31&Font=/font/Jigsaw-Stencil-CE.ttf&FontColor=%23cc001d&FontStyle=Regular&BgColor=%23272727&Width=570');
		$(dateimg).attr('src', '/umbraco/imageGen.ashx?text=' + escape(data[0].datum + " u " + data[0].sat) + '&Fontsize=29&Font=/font/Jigsaw-Stencil-CE.ttf&FontColor=%23FFFFFF&FontStyle=Regular&BgColor=%23272727&Width=570');
		
		$("#nexit-title").empty().append(titleimg);
		$("#nexit-date").empty().append(dateimg);
		$("#nexit-link").empty().html(data[0].url);
		
		overlayUpcoming(0, nexit);		
	}, 'json');
});
