(function($){ 
	$(function(){
		// Cufon
		// Cufon.replace('#navigation li a', { hover: true, fontFamily: 'Futura' });
		
		// Dropdown Menu
		$('#navigation ul li:not(.current_page_item, .current_page_ancestor, .current_page_parent) ul').slideUp(0).addClass('jquery');
		$('#navigation ul > li:not(.current_page_item, .current_page_ancestor, .current_page_parent)').hover(function () {
			$("ul", this).stop(true, true).slideDown(200);
		},function () {
			$("ul", this).stop(true, true).delay(140).slideUp(100);
		});
		$('#navigation ul:first > li').addClass('first-children');
		
		//Cancel if there's only one subnav item
		$length = $('#navigation .current_page_parent ul li, #navigation .current_page_ancestor ul li, #navigation .current_page_item ul li').length;
		if( $length == 1 ) {
			$('#navigation .current_page_parent > ul, #navigation .current_page_ancestor > ul, #navigation .current_page_item > ul').remove();
			$('body').removeClass('page-parent, page-child');
			
			return false;
		}
		
		if ($('#navigation li.current_page_item ul, #navigation li.current_page_ancestor ul, #navigation li.current_page_parent ul').is(':visible')){
			$('body').addClass('hasSubNav');
		}

		//Randomly sort image gallery
		function randOrd() { return(Math.round(Math.random())-0.5); }
		
		$targets = $('#sidebar-media .ngg-gallery-thumbnail-box');
		$targetCount = $targets.length;
		
		if($targetCount > 1) {
			$targets.remove();
			
			var indices = new Array();
			for (i=0; i < $targetCount; i++) { 
				indices[indices.length] = i; 
			}
			
			indices = indices.sort(randOrd);
			$i = 0;
			$.each(indices,function(j,k) { 
				if($i == 4) return;
				$('#sidebar-media .ngg-galleryoverview').append($targets.eq(k)); 
				$i++;
			});
		
		}
		
		 
		//Comments hint box
		$('#commentsform #rules-toggle').show(0);
		$('#commentsform .comment-rules').hide(0);
		$('#commentsform #rules-toggle a').toggle(
			function(){
				$('#commentsform #rules-toggle a').html("hide" );
				$('#commentsform .comment-rules').stop(true,true).slideDown(140);
				return false;
			},
			function(){
				$('#commentsform #rules-toggle a').html("show allowed tags" );
				$('#commentsform .comment-rules').stop(true,true).slideUp(130);
				return false;
			}
		);
	});
})(jQuery);

