
var firstCommentLoad = true;
var numLoads = 0;

function loadCustomerComments() {
   $.post("/unc?action=ajaxnextcomments",commentsLoaded,"html");
}

function showComment(index) {
   if ($("#thecomment:visible").length == 1) {
      $("#thecomment").fadeOut(1500,function(){showComment(index);});
      $("#custdata").fadeOut(1500);
      return;
   }
   var $next = $("#comment"+index);
   $("#initials").html($next.attr("initials"));
   $("#location").html($next.attr("location"));
  
   $("#thecomment").text( $next.text());
   $("#thecomment").fadeIn(1500);
   $("#custdata").fadeIn(1500,function(){$("#morecomments").show();});
   var theHeight = $("#thecomment").height();
   
   var topAdjust = (70-theHeight) / 2;
   $("#beginquote").animate({top: topAdjust+8 },1000);
   $("#endquote").animate({top: theHeight+topAdjust-10  },1000);

   $("#thecomment").css("margin-top",topAdjust);
   $("#custdata").css("margin-top",theHeight+5+topAdjust);
   if ($("#comment"+(index+1)).length === 0) {
      if (++numLoads == 20)
         return;  //stop showing after 20 loads
      loadCustomerComments();
      index = 0;
   }
   setTimeout(function(){showComment(index+1);},9000);
}

function commentsLoaded(data) {
   $("#commentLoader").html(data);
   if (firstCommentLoad) {
      $("#beginquote").animate({top: "10px"},500).animate({left: "5px"},1000);
      $("#endquote").animate({top: "60px"},500).animate({left: "419px"},1000,function(){showComment(1);});
      firstCommentLoad = false;
   }
}

$(document).ready(function() {
   var currentDock = 0;
   var showing = -1;
   var hiding = -1;
   
   var opts = {
      align: 'middle',   // horizontal Dock with images expanding downwards in the vertical axis...
      size: 65,        // set the maximum minor axis (vertical) image dimension to 48px
      coefficient: 3,  // def 1.5
      distance: 24,    // def 54
      duration: 500,   // def 500
      labels: 'mc',    // add labels..
      hovercb: function(hoverDock) { 
         if (currentDock != hoverDock) {
            $(".dockprod").hide();
            $("#dockprod"+hoverDock).css("display","inline-block");
            currentDock = hoverDock;
         }
      }
   };

   $("#dock").jqDock(opts);
   $("#dockprod0").show();
//   setTimeout(function(){$(".jqDock").corners();},2000); 
   loadCustomerComments();
   
   $(".prodimage").click(function(){ document.location = $(this).attr("link"); });
   
   $("#morecomments span").click(function() {
      if (buttonIsEnabled("#morecomments")) {
         disableButton("#morecomments");
         var gotoUrl = uncdomain+"/unc?action=customersSay.jsp";
         setTimeout(function(){document.location=gotoUrl;},1);  // invoke with delay - allows screen to fully repaint disabled button
      }
   });
});
