/**
 * Extender jQuery med funk for å animere sitater i header
 */
if(typeof jQuery != "undefined"){
  ;(function($){
  
    jQuery.fn.extend({
      animateQuotes: function(options,callback){
        options = $.extend( {},
                            $.quotes.defaults,
                            options );
        var result = $(this);
        var quotes = new Array();
        result.find('li').each(function(){
          quotes.push($(this).html());
        });
        quotes.push($(options.target+' span.text').html());
        return this.each(function(){
          new $.quotes(this,quotes,options,callback);
        });
      }
    });

    $.quotes = function(input,quotes,options,callback){
      var timeout;
      var animating = false;

      if( quotes.length>1 ){
        timeout = setTimeout(changeQuote, options.delay);
      }

      function changeQuote(){
        var newQuote = quotes.shift();
        quotes.push(newQuote);
        $(options.target).after('<p class="quote newquote"><span class="start">&ldquo;</span><span class="text">'+newQuote+'</span><span class="end">&bdquo;</span></p>');
        $(options.target).fadeOut(2000,function(){
          $(this).remove();
        });
        $(options.target).siblings('p.newquote').fadeIn(2000,function(){
          $(this).removeClass('newquote');
        });
        timeout = setTimeout(changeQuote, options.speed);
      }
    };
    
    $.quotes.defaults = {
      target: "",
      speed: "15000",
      delay: "10000"
    };
    
  })(jQuery);
}
