//<![CDATA[
$(document).ready(function(){			
	// Add product to catalogue
	$('.addProdToCat').click(function(e){
		
		// TODO - must be a cleaner solution
		// Prevent default link destination if it's to add-catalog-item.php
		if ($(this).attr("href").indexOf("add-catalog-item") != -1) {
			e.preventDefault();
		}
		
		// Init vars
		var nodeId = $(this).attr('rel');
		var fileURL = DOMAIN_NAME + 'account/ajax-add-catalogue-item.php';
		var nodeObject = {id: nodeId};
		
		// Provide feedback message
		$("a[rel='" + nodeId + "']").text('Adding to catalogue...');		

		// Send AJAX request
		$("a[rel='" + nodeId + "']").load(fileURL, nodeObject, function(responseText, textStatus, XMLHttpRequest) {
			if (responseText.indexOf("View") != -1) {
				// Change link, title and class if successfully added
				$(this).attr("href", DOMAIN_NAME + "account/catalogue.php");
				$(this).attr("title", "Click to view Catalogue");
				$(this).removeClass("addProdToCat");

			}
		});		
	});
});
//]]>