var $j = jQuery.noConflict();

function saveIndi(nodeid) {
  var map=getUrlVars();
   
  if (map['key']!=undefined && map['value']!=undefined) {
    $j.cookie("preference", map['key']+"&"+map['value'], { path: '/' });
  }

  var history=$j.cookie("history");
  if (history==null) history="";

  if(history.length>3000)
    var history=history.substring(1000)

  $j.cookie("history", history+nodeid+",", { expires: 730, path: '/' });
}

function showIndi() {

  var preference = $j.cookie("preference")
  var showdefault=true;

  if (preference) {
    var keyvalue = $j.cookie("preference").split("&");
    var show = ".pref-"+keyvalue[0]+"-"+keyvalue[1];

    if ($j(show).length) {
      showdefault=false;
      $j(show).show();
      return;
    }
  }

  $j(".bes").each(function(i) {
   var id=$j(this).attr('title');
   var history=","+$j.cookie("history");
   if (history.match(".*,"+id+",.*")) {
     showdefault=false;
     $j(".bes-"+id).show();
     return;
   }
  })



  if (showdefault) $j(".individualisering-default").show();


} 

function getUrlVars() {
  var map = {};
  var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
  map[key] = value;
  });
  return map;
}