$(document).ready(function() {
  var count = $('#slideshow .slide').length;
  var rand = Math.floor(Math.random() * count);
  $('#slideshow .slide').eq(rand).fadeIn(3000, function() {
    if($.browser.msie && parseInt($.browser.version) < 9) {
      $('#smile-overlay').show();
      $('#slideshow').slideShow();                  
    } else {
      $('#smile-overlay').show('puff', {}, 600, function() {
        $('#slideshow').slideShow();                  
      });
    }
  });
});

(function($) {
  $.fn.slideShow = function() {

    function sShow(ss) {
      this.intID = 0;
      this.ss = ss;
      
      if($(ss).children('.slide').length > 1)     
        this.start();
    }
    
    sShow.prototype.start = function() {
      var instant = this;
      this.intID = setInterval(function() { instant.nextSlide(); }, 6500);                                                                                                                                                                                                            }
    
    sShow.prototype.nextSlide = function() {
      var curr = $(this.ss).children('.slide:visible');
      
      if(curr.is(':last-child')) {
        var next = $(this.ss).children('.slide:first-child');
      } else {
        var next = curr.next('.slide');
      }
      
      curr.fadeOut(2000, 'linear');
      next.fadeIn(2000, 'linear');  
    }
  
    this.each(function(i, e) {
      var s = new sShow(e);
    });

  };
})(jQuery); 

