jQuery(document).ready(function($) {

	// Instead of stycky footer
	$('.sidebar').css('min-height', $(window).height()-168 );
	var resizeTimer = null;
	$(window).bind('resize', function() {
	    if (resizeTimer) clearTimeout(resizeTimer);
	    resizeTimer = setTimeout(function(){
	  		$('.sidebar').css('min-height', $(window).height()-168 );
		}, 100);
	});

    
    /* Activate jCarousel */
    jQuery('#mycarousel').jcarousel({
        vertical: true,
        scroll: 2,
        visible: 7
    });
    

    /* Correct a thumbnail issue in webkit browsers */
    if ($.browser.webkit) {
	    $('.jcarousel li img').css('margin-top','-19px');
	}
	

	var first_item = $('.ngg-galleryoverview li.jcarousel-item a')[0];
	if (first_item) select_item(first_item);

	$('.ngg-galleryoverview li.jcarousel-item a')
		.mousedown(function(){
			
			select_item(this);

			$(this).parent().parent().find('li a:not(.active)')
				.animate({'opacity':'1'},100);
			
			return false;
		})
		.click(function(){
			return false;
		})
		.mouseenter(function(){
			//$(this).not('.active').animate({'opacity':'7.5'},100);			
		})
		.mouseleave(function(){
			//$(this).not('.active').animate({'opacity':'0.5'},100);
		})
		//.css('opacity','0.75');
	
    

	function select_item(element) {
		e=$(element);
		var item_url = e.attr('href');
		var item_description = e.attr('title');

		var main_image_html = '<a style="display:none;" href="'+item_url+'" id="image_link" title="Expand this image"><img src="'+item_url+'" alt="'+item_description+'" /></a>';
		main_image_html += '<h2 style="font-size:1em;">'+item_description+'</h2>';
		
		// $('#main_image')
		// 	.html('<span class="loading">loading...</span>')
		// 	.show();

		// $('<img />')	// Preload the image, before fading it in.
		//     .attr('src', item_url)
		//     .load(function(){
		//         $('#main_image')
		//         	.html(main_image_html)
		//         	.find('#image_link')
		//         		.fadeIn('fast')
		//         		.lightBox();
		//     });

		$('#main_image')
	    	.stop(false,true)
	    	.html(main_image_html)
	    	.find('#image_link')
	    		.show()
	    		.lightBox();


		e.parent().parent().find('li a').removeClass('active');
		e.animate({'opacity':'0.75'},100);
		e.addClass('active');
	};

	$.extend($.fn.disableTextSelect = function() {
		return this.each(function(){
			if($.browser.mozilla){//Firefox
				$(this).css('MozUserSelect','none');
			}else if($.browser.msie){//IE
				$(this).bind('selectstart',function(){return false;});
			}else{//Opera, etc.
				$(this).mousedown(function(){return false;});
			}
		});
	});
	$('.jcarousel-container').disableTextSelect();

	
	
});








(function($) {
    // $() will work as an alias for jQuery() inside of this function
})(jQuery);
