  jQuery(function() {
  
  	$('#summary').fadeIn(300);
  	
/* preload images */	
$.preload( '#gallery img', {//the first argument is a selector to the images
		onRequest:request,
		onComplete:complete,
		onFinish:finish,
		placeholder:'placeholder.png',//this is the really important option
		notFound:'notfound.png',//optional image if an image wasn't found
		threshold: 2 //'2' is the default, how many at a time, to load.
	});
	
	function update( data ){
		$('#done').text( ''+data.done );
		$('#total').text( ''+data.total );
		//$('#loaded').html( ''+data.loaded );
		//$('#failed').html( ''+data.failed );
	};
	function complete( data ){
		update( data );
		//$('#image-next').html( 'none' );//reset the "loading: xxxx"
		//$('#image-loaded').html( data.image );
	};
	function request( data ){
		update( data );
		$('#image-next').text( data.image );//set the "loading: xxxx"
	};
	function finish(){//hide the summary
		$("#summaryInner img").hide();
		$('#summary').fadeOut(800);
		$('#gallery').fadeIn(1800);
	};  	
  	

/* make gallery draggable */
	$("#gallery").draggable({
		cursor: 'move'
	 });

/* enable mousewheel */   
 $("#container").bind('wheel',function(event,delta){ 
 
 		if (delta>0) {
 			newLeft = (parseInt($("#gallery").css("left"))+(60*delta))+'px';
			$("#gallery").css({'left' : newLeft});
			}
		else {
			newLeft = (parseInt($("#gallery").css("left"))+(60*delta))+'px';
			$("#gallery").css({'left' : newLeft});
		}
        
         });  
   
 /* soften navigation */  
 $("#nav").hover(function () {
      $("#nav").css({ "opacity":"1"});
    }, function () {
      var cssObj = {
         "opacity": "0.3"
      }
      $("#nav").css(cssObj);
    });  
    
   
 /* initialize shadowbox */     
   Shadowbox.init({
    overlayOpacity: 1,
    displayNav: true,
    fadeDuration: '1.2',
    resizeDuration: '0.3',
    viewportPadding: '5',
    animSequence: 'wh',
    displayCounter: false,
    autoDimensions: true,
    slideshowDelay: '5',
    continuous: true,
    players:  ['img'],
    onFinish:function(){ $('#sb-body-inner img').one('click',Shadowbox.close);  }
	});

/* show image info */
$("#gallery a").hover(function () {
			
			/*$ele = $(this).prev();			
			$ele.fadeIn("slow"); 
						   },function(){
						   $ele.fadeOut("slow"); */
				$ele = $(this).prev();
				$ele.filter(':not(:animated)').fadeIn("slow");
													}, function () { $ele.fadeOut("slow");			
				});
				


/* cursors */

if($.browser.mozilla) { $("#gallery").css("cursor", "-moz-grab");  }
			else { $("#gallery").css("cursor", "url(files/openhand.cur)");  }
			
//var cursor = $("#gallery").draggable('option', 'cursor');
//alert(cursor);
			
			$("#gallery").mousedown( function() { 
				if($.browser.mozilla) { $("#gallery").css("cursor", "-moz-grabbing"); }
				else { $("#gallery").css("cursor", "url(files/closedhand.cur)"); }
				//alert($(this).css("cursor"));
			});
			
			$("#gallery").mouseup( function() { 
				if($.browser.mozilla) { $("#gallery").css("cursor", "-moz-grab"); }
				else { $("#gallery").css("cursor", "url(files/openhand.cur"); }
			});

$("#thumbnails").click( function () {
	window.print();
		});	
		

});