

$(document).ready(function(){
  var iNum = $('#sSlider img').length;
  var strDot = '<div class="dot"></div>';

  for (i=1;i<=iNum;i++){
    $("#dots").append(strDot);
  }  

  $('#dots .dot').each(function(){
    $(this).click(function(){
      clearTimeout(s);
      swImage($(this).index(), iNum);
    });
  });
  
  swImage(0, iNum);
});


function swImage(n, iNum) {
  $('#dots .rdot').removeClass('rdot');

  k = parseInt(0);
  j = parseInt(4);
  v = Math.floor( Math.random() * (j - k + 1) ) + k;

  if (v == 0) { $('#sSlider img:visible').animate({opacity: "hide", top: "85"}, 600, function(){ $(this).css({top:"0"});} );}
  if (v == 4) { $('#sSlider img:visible').animate({opacity: "hide", top: "-85"}, 600, function(){ $(this).css({top:"0"});} );}
  if (v == 3) { $('#sSlider img:visible').animate({opacity: "hide", width: "50%", left: "25%", height: "0"}, 600, function(){ $(this).css({left: "0", width: "100%", height: "100%"});} );}
  if (v == 2) { $('#sSlider img:visible').animate({opacity: "hide", width: "50%", left: "25%", top: "50%", height: "0"}, 600, function(){ $(this).css({left: "0", top: "0", width: "100%", height: "100%"});} );}
  if (v == 1) { $('#sSlider img:visible').animate({opacity: "hide", width: "50%", left: "25%", top: "100%", height: "0"}, 600, function(){ $(this).css({left: "0", top: "0", width: "100%", height: "100%"});} );}


  $('#dots .dot:eq('+n+')').addClass('rdot');
  $('#sSlider img:eq('+n+')').animate({opacity: "show"}, 1000);

  n++;
  if(n==iNum) {n=0;}
  s = setTimeout("swImage('" + n + "', '"+ iNum +"')", 4000);
}
