var IE        = window.attachEvent? true : false;

//get basepath
var site_base = "";
if(a=document.getElementsByTagName("link")[0])
{
  site_base = a.href.substr(0,a.href.indexOf('/resources'));
}

function popup(url,w,h,scroll)
{
  var l = (screen.width-w)/2;
  var t = (screen.height-h)/2;

  window.open(url,'_blank','resizable=yes,location=no,menubar=no,scrollbars='+scroll+',status=no,toolbar=no,fullscreen=no,dependent=no,width='+w+',height='+h+',left='+l+',top='+t);
}

window.addEvent('domready', function()
{
  if ($('searchq'))
  {
    new FieldText($('searchq'),'Uw zoekopdracht');
  }
  if($('ververs'))
  {
    $('ververs').set('html','ververs afbeelding');
    $('ververs').addEvent('click', reloadValidationImage);
    $('ververs').className = 'ververslink';
  }
  
  $$('a.newwindow').each(function(el) {
    el.addEvent('click', function(event){
      window.open(this.href,"_blank");
      return false;
    });
  })
  
  if($('playsound'))
  {
    $('playsound').addEvent('click', function(){captchaMp3();return false;}); 
  }
  
  if(IE && $('breadcrumb'))
  {
    var el = $$('#breadcrumb li.first');
    el.addEvent('mouseover', function(event){
      this.addClass("iehover");
    });
    el.addEvent('mouseout', function(event){
      this.removeClass("iehover");
    });
  }
  if(IE && $('navigation'))
  {
    $$('#navigation>ul>li').each(function(el)
    {
      el.addEvent('mouseover', function(event){
        this.addClass("iehover");
      });
      el.addEvent('mouseout', function(event){
        this.removeClass("iehover");
      });
    });
  }
 
});

function captchaMp3()
{
  var d = new Date();
  var msie  = (navigator.userAgent.toLowerCase().indexOf("msie") > -1) ? true : false;
  if(document.all && msie)
  {
    if(Number(parseFloat(navigator.appVersion.split('MSIE ')[1])) < 7)
    {
      embed = document.createElement("bgsound");
      embed.setAttribute("src", $('playsound') + "&cfsnd=" + d.getTime());
      document.getElementsByTagName("body")[0].appendChild(embed);
      return;
    }
  }
  if(document.getElementById)
  {
    var mp3player = '<embed src="' + $('playsound') + "&cfsnd=" + d.getTime() + '" hidden="true" type="audio/x-mpeg" autostart="true" />';
    $('soundcontainer').set('html',mp3player);
    return;
  }
  return;
}


var FieldText = new Class({
  initialize: function(element, default_text)
  {
    this.element      = element;
    this.default_text = default_text;

    this.unsel(); //set the defaulttext

    if(this.element.form)
    {
      this.element.form.onsubmit = function(){this.sel()}.bind(this);
    }
    this.element.onclick = function(){this.sel()}.bind(this);
    this.element.onblur  = function(){this.unsel()}.bind(this);
  },
  sel : function()
  {
    if(this.element.value==this.default_text)
    {
      this.element.value = '';
    }
  },
  unsel : function()
  {
    if(this.element.value=='')
    {
      this.element.value = this.default_text;
    }
  }
});

function reloadValidationImage()
{
  if($('validationimage'))
  {
    var now = new Date();
    newSrc = $('validationimage').src
    newSrc = (newSrc.indexOf("&")>0)? newSrc.substr(0,newSrc.indexOf("&")) : newSrc;
    newSrc+= "&"+ now.getTime();
    $('validationimage').src = newSrc;
  }
}
