// JavaScript Document

	jQuery(function() {
  	   	// image preview function, demonstrating the ui.dialog used as a modal window
		
    	function viewLargerImage( $link ) {
    		if($link.attr("src")){
				var src = $link.closest( "a" ).attr("href"),
    			title = $link.attr( "alt" ),
    			$modal = $( "img[src$='" + src + "']" );
			}
			else{
				var src = $link.attr( "href" ),
    			title = $link.siblings( "img" ).attr( "alt" ),
    			$modal = $( "img[src$='" + src + "']" );
			};
 
    var img = jQuery( "<img alt='" + title + "' width='384' height='288' style='display: none; padding: 8px;' id='imgDialog' />" )
    .attr( "src", src ).appendTo( "body" );
    setTimeout(function() {
    img.dialog({
	show: "blind",		
    title: title,
    width: "auto",
	height: 500,
	position: "center",
    modal: false
    });  
    }, 1 );
    
    }

//Bind to the ui-widget-overlay and watch for when it is clicked
      jQuery('.ui-widget-overlay').live("click", function() {
//Close the dialog
  jQuery(".ui-dialog").hide(); jQuery(".ui-widget-overlay").hide();
      }); 
	  
// resolve the icons behavior with event delegation
   jQuery( "ul.gallery > li" ).click(function( event ) {
										  
    var $item = jQuery(this).closest("a"),
    $target = jQuery( event.target );
									
    viewLargerImage( $target );
   
    return false;
    });
    });

(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  jQuery.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)
