// JavaScript Document
(function($){
  $.fn.quotator = function(options){
    var container = this;
    var defaults = 
    {
      speed : 5000,
      json : "http://jp.akachanwear.com/feeds/bestsellers.php"
    }
    
    var options = $.extend(defaults, options);
    
    var quotes_json = options.json;
    var quotes;
    
    $.getJSON(quotes_json, function(data){
    var quotesobject = eval(data.quotes);
    var index = 0;
    
    
    setInterval(changeQuote, options.speed);
    
    container.html("<p class='highlight'>&nbsp;♪ ランキング " + quotesobject[index].ranking  + "</p><p class='highlight'><a href='" + quotesobject[index].link  + "'>" + quotesobject[index].title + "</a></p><br /><a href='" + quotesobject[index].link  + "'><img width='145' height='145' src='" + quotesobject[index].image  + "' /></a><p class='highlight'>" + quotesobject[index].price + "</p>");
    
    
    function changeQuote(){
      container.fadeOut(function(){
        container.html("<p class='highlight'>&nbsp;♪ ランキング " + quotesobject[index].ranking  + "</p><p class='highlight'><a href='" + quotesobject[index].link  + "'>" + quotesobject[index].title + "</a></p><br /><a href='" + quotesobject[index].link  + "'><img width='145' height='145' src='" + quotesobject[index].image  + "' /></a><p class='highlight'>" + quotesobject[index].price + "</p>").fadeIn();
      });
      
      if(index == quotesobject.length - 1){
        index = 0;
      } else{
        index++;
      }
    }
      
  });
  return container;
}
})(jQuery);
