$.fn.image = function(src, f){
    return this.each(function(){ 
        var i = new Image();
        i.src = src;
        i.onload = f;
        this.appendChild(i);
    });
}

$.fn.addCaption = function(title, f){
    return this.each(function(){ 
        $(this).append('<div class="caption">'+title+'</div>');
    });
}

$(document).ready(function() {
						   $('#menu li a').not('.current').mouseenter(function() {
														  $(this).siblings('span.flyout').css({display: 'block', width: '0px'})
														  								 .animate({width: '170px'});
//														  $(this).parent('li').sibings().not('.current').children('span.flyout').animate({width: '0px'});
														  })
						   								  .mouseleave(function() {
														  $(this).siblings('span.flyout').animate({width: 'hide'});
														  });
						   $('img').each(function() {
												  if ($(this).attr('pop') !== undefined) {
													  $(this).parent('a').click(function(e) {
																		   e.preventDefault();
																		   $('#popup #loading').show();
																		   $('#popup').show('slow')
																		   			  .animate({marginTop: '-255px',
																								marginLeft: '-500px',
																								width: '1000px',
																								height: '665px'
																								})
																					  .children('#inner').hide()
																					  					 .empty()
																					  					 .image(BASE_URI+$(this).children('img').attr('pop'),function(){
																																										  $(this).parents('#inner').show('slow');
																																										  $('#popup #loading').hide();
																																										});
																			$('#popup').children('#inner').addCaption($(this).children('img').attr('alt'));


//'<img src="'++'"/>'
																			});
												  }
												  });
						   $('.close').click(function(e) {
													  e.preventDefault();
													   $('#popup').hide('slow')
																  .animate({marginTop: '0px',
																			marginLeft: '0px',
																			width: '0px',
																			height: '0px'
																			});
													  });
						   });
