﻿
$(document).ready(function () {
  var url = "", i = 1; // Declare Variables

  // Build current URL string
  do {
    url += "/" + location.pathname.split("/")[i]; i++;
  } while (typeof (location.pathname.split("/")[i]) != "undefined");

  // Format URL string to get rid of trailing "/"
  url = (url.substring(url.length - 1) == "/") ? url.substring(0, url.lastIndexOf("/")) : url;

  // Add active class to matching navigation link
  $('#storeHeader div.navigation #qm0 > a[href="' + url + '"]').addClass('active');

  var search = $('.search input[type="text"]');
  search.data('label', search.val());

  search.focusin(function () {
    // If the value matches its label, clear it
    if (search.val() == search.data('label')) { search.val(''); }
  }).focusout(function () {
    // If the value is empty, add in the label
    if (search.val() == '') { search.val(search.data('label')); }
  });

  $('.search a.search-button').click(function (e) {
    if (search.val() == search.data('label')) { e.preventDefault(); }
  });
});
