
$(function(){
    $('.photo-thumb').mouseover( function(){
              clearTimeout();               
              var thumb = this;
              var id = $(this).attr('id').replace('photo-', '');
              var fileUrl = $(this).attr('src').replace('_small', '_medium');

              var nextEl = null;
              var prevEl = null;

              var images =  $( '#preview-' + id ).children( 'div.photo-preview' );

              images.each( function() {
                    if($(this).children('img:first').attr('src') == fileUrl)
                        nextEl = this;

                    if( 'block' == $(this).css('display') )
                        prevEl = this;
              });

              if (prevEl == nextEl )
              {
                   show_comment();
              } else {
                   $(prevEl).fadeOut('fast', function(){
                        $(nextEl).fadeIn('fast', function() {
                             var o = this;
                             setTimeout( show_comment, 150 );
                        }); 

                    } );
              }

              function show_comment() {
                  $(nextEl).children( '.photo-comment-container' ).animate( { marginTop: "-56px" }, 250 );
                  $(thumb).mouseout( hide_comment );
              }

              function hide_comment() {
                                  $(nextEl).children( '.photo-comment-container' ).animate( { marginTop: "0px" }, 250 );
              }


          }, function(){});
});