/* Register page setup functions */
$(document).ready(page_setup);

/* Register handlers to the page */
function page_setup() {
    /* Override the hover to degrade with CSS */
    $("#navigation_links li:hover ul").css("display","none");
    /* Make the Store Finder Click */
    $("#navigation_links ul li div.parent_link a").click(slideToggleMenu);
    
    /* Make the Store Finder Click */
    $("#navigation_links ul.sub_menu").mouseleave(slideUpMenu);
    
    /* Submission Validation */
    $("#store_finder_form").submit(storefinderSubmit);
}

function slideUpMenu(e) {
    $(this).slideUp(300);
}

function slideDownMenu(e) {
    $(this).slideDown(300);
}

function slideToggleMenu(e) {
    is_open = $(this).parent().next().css('display') == 'block';
    
    $('ul.navigation_bar ul.sub_menu').hide();
    
    if(is_open)
        $(this).parent().next().slideUp("fast");
    else
        $(this).parent().next().slideDown("fast");
    
    return false;
}

function textBoxFocus(textbox,init_value) {
    if(textbox.value == init_value)
        textbox.value = '';
}

function textBoxBlur(textbox,init_value) {
    if(textbox.value == '')
        textbox.value = init_value;
}

/**
 * Actions to occur when submitting a form
 */
function storefinderSubmit()
{
  if($("#store_finder_city").attr("value") == "City" && $("#store_finder_postal_code").attr("value") == "Postal Code")
  {
    window.location = this.action;
    return false;
  }
}
