$(function() {          

	$('img').lazyload({ 
		placeholder: "../gfx/placeholder.gif",
    effect : "fadeIn"		
		});
 
 	$("body").data("headerOriginalTop", parseInt($("#header").css("top")));
	$("body").data("contentOriginalHeight", parseInt($("#content").height()));
	$("body").data("contentOriginalMarginTop", parseInt($("#content").css("marginTop")));
	
	function adjustContent(animated) {
		 
		var windowHeight = $(window).height();
		var contentMax = $("body").data("contentOriginalHeight") + $("body").data("contentOriginalMarginTop");
		var overflow = windowHeight - contentMax;
			
		$("#header").css({top:overflow > 0 ? overflow/2 : $("body").data("headerOriginalTop")});
		$("#content").css({marginTop:overflow > 0 ? overflow/2 + $("body").data("contentOriginalMarginTop") : $("body").data("contentOriginalMarginTop")});
		
		}
		
	adjustContent(false);
	
	$(window).resize(function() {
  	adjustContent(false);
		});
	
	$("table#content tr td").not(":first").click(function() {
		var offset = - ($(window).width() / 2) + ($(this).width() / 2);
		var xPosGoTo = $(this).position().left + offset;	
		var animationDuration = 200;
		$.scrollTo(xPosGoTo > 0 ? xPosGoTo : 0, animationDuration, {axis:'x'});
		$(this).siblings('.highlighted').removeClass('highlighted');
		$(this).addClass('highlighted');	
		return true;	
		});
	
    // MAIL HIDER    
  $(".epost").each(function(i){ 
     var epostadr = $(this).text().replace(/\W?alfakr\wll\W?/i, '@').replace(/\W?alfamark\W?/i, '@').replace(/\W?dot\W?/i, '.').replace(/\W?punktum\W?/g, '.');
      if($(this).attr('title')) var text = $(this).attr('title');
      else var text = epostadr;
      if($(this).attr('value')) var extra = $(this).attr('value'); 
      else var extra = "";
  	$(this).replaceWith('<a class="epost" hr' + 'ef="mai' + 'lto:' + epostadr + extra+'">' + text + '</a>');       
    });

});
