
// styleswitch function 

$(document).ready(function()
{
  $('.styleswitch').click(function()
  {
      switchStylestyle(this.getAttribute("rel"));
      return false;
  });

  var c = readCookie('style');
  if(c)
  {
    switchStylestyle(c);
  }

  // Geef links met rel="external" een target="_blank" attribuut.
  $(document.links).filter('[href][rel=external]').attr("target", "_blank");

  $(".newsrow").each( function(i)
  {
    var highestnewsblock = 0;
    var curnewsrow = $(this);
    var curnewsrow2 = $(this);
    curnewsrow.find(".newsblock").each( function(i)
    {
      if( this.offsetHeight > highestnewsblock )
      {
        highestnewsblock = this.offsetHeight;
      }
    });

    if( jQuery.browser.msie && jQuery.browser.version < 7 )
    {
      curnewsrow2.find(".newsblock").css( {'height': highestnewsblock + "px"} );
    }
    else
    {
      // Use min height so text zooming won't break.
      curnewsrow2.find(".newsblock").css( {'min-height': highestnewsblock + "px"} );
    }
  });
});

function switchStylestyle(styleName)
{
  $('link[rel*=style][title]').each(function(i) 
  {
      this.disabled = true;
      if (this.getAttribute('title') == styleName) this.disabled = false;
  });
  createCookie('style', styleName, 365);
}


// cookie functions http://www.quirksmode.org/js/cookies.html

function createCookie(name,value,days)
{
  var expires;
  if(days)
  {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    expires = "; expires="+date.toGMTString();
  }
  else
  {
    expires = "";
  }

  document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name)
{
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++)
  {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

function eraseCookie(name)
{
    createCookie(name,"",-1);
}       
