(function($){
 $.fn.zeroSlide = function(options) {

  var defaults = {
  };
  var options = $.extend(defaults, options);
    
  return this.each(function() {
    var obj;
    var id;
    obj = $(this);
    id=obj.attr("id");
    
    //
    var cnt = $("#"+id+" ul li").length;
    var h = $("#"+id+" ul li").height();
    
    $("#"+id+" ul").height(h*cnt);    
    
    document.getElementById(id).t=-60;
    
    
    $("#"+id).append("<div class='dots' />")
    for(i=0;i<cnt;i++){
      var x = $("<a href='#' />").click(function(){
        zeroSlideMove(id,$(this).index()+1);
        
        /*
          $(".dots a img").attr("src","images/dot_white.png");
          $(this).children("img").attr("src","images/dot_orange.png");
          
          var s = $(this).index()*h*-1;
          
          $("#"+id+" ul").stop().animate({marginTop:s+"px"},"slow");
        */  
        } ).html("<img src='images/dot_white.png' />");
        
        $(".dots").append(x);
    }
    $(".dots a:nth-child(1)").children("img").attr("src","images/dot_orange.png");
    $(".dots a:nth-child(1)").addClass("active");
    
    setInterval("zeroSlideAutoMove('"+id+"')",100);
  });
 };
})(jQuery);

function zeroSlideAutoMove(id){

  var t = document.getElementById(id).t;
  if(t==60){
    document.getElementById(id).t=0;
    
    var i = $(".dots a.active").index()+2;
    if(i > $("#"+id+" ul li").length){
      i=1;
    }
    zeroSlideMove(id,i);
  }else{
    document.getElementById(id).t++;
  }
}
function zeroSlideMove(id,i){
  $(".dots a img").attr("src","images/dot_white.png");
  $(".dots a").removeClass("active");
  $(".dots a:nth-child("+i+")").addClass("active");
  $(".dots a:nth-child("+i+")").children("img").attr("src","images/dot_orange.png");
  
  var h = $("#"+id+" ul li").height();
  var s = (i-1)*h*-1;
  
  $("#"+id+" ul").stop().animate({marginTop:s+"px"},"slow");
}
