$(document).ready(function()
{
  var c_delay = 5000; // milliseconds
  var c_current = 1;
  var c_old = 0;
  var c_width = 180;
  
  if($("#clients_rotator ul").children().length > 1)
  {
    var c_t = setTimeout(c_next,c_delay);
  }
  
  $("#logo_left a").click(function()
  {
    clearTimeout(c_t);
    c_old = c_current;
    c_current--;
    
    if (c_current == 0)
    {c_current = $("#clients_rotator ul").children().length}
    
    c_animateRight();
    return false;
  });
                             
  $("#logo_right a").click(function()
  {
    clearTimeout(c_t);
    c_old = c_current;
    c_current++;
    if (c_current == $("#clients_rotator ul").children().length + 1)
    {c_current = 1}
    
    c_animateLeft();
    return false;
  });

  function c_next()
  {
    c_old = c_current;
    c_current++;
    if (c_current == $("#clients_rotator ul").children().length + 1)
    {c_current = 1}
 
    c_animateLeft();
    c_t = setTimeout(c_next,c_delay);
  }

  function c_animateLeft()
  {
    //$(".rotator_menu a:nth-child("+ old +") img").attr("src", "/images/b_rotator-up.gif");
    //$(".rotator_menu a:nth-child("+ current +") img").attr("src", "/images/b_rotator-over.gif");
    
    $("#clients_rotator ul li:nth-child("+ c_current +")").css("left", c_width +"px");
    $("#clients_rotator ul li:nth-child("+ c_current +")").animate({"left": "0px"}, 400, "swing");
    $("#clients_rotator ul li:nth-child("+ c_old +")").animate({"left": -c_width+"px"}, 400, "swing");
    //$("#slide_contents li:nth-child("+ current +")").fadeIn();
    //$("#slide_contents li:nth-child("+ old +")").fadeOut();
  }
  
  function c_animateRight()
  {
   // $(".rotator_menu a:nth-child("+ old +") img").attr("src", "/images/b_rotator-up.gif");
    //$(".rotator_menu a:nth-child("+ current +") img").attr("src", "/images/b_rotator-over.gif");
    
    $("#clients_rotator ul li:nth-child("+ c_current +")").css("left", -c_width +"px");
    $("#clients_rotator ul li:nth-child("+ c_current +")").animate({"left": "0px"}, 400, "swing");
    $("#clients_rotator ul li:nth-child("+ c_old +")").animate({"left": c_width+"px"}, 400, "swing");
    //$("#slide_contents li:nth-child("+ current +")").fadeIn();
    //$("#slide_contents li:nth-child("+ old +")").fadeOut();
  }
});
