$(function() {
  if (typeof Loco2 == 'undefined') {
    Loco2 = {};
  }

  // Random header image
  var headers = 5;
  $('#header').css('background-image', 'url(/images/headers/' + (1 + Math.floor(Math.random() * headers)) + '.jpg)');

  // Scrollable images on the homepage
  $('.featured-box .controls').tabs(".featured-box .items .item", {
      effect: 'fade',
      fadeOutSpeed: "slow",
      rotate: true
  }).slideshow({autoplay: true});

  // Labels inside input
  Loco2.LabelInside = $.klass({
    initialize: function() {
      this.label = this.element.siblings('label');
      this.label.hide();
      this.original_value = this.label.text();
      this.element.parents('form').submit($.bind(this.clear, this));
      this.restore();
    },

    clear: function() {
      if (this.element.val() == this.original_value) {
        this.element.val('');
      }
    },

    restore: function() {
      if (this.element.val() == '') {
        this.element.val(this.original_value);
      }
    },

    onfocus: function() { this.clear() },
    onblur: function() { this.restore() }
  });
  $('.label_inside').attach(Loco2.LabelInside);

  // Dropdown Navigation
  Loco2.DropDownNavigation = $.klass({
    initialize: function() {
      this.dropdown = this.element.siblings('select');
    },

    onclick: function() {
      window.location.href = '/' + this.dropdown.val();
    }
  });
  $('.drop_down_navigation').attach(Loco2.DropDownNavigation);
})
