$(document).ready(function(){
	
	// activates SuperFish CSS Menu
	$('ul#nav').superfish({
		autoArrows: false
	}); 

	// fixes some IE6/7 CSS compatibility issues
	$('#nav > li:first-child a').css('padding-left', '22px');
	$('#nav > li:last-child, #nav > li:last-child > a').css('background-image', 'none');
//	$('#nav li:last-child ul li').css({'min-width': '175px', 'min-width': 'auto !important', 'width': '175px'});
	
	// Make main navigation unclicable if have sub nav
	// $('#nav li').each(function(i){
	// 	if ($(this).find('ul').length >= 1) {
	// 		$(this).children('a').click(function(event){
	// 			event.preventDefault();
	// 		});
	// 	}
	// });
	
	
	// NextGen Gallery modifications:
	
	$('a.image_list_link').live('click', function(){
		$('#image_list ul').toggle();
		
		return false;
	});
	
	$('#image_list a').live('click', function(){
		$currentPage = $(this).parent().index()+1;
		$imageURL = $(this).attr('href');
		$imageTitle = $(this).text();
		$imageDescription = $(this).parent().find('.image_description').text();
		$imageDownloadLink = $(this).parent().find('.image_download_link').text();
		
		$nextImagePid = $(this).parent().next().children().attr('id');
		if (!$nextImagePid) {
			$nextImagePid = $(this).parent().parent().find('li:first a').attr('id');
		}

		//replace image:
		$('.pic img').attr('src', $imageURL);
		// replace pid on the "next" link:
		$('.next a').attr('id', 'ngg-next-'+$nextImagePid);
		$('.pic a').attr('id', 'ngg-next-'+$nextImagePid);
		// set current page
		$totalPages = $('.next a span').text().substring(3, 4);
		$('.next a span').text('('+$currentPage+'/'+$totalPages+')');
		// replace image title
		$('.ngg-imagebrowser-nav h3').text($imageTitle);
		// replace image description
		$('.ngg-imagebrowser-desc p').text($imageDescription);
		// replace image custom field
		if ($imageDownloadLink) {
			$('.download_link').show();
			$('.download_link').attr('href', $imageDownloadLink)
		}
		else {
			$('.download_link').hide();
		}
		
		// hide image list
		$('#image_list ul').toggle();
		
		return false;
	});
	
});
