// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults


function defaultValue(obj, val) {
  $(obj).bind("focus", function(e) {
    if($(this).val() == val) {
      $(this).val('');
      $(this).removeClass('inactive');
    } 
  });
  $(obj).bind("blur", function(e) {
    if($(this).val() == '') {
      $(this).val(val);
      $(this).addClass('inactive');
    } else if($(this).hasClass('inactive')) {
      $(this).removeClass('inactive');
    }
  });
  $(obj).trigger('blur');
}

function account_form_toggle(f) {
  if(f == 'guest') {
    if($('#guest-welcome').html().length != 0) {
      $('#guest-welcome').show();
      $('#login-form').hide();
    } else {
      $('#login-form').attr('action', '/guests/login');
      $('#login-form').attr('method', 'get');
    }
  } else {
    $('#login-form').attr('action', '');
    $('#login-form').attr('method', '');
    $('#guest-welcome').hide();
    $('#login-form').show();
  }
}

function login_box() {
  $('#login ul li a.guest').each(function() {
    var c = $(this).html().toLowerCase();
    $(this).click(function() {
      $('#login').attr('class', c);
      account_form_toggle($('#login').attr('class'));
    });
  });
  defaultValue($('#account_number'), 'Enter Your Account Number Here');
  // click guest by default
  $('#login ul li a.guest').click();
}

function search_box() {
	$('#search a.search').click(function() { $('#search form#site-search').show(); $('#search form#site-search input#q').focus(); return false; });
	$('#search a.close').click(function() { $('#search form#site-search').hide(); return false; });
	defaultValue($('form#site-search input#q'), 'What can we help you find today?');
}

function menu_rollovers() {
  $('ul#navigation li.main-nav-li').hover(
    function() { 
      $(this).addClass('hover');
      cl = $(this).children('a').attr('class').replace('image-bg ', '');
      $('#navigation-container').attr('class', cl);
    },
    function() {
      $(this).removeClass('hover');
      $('#navigation-container').attr('class', '');      
    }
  );
}


function drop_downs() {
  $('.dropdown').each(function() {
    var d = this;
    var p = $(this).parent();
    $(p).hover(
      function () {
        $(d).show();
      },
      function () {
        $(d).hide();
      }
    );
  });
  // rollover effect
  $('.dropdown ul li').each(function() {
    $(this).hover(
      function () {
        $(this).addClass('over');
      }, 
      function () {
        $(this).removeClass('over');
      }
    );
  });
}


$(function() {
  login_box();
	search_box();
  menu_rollovers();
  drop_downs();
});