$(document).ready(function(){
     $('#scrolling_testimonials').hide();
     i = 0;
     last ='';
     pullQuotes();
     $('#client').live('hover', function(){
          if(last[0] != $(this)[0]){
               if(last != ''){
                   last.children(".clientInfo").slideUp();
                   last.animate({
                         backgroundColor: "#FFFFFF"
                    }, 500);
                   last.css({'cursor':'pointer'});
               }
               $(this).children(".clientInfo").slideDown();
               $(this).animate({
                    backgroundColor: "#ECEDED"
               }, 500);
               $(this).css({'cursor':'auto'});
               last = $(this);
          }
     }); 
	 $('#affiliation').live('hover', function(){
          if(last[0] != $(this)[0]){
               if(last != ''){
                   last.children(".clientInfo").slideUp();
                   last.animate({
                         backgroundColor: "#FFFFFF"
                    }, 500);
                   last.css({'cursor':'pointer'});
               }
               $(this).children(".clientInfo").slideDown();
               $(this).animate({
                    backgroundColor: "#ECEDED"
               }, 500);
               $(this).css({'cursor':'auto'});
               last = $(this);
          }
     }); 
     var timer = setInterval(toggleQuote, 10000);
     function toggleQuote(){
          if(i == locations.length) i = 0;
          var quote = locations[i][0];
          var author = locations[i][1];
          var affiliation = locations[i][2];
          $('#scrolling_testimonials').fadeOut(500, function(){
               $('#testimonialQuote').html(quote);
               $('#testimonialAuthor').html(author);
               $('#testimonialAffiliation').html(affiliation);
               $('#scrolling_testimonials').fadeIn('slow');
          });
          i++;
     }
     function pullQuotes(){
          $.getJSON('ajax/testimonials.json', function(data) {
              locations = [];
               $.each(data.testimonials, function(i, obj) {
                   locations.push([obj.quote, obj.author, obj.affiliation]);
               });
               toggleQuote();
          });
     }
});
