// add commas to digits
String.prototype.digits = function(){
  return this.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
}

$(document).ready(function(){
  
  $timer = 0;
  $cycles = ["div#promoMegadog", "div#cake", "div#shake", "div#promoMegapromo", "div#promoProf", "div#cone", "div#hotdog"];
  setInterval(cycleFront, 30000);
  
  $.getJSON('http://graph.facebook.com/WendysAustralia', function(data) {
    $likes = new String(data['likes']).digits();
    $('ul.promos li.facebook-promo span').text($likes+' PEOPLE LOOOOOOVE WENDYS!');
  });
  
  
});

$(window).load(function() {
  $('#promo').nivoSlider({
    effect: 'slideInRight'
  });
});

function cycleFront() {
    $($cycles[$timer]).fadeOut(500, function () {
	  $timer = $timer+1;
	  if ($timer == $cycles.length) {
		 $timer = 0;
	  };
      $($cycles[$timer]).fadeIn(500);
    });
};


