// gedrag projects formulier
// gebruikt jQuery
$(document).ready(function() {
	initTopbars();
	initDel();
	
});

function initDel() {
	$(".delLink").click(function() {
		if (confirm('Are you sure?')) {
			var scriptSrc = $('script[@src$=jquery.js]').attr('src').replace('js/jquery.js', '');
			var activeLink;
			activeLink = this;
			$.ajax({
				type: "POST",
				url: scriptSrc+"scripts/delete_project.php",
				data: 'miAction=del&projectId='+$(this).id().split('item-').join(''),
				dataType: "json",
				success: function(msg){
					if (msg.deleted) {
						$(activeLink).parent().parent().remove();
					} else {
						alert('Could not delete item.');
					}
				}
			});
		}
		return false;
	});
}

// Function for closing and opening the bars by clicking the top.
function initTopbars(){
	$(".topbar").click(function() {
		$(this).parent().find(".listsection").slideToggle(800);
		$(this).children("div").toggleClass("prodetid");
		$(this).children("div").toggleClass("prodactive");
	});
}