
// usage: log('inside coolFunc', this, arguments);
// paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
window.log = function(){
  log.history = log.history || [];   // store logs to an array for reference
  log.history.push(arguments);
  if(this.console) {
    arguments.callee = arguments.callee.caller;
    var newarr = [].slice.call(arguments);
    (typeof console.log === 'object' ? log.apply.call(console.log, console, newarr) : console.log.apply(console, newarr));
  }
};

// make it safe to use console.log always
(function(b){function c(){}for(var d="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,timeStamp,profile,profileEnd,time,timeEnd,trace,warn".split(","),a;a=d.pop();){b[a]=b[a]||c}})((function(){try
{console.log();return window.console;}catch(err){return window.console={};}})());


// place any jQuery/helper plugins in here, instead of separate, slower script files.

!function( $ ){

  "use strict"

  var Passevue = function ( content, options ) {
    this.settings = $.extend({}, $.fn.passevue.defaults, options)
    this.$element = $(content);
        //.on('click', $.proxy(this.next, this));
        
//      .delegate('.close', 'click.modal', $.proxy(this.hide, this))

    this.$element.find('img').css({opacity:'0'}).removeClass('active')
    this.$element.find('img:first').css({opacity:'1'}).addClass('active');

    if (this.$element.find('img').size() <= 1)  {
        this.settings.autoplay = false;
        return;
    }
    //this.$element.bind('click', $.proxy(this.next, this));
    $('#passvue-nav a').fadeTo(1, 0);

    $('#passvue-nav').on('mouseenter', $.proxy(this.onhover, this));
    $('#passvue-nav').on('mouseleave', $.proxy(this.onout, this));

    $('#passvue-nav').on('mouseleave', $.proxy(this.onout, this));
    $('#nav-left').on('click', $.proxy(this.previous, this));
    $('#nav-right').on('click', $.proxy(this.next, this));

    if (this.settings.autoplay)
        this.start();

    return this;
  }

  Passevue.prototype = {
      onhover:function() {
          $('#passvue-nav a').stop().fadeTo(500, .8);
      },
      onout:function() {
          $('#passvue-nav a').stop().fadeTo(500, 0);
      },
      next:function() {
          clearTimeout(this.timeout);
          this.animating = false;
          this.anim();

      },
        previous:function() {
            clearTimeout(this.timeout);
            this.animating = false;
            this.animprev();

        },
      start:function() {
          this.animating = true;
          var _self = this;
          this.timeout = setTimeout(function () {
              _self.anim();
          }, this.settings.sAnim)
      },
      
      anim:function() {
          
      	var current = (this.$element.find('img.active').size()>0 ?  this.$element.find('img.active') : this.$element.find('img:first'));
      	var next = ((current.next().length) ? ((current.next().hasClass('active')) ? this.$element.find('img:first') :current.next()) : this.$element.find('img:first'));	

      	next.css({opacity: 0.0}).addClass('active').animate({opacity: 1.0}, this.settings.sTransition);
      	current.animate({opacity: 0.0}, this.settings.sTransition).removeClass('active');

        if (this.animating) this.start();


      },
      animprev:function() {
          
      	var current = (this.$element.find('img.active').size()>0 ?  this.$element.find('img.active') : this.$element.find('img:first'));
      	var previous = ((current.prev().length) ? ((current.prev().hasClass('active')) ? this.$element.find('img:last') :current.prev()) : this.$element.find('img:last'));	

      	previous.css({opacity: 0.0}).addClass('active').animate({opacity: 1.0}, this.settings.sTransition);
      	current.animate({opacity: 0.0}, this.settings.sTransition).removeClass('active');

        if (this.animating) this.start();


      }

      
  }


 /* TABS/PILLS PLUGIN DEFINITION
  * ============================ */

  $.fn.passevue = function ( options ) {
      return this.each(function () {
          $(this).data('passevue', new Passevue( this, options ));
      });
  };
  $.fn.passevue.defaults = {
      sAnim: 8000,
      sTransition: 1500,
      autoplay:true
  }

}( window.jQuery || window.ender );

