$(document).ready(function () {

  if ($.cookie('prefs_navclick') !== null && $.cookie('prefs_navclick') != '') {
    $(".form_navclick:eq(" + $.cookie('prefs_navclick') + ")").attr("checked","checked");
  }
  else {
    $(".form_navclick:eq(0)").attr("checked","checked");
  }

  if ($.cookie('prefs_accordion') !== null && $.cookie('prefs_accordion') != '') {
    $(".form_accordion:eq(" + $.cookie('prefs_accordion') + ")").attr("checked","checked");
  }
  else {
    $(".form_accordion:eq(0)").attr("checked","checked");
  }
  
  if ($.cookie('prefs_search') !== null && $.cookie('prefs_search') != '') {
    $(".form_search:eq(" + $.cookie('prefs_search') + ")").attr("checked","checked");
  }
  else {
    $(".form_search:eq(0)").attr("checked","checked");
  }

  $("#saveprefs").bind('click', function () {
      $.cookie('prefs_navclick', $(".form_navclick:checked").val(), {expires: 365});
      $.cookie('prefs_accordion', $(".form_accordion:checked").val(), {expires: 365});
      $.cookie('prefs_search', $(".form_search:checked").val(), {expires: 365});
      if($.cookie('prefs_navclick') !== null) {
        //alert('Your preferences have been saved.');
        window.location.hash = '';
        window.location.reload(true);
        //self.close();
      }
      else {
        alert('You must enable cookies in order to save your site preferences.');
      }
      return false;
  });
});