$(function(){
	setInterval("checkAnchor()", 300);
	$('.seksjon').hide();
	$('body').height('100%');
	
	$('.eposterstatter').hide().each(function() {
       	var splits = $(this).html().split(' ');
       	var adresse = splits[0] + '@' + splits[2];
        $(this).after($('<a></a>').html(adresse).attr('href', 'mailto:' + adresse));
	});
	$('#shows li').each(function(){
		if (autoExpire($(this).attr('class'))) {
			$(this).addClass("ferdig");
		}
	});
});

function autoExpire(expireDate) {
  var nowDate = new Date();
  var day = nowDate.getUTCDate();
  var month = nowDate.getUTCMonth();
  var correctedMonth = month + 1;

  if (correctedMonth < 10) { 
    correctedMonth = "0" + correctedMonth;
  }
   
  if (day < 10) {  
    day = "0" + day;
  }

  var year = nowDate.getYear();  
  if (year < 1900) {
    year = year + 1900; 
  }

  var GMTdate = year + "" + correctedMonth + "" + day; 
  if (GMTdate <= expireDate) {
	  return false;
  } else return true;
}


var currentAnchor = "a";

function checkAnchor() {
    if(currentAnchor != document.location.hash){
		if (!(!document.location.hash && currentAnchor == "#home"))
		{
        	currentAnchor = document.location.hash;
			//if there is not anchor, the loads the default section 
			if(!currentAnchor) {
				currentAnchor = "#home";
				$cover = $('#coverbilde img');
				$cover.hide();
	
				if($cover.length != 0) {
					if($cover[0].complete) {
						$cover.fadeTo(150, 1);
					} else {
						$cover.load(function(){
							$cover.fadeTo(150, 1);
						});
					}
				}
	
			}
			$('.seksjon').hide();
			$(currentAnchor).show();
		}
    }
}
