$(document).ready(function() {

  setLinks();

  $('div.ark_sub').hide();
  $('a.ark_main').click(function() {
    $(this).siblings('div').slideUp('fast');
    $(this).next().slideDown('fast');
    this.blur(); return(false);
  });

});

function setLinks () {
  if (LEHTI_PID) {
    var href = '';

    // Skip Javascript/links with lehti_pid-parameter
    var local = new RegExp('^/');
    var js = new RegExp('^javascript');
    var pid = new RegExp('lehti_pid');

    $("a").each( function () {
      href = $(this).attr("href");
      if (local.exec(href) && !js.exec(href) && !pid.exec(href)) {
        check = new RegExp('\\\?');
        if (!check.exec(href)) 
          href += "?lehti_pid="+ LEHTI_PID;
        else
          href += "&lehti_pid="+ LEHTI_PID;
        $(this).attr("href", href);
      }
    });
  }
}


