function queryString(parameter) { 
  var loc = location.search.substring(1, location.search.length);
  var param_value = false;

  var params = loc.split("&");
  for (i=0; i<params.length;i++) {
      param_name = params[i].substring(0,params[i].indexOf('='));
      if (param_name == parameter) {
          param_value = params[i].substring(params[i].indexOf('=')+1)
      }
  }
  if (param_value) {
      return param_value;
  }
  else {
      return false; //Here determine return if no parameter is found
  }
}

(function($,undefined) {

// naytetaan valittu tiedote, piilotetaan loput
function nayta_tiedote(tiedote_id) {
	$('.tiedote').hide();
	$('#'+tiedote_id).show();
}

$(document).ready(function() {
	tiedotteet = $('.tiedote');
	if(tiedotteet.length > 0) {
		nayta_tiedote(tiedotteet[0].id);
		linkkilista = '<h3>Ajankohtaiset tiedotteet</h3><ul>';
		for(i=0; i<tiedotteet.length; i++) {
			id = tiedotteet[i].id;
			otsikko = $('h3:first', tiedotteet[i])[0].textContent;
			julkaisuaika = $('#aika', tiedotteet[i])[0].textContent;
			linkkilista += '<li><a href="#' + id + '" id="' + id + '" class="tiedotelinkki">' + otsikko + '</a> (' + julkaisuaika + ')</li>';
		}
		linkkilista += '</ul>';
		tiedotteet.last().after(linkkilista);
		
		$('.tiedotelinkki').click(function() {
			nayta_tiedote(this.id);
		});

	}
	
	if(location.hash)	
		nayta_tiedote(location.hash.replace(/#/, ''));
	
});

})(jQuery);

