if (document.observe) document.observe("dom:loaded", function() {
  
});
function getAssortiment() {
  var assortiment =  arguments[0];
  var regio       = arguments[1] || 0;
  var type        = arguments[2] || 0;
  var formValue   = (assortiment == "alles") ? "" : assortiment;
  
  toggleAssortimentPointer(assortiment);
  
  setFormVars('ajaxVars','assortiment',formValue);
  setFormVars('ajaxVars','bestseller',0);
  
  // reset trefwoord zoeken
  setFormVars('ajaxVars','trefwoord',0);
  
  // Region search
  setFormVars('ajaxVars','regio',regio);
  
  // Type search
  setFormVars('ajaxVars','type',type);
  
  doNavigateTo(1);
}
function doNavigateTo(page) {
  // hide homeDiv
  (page == "home") ? page = 1 : $("home") ? $("home").hide() : "";
  var cID         = arguments[1] || 0;
  var action      = arguments[2] || false;
  
  // When deeplinken then action can't be init
  // init implies: show six chosen items on homepage
  //if(cID && action == 'init') action = false 
  
  // if not searching for bestsellers then get form values
  var params = "";
  if(action != 'bestsellers') params = $("ajaxVars").serialize();
  
  params += '&current_page='+page+'&cID=' + cID;
 
  if(action == 'init') params += '&init=1';
  console.log(params);
  var container = $("ajaxContent");
  var myAjax = new Ajax.Request(
    "ajax-content.lp", {
    method: 'post',
    parameters: params,
    onCreate: function(originalRequest) {
      //if($(container).visible()) $(container).hide();
      $(container).update('<img style="margin-left:250px;margin-top:100px;" src="/images/loading.gif" alt="">');
    },
    onComplete: function(originalRequest) {
      if(!$(container).visible()) $(container).show();
      $(container).update(originalRequest.responseText);
      initFlash();
    }
  });
}
function setFormVars(form,element,value) {  
  var selector = "input[name='"+element+"']";
  $(form).select(selector)[0].value = value; 
}
function toggleAssortimentPointer(element) {
  var defaultSRC = "../images/i_ops_vogel.gif";
  var activeSRC = "../images/i_ops_vogel_d.gif";
  $$(".assortimentPointers").each(function(el) {
    el.src = defaultSRC;
    if(el.id == element+"Assortiment") el.src = activeSRC;
  });
}

/*function __doNavigateToBestsellers(page) {
  // hide homeDiv
  if($("home")) $("home").hide();
  var cID = arguments[1] || 0;
  var params = '&current_page='+page+'&cID=' + cID;
  new Ajax.Updater("ajaxContent", "ajax-bestsellers-content.lp", {
    parameters: params,
    onComplete: function() {
      initFlash();
    }
  });
}*/