$(document).ready(function() {
	if (typeof(console) != "undefined") {
		console.log($(this).attr("title") + " - initiated");
	}
	$("#projects li, #old_projects tr").click(function(event) {
		var dialogContent = $(this).html();
		var img = $(this).find("img").attr("src");
		var name = $(this).find(".name").html();
		var value = $(this).find(".value").html();
		var year = $(this).find(".year").html();
		var month = $(this).find(".month").html();
		var customer = $(this).find(".customer").html();
		var period = $(this).find(".period").html();
		var type = $(this).find(".type").html();
		
		var label_value, label_customer;
		
		if (type == "1113") {
			label_value = "Brutto eiendomsverdi";
			label_customer = "Leietager";
		} else if (type = "1114") {
			label_value = "Prosjektverdi";
			label_customer = "Befrakter";
		}
		var dialogContent = '<img src="'+img+'" width="300px" height="339px" alt="tombstone" /><div class="info_container"><div class="name">'+name+'</div><div class="label">'+label_value+':</div><div class="value">'+value+'</div>';
		
		if (type == "1113") {
			'<div class="label">Dato:</div><div class="date">'+month+' '+year+'</div>';
		}
		if (period.length > 0) {
			dialogContent += '<div class="label">Kontraktslengde:</div><div class="period">'+period+'</div>'
		}
		if (customer.length > 0) {
			dialogContent += '<div class="label">'+label_customer+':</div><div class="customer">'+customer+'</div>'
		}

		dialogContent += '</div>';
		novusDialog(dialogContent);
	});
});

/* Not big fan of jQuery UI dialog so I made our own implementation */
function novusDialog(message) {
	$("body").append('<div id="catch_clicks"></div>');
	$("body").append('<div id="dialog">'+message+'<div id="close">LUKK <strong>X</strong></div></div>');
	
	$("#close").bind("click", function() {
		$("#catch_clicks").remove();
		$("#dialog").remove();
	});
}
