/* (c)2006-2009 Jacopo Salvestrini - 1.1.20090503 */
$(function(){
	resize();
	$(window).bind('resize',resize);
	// span.nosp
	var $s=$('span.nosp');
	$s.each(function(){
		var $t=$(this);
		var t=$t.text().replace(' (at) ','@').replace(' (dot) ','.');
		$t.html('<a href="mailto:'+t+'">'+t+'<\/a>');
		$t.css('text-decoration','none');
	});
	// a.blank
	$s=$('a.blank');
	$s.each(function(){
		var $t=$(this);
		$t.attr({'target':'_blank','title':$t.attr('title')+' ['+$t.attr('href').replace(/^(http:\/\/[^\/]+\/).+$/,'$1')+']'});
	});
	// IE fix #body-nav
	if($.browser.msie&&$('#body-nav').css('left')&&$('#body-nav').css('left').replace(/[a-z]+/i,'')<0){
		var $b=$('#body');
		var boff=$b.offset();
		var $bn=$('#body-nav');
		var bnT=parseInt($bn.css('top').replace('px','')),bnL=parseInt($bn.css('left').replace('px',''));
		$bn.remove();
		$bn.css({'top':(boff.top+bnT)+'px','left':(boff.left+bnL)+'px',
			'z-index':'1000',
			'font-size':'1.0em'
			//'filter':'alpha(opacity='+Math.round($b.css('opacity')*100)+')'
		});
		$('body').append($bn);
	}
	
	function resize(){
		var RATIO=1.444623,$imgs,imgL,imgW;
		var h=$(window).height();
		var $f=$('#foot'),$bc=$('#body-content'),$doc=$('#document');
		var MIN=530,MAX=623;
		if(h<MIN)h=MIN;
		if(h>MAX)h=MAX;
		$doc.height(h);
		imgL=Math.round(($doc.width()-h*RATIO)/2);
		imgW=Math.round(h*RATIO);
		if(($imgs=$doc.children()).is('img:first-child')){
			$($imgs[0]).css({'left':imgL+'px','width':imgW+'px','height':h+'px'});
		}else{
			$doc.prepend('<img src="'+$doc.css('background-image').replace(new RegExp('.+(http:\/\/.+\\.jpg).+','i'),'$1')
				+'" class="noprint" style="z-index:1;position:absolute;top:0;left:'+imgL+'px;width:'+imgW+'px;height:'+h+'px;" \/>');
			$doc.css('background-image','url("")');
		}
		h-=$f.outerHeight();
		$f.css({'top':h+'px',bottom:'auto'});
		if($bc.css('top').replace('px','').replace('auto','0')<1){
			var OFFSET=12;
			var $b=$('#body');
			h=h-$b.outerHeight()-$b.offset().top-OFFSET;
			$b.css('height',($b.height()+h)+'px');
			if($bc.css('margin-top').replace('px','')<1)$bc.css('height',($bc.height()+h)+'px');
		}
	}
});

