// JavaScript Document


$(document).ready(function() {
	$('#gallery').fadeIn('fast');
	$('#main_image img').fadeIn('slow');
	/**
	 * All the functions below, are used to update the summary div
	 * That is not the objective of the plugin, the really important part 
	 * is the one right below. The option placeholder, and threshold.
	 
	$.preload( '.slideit', {//the first argument is a selector to the images
		onFinish:finish,
		placeholder:'/img/loadingimages.gif',//this is the really important option
		threshold: 150 //'2' is the default, how many at a time, to load.
	});
	
	function finish(){//hide the summary
		$('#gallery').fadeIn('fast');
	};
					   
	*/					   				   		   

	$(".slideit").jCarouselLite({
        btnNext: ".next",
        btnPrev: ".prev",
		circular: true,
		visible: 15,
		scroll: 5,
		//auto: 2000,
		speed: 500
    });
	
$('#load').hide();

	// fade out inactive thumbnails
	$('ul#gallery li.active').siblings().css({display:'none',opacity:'0.4'}).fadeIn(500);
	
	// thumbnails hover effects
	$('ul#gallery li').hover(function() {
			$(this).not('.active').fadeTo('fast',1);
			$(this).not('.active').css('position', 'relative').css('left', 0).css('top', 0); // Fixes Safari 2 rendering issue
		}, function() {
			$(this).not('.active').fadeTo('fast',0.4);
		}
	);
		



// fade in default image
	$('ul#gallery li').click(function() {	
		var img = $(this).children('a').attr('href');
		$('.default').fadeOut('fast');
		$('#load').fadeIn('fast').show();
		// fade out and remove active classes on all other thumbnails								 
		$(this).siblings().removeClass('active').fadeTo('fast',0.4);	
		// set class for clicked thumbnail to active
		$(this).addClass('active')
		// get image source reference from the thumbnail link and store in a variable
		//$('#load').html('<img src="/assets/img/loading.gif" />').fadeIn(800);
		$('#main_image').html('<img src="/assets/img/loading.gif" class="loadpos" />').fadeTo(800, 1);
		//	$('#main_image').fadeIn(800, function() {
			$('#main_image').load("imageloader.asp?" + img);
		//$('#main_image').html('<img src="/assets/img/loading.gif" />').fadeTo(800);
		});
	//});
	
});