 

document.observe('dom:loaded', function() {
	var categoryId = document.location.href.match(/\#.*categoryId=([0-9]+)/);
	if (categoryId) { showContent(categoryId[1]); }

	convertLinks($$('.submenu a'));
});


function convertLinks(links) {
	links.each(function (link) {
		if (link.href.toQueryParams().categoryId) {
			// if this link links to a categoryId:
			link.observe('click', function(evt) { evt.stop(); scroll(0,0); showContent(link.href.toQueryParams().categoryId); return false; });
		}
	});
}


function showContent(categoryId) {
	if (document.location.href.toQueryParams().categoryId) {
		// url contains ?categoryId -> redirect to #categoryId
		document.location.href = './#categoryId='+categoryId;
	}
	else {
		var url = 'Ajax/content.php';
		document.location.href = '#categoryId='+categoryId;
		new Ajax.Request(url, {
			method: 'get',
			parameters: { categoryId: categoryId },
			onSuccess: function(transport) {
				$('content').update(transport.responseText);
			}
		});
	}
}
