var j = jQuery.noConflict();
var currentPageClass = 'currentItem';
var hideOtherOpenMenuItems = true;

j(function() {
	
	/* Find and hide all menus not related open menu then add a class to the current active one */
	j(".Catelogue div > ul")
		.find('ul.dropDown')
		.hide()
		.end()
		.find('ul:not(:hidden)')
		.parent('li')
		.addClass('Open')		
	;
	

	/* Find all items with a submenu - make the a tag into a div */
	j(".Catelogue a + ul")
		.prev()
		.each(function (i) {
			j(this).replaceWith('<div class="hasChildren"><div class="itemWrap"><span>' + j(this).text() + '</div></span></div>')
		})
	;
	j(".Catelogue span")
		.each(function (i) {
			j(this).addClass('Bugg')
		})
	;
	

	/* Add a hover state to the divs */
	j(".Catelogue div.hasChildren").hover(
		  function () {
			j(this).addClass('Hover');
		  }, 
		  function () {
			j(this).removeClass('Hover');
		  }
		)
	;

	/* Slide toggles */
	j(".Catelogue div.hasChildren").live("click", function(){
		j(this)
			.parent()
			.toggleClass('Open')
			.end()
			.next("ul")
			.slideToggle()
		;
		if (hideOtherOpenMenuItems==true){
			j(this)
				.parent()
				.siblings(".Open")
				.toggleClass('Open')
				.find("ul:first")
				.not('.noAnimate')
				.slideToggle()
			;
		}
	});
	
	//j(".Catelogue .hasChildren a").corners();
	//j(".Catelogue .hasChildren .itemWrap").corners();	

	//j(".Catelogue .hasChildren,.Catelogue a").corner("br tr 6px");
	
	j(".Catelogue .hasChildren,.Catelogue a")
		//.wrapInner('<span class="wrap"></span>')
		.append('<span class="CornerBottomRight"></span><span class="CornerTopRight"></span>')
	;

	//j('.Catelogue a span').corner();

});
