jQuery(document).ready(function($) {
	initMenus();
	
	function initMenus() {
		$('ul#menu-sidebar ul').hide();
		$('ul#menu-sidebar li a').click(function() {
			var checkElement = $(this).next();
			var parent = this.parentNode.parentNode.id;
			if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
				$('#' + parent + ' ul:visible').parents('li').css('background-image','url("/wp-content/themes/superior/images/menu-close.png")');
				$('#' + parent + ' ul:visible').slideUp('normal');
				checkElement.slideDown('normal');
				checkElement.children("li").css('background-image','url("/wp-content/themes/superior/images/menu-open.png")');
				checkElement.parents("li").css('background-image','url("/wp-content/themes/superior/images/menu-open.png")');
				
				return false;
			}
		});
	}
	
	$('.gallery-thumbs a').click(function() {
		var id = $(this).attr('id');
		$('.gallery-image').fadeOut('slow');
		$('#image-' + id.substr(6)).fadeIn('slow');
		return false;
	});
	
	$('.gallery-navigation a.next').click(function() {
		var $current = $('.gallery-image:visible')
		$next = $current.next('.gallery-image');
		if($next.length == 0 ) {
			$next = $('.gallery-image:first');
		}
		$current.fadeOut('slow');
		$next.fadeIn('slow');
		return false;
	});
	
	$('.gallery-navigation a.previous').click(function() {
		var $current = $('.gallery-image:visible')
		$previous = $current.prev('.gallery-image');
		if($previous.length == 0 ) {
			$previous = $('.gallery-image:last');
		}
		$current.fadeOut('slow');
		$previous.fadeIn('slow');
		return false;
	});
	
});
