(function($){
  
  var Expand = function(element, options) {
    var el = $(element);
    var obj = this;
    var settings = $.extend({}, options || {});
    
    var initialize = function() {
      if ($.cookie('spot') == 'true') {
        el.css('height', 0);
        $(window).load(onLoad);
      }
      $(window).unload(onUnload);
    }
    
    var onLoad = function() {
      setTimeout(function() {
        $('body').addClass('stretch');
        el.animate({ height: 382 }, 'normal', function() {
          $('body').removeClass('stretch');
        });
      }, 400);
    }
    
    var onUnload = function() {
      var date = new Date();
      date.setTime(date.getTime() + (60 * 1000));
      $.cookie('spot', false, { path: '/', expires: date });
    }
    
    initialize();
  }
    
  var Contract = function(element, options) {
    var el = $(element);
    var obj = this;
    var settings = $.extend({}, options || {});
    
    var initialize = function() {
      if ($.cookie('spot') == 'false' && document.location.hash == '') {
        el.css('height', 382);
        $(window).load(onLoad);
      }
      $(window).unload(onUnload);
    }
    
    var onLoad = function() {
      setTimeout(function() {
        $('body').addClass('stretch');
        el.animate({ height: 0 }, 'normal', function() {
          $('body').removeClass('stretch');
        });
      }, 400);
    }
    
    var onUnload = function() {
      var date = new Date();
      date.setTime(date.getTime() + (60 * 1000));
      $.cookie('spot', true, { path: '/', expires: date });
    }
    
    initialize();
  }
  
  $.fn.expand = function(options) {
    return this.each(function() {
      var element = $(this);
      
      // Return early if this element already has a plugin instance
      if (element.data('expand')) return;
      
      // pass options to plugin constructor
      var expand = new Expand(this, options);
      
      // Store plugin object in this element's data
      element.data('expand', expand);
    })
  }
  
  $.fn.contract = function(options) {
    return this.each(function() {
      var element = $(this);
      
      // Return early if this element already has a plugin instance
      if (element.data('contract')) return;
      
      // pass options to plugin constructor
      var contract = new Contract(this, options);
      
      // Store plugin object in this element's data
      element.data('contract', contract);
    })
  }
})(jQuery);
