$(document).ready(function(){
 //alert();
     var photosUl = $('.slide-show .photos-container');
     var options  = $('.slide-show #functional-panel');
     var h2 = options.find('.photo-description h2');

     var t;

     function showNext(){
          //alert();
          var curr = photosUl.find('li.active');
          var next = curr.next();
              next = (next.length==1)?next:photosUl.find('li:first');
              $(next).insertAfter(curr);
              $(curr).hide('slow').removeClass('active');//animate({opacity: 0.9},1000).removeClass('active');
              //next.addClass('active').slideDown();
              $(next).show('slow').addClass('active');
              h2.html($(next).find('img').attr('title'));
             // alert(next.length);
     }

     function showPrev(){
          var curr = photosUl.find('li.active');
          var prev = curr.prev();
              prev = (prev.length==1)?prev:photosUl.find('li:last');
              $(prev).insertBefore(curr);
              $(curr).hide('slow').removeClass('active');//animate({opacity: 0.9},1000).removeClass('active');
              //next.addClass('active').slideDown();
              $(prev).show('slow').addClass('active');
              h2.html($(prev).find('img').attr('title'));
             // alert(next.length);
     }

     $(options).find('.next').click(function(){
         clearTimeout(t);
         setTimeout(function(){
           showNext();
           loopIt();
        },400);
        return false;
     });

     $(options).find('.previous').click(function(){
         clearTimeout(t);
         setTimeout(function(){
           showPrev();
           loopIt();
        },500);
        return false;
     });

     function loopIt(){
        t = setTimeout(function(){
           showNext();
           loopIt();
        },4000);
     }
      loopIt();
});
