// JavaScript Document

	$(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$='http://webdev.sbretc.org/" + src + "']" );

		}
		else{
			var src = $link.attr( "href" ),
    		title = $link.siblings( "img" ).attr( "alt" ),
    		$modal = $( "img[src$='" + src + "']" );
		};
 
    var img = $( "<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",
	position: "center",
    modal: false
    });  
    }, 1 );
    
    }

//Bind to the ui-widget-overlay and watch for when it is clicked
      $('.ui-widget-overlay').live("click", function() {
//Close the dialog
  $(".ui-dialog").hide(); $(".ui-widget-overlay").hide();
      }); 
	  
// resolve the icons behavior with event delegation
    $( "ul.gallery > li" ).click(function( event ) {
										  
    var $item = $(this).closest("a"),
    $target = $( event.target );
									

/*
									$.fn.fullSizeFullOpacity3 = function() {
    return this.each(function() {
     $(this).find('img').each(function() {
      if (this.src == $img.closest('a')[0].href) {
       $(this).css('opacity', 1.0);
      }
     });
*/
    viewLargerImage( $target );
   
    return false;
    });
    });

(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.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)
