$(document).ready(function() {

	speed=350;
	ie6=($.browser.msie && $.browser.version.substr(0,1)<7);	
	
	// show content if history is in site
	$('#content.hidden').hide().fadeIn(speed);
	
	// blocks
	blockStart='<div class="top"><div class="left"></div><div class="bottom"><div class="inner">';
	blockEnd='</div></div></div>';	
	$('.blok').add('#menu li').each(function(){
		inner=$(this).html();
		$(this).html(blockStart+inner+blockEnd).addClass('jBlock');
	});
	add=39;
	index=1000;
	p=0;
	$('#menu li').each(function(){
		$(this).css({'top':10+p*add,'z-index':index-p});
		p++;
	});

	// Animation for blocks and content
	
	if (!ie6) {
	
		// replace menu links with links and a span and add a hover animation
		$('#menu li a').wrapInner('<span></span');
		$('#menu li:not(.current)').hover(function(){
			$(this).animate({marginTop:'8px',marginRight:'0px',marginBottom:'0px',marginLeft:'8px'},speed/2);
		},function(){
			$(this).animate({marginTop:'0px',marginRight:'8px',marginBottom:'8px',marginLeft:'0px'},speed/3);
		});
	
		// remove normal (internal) links and bind a animation funcion
		$('a').each(function(){
			thisHref=$(this).attr('href');
			slash=thisHref.lastIndexOf('/');
			if (slash>=0 && slash<thisHref.length-1) {
				thisHref=thisHref.substr(slash+1);
			}
			if (thisHref.indexOf('.')==-1) {
				$(this).attr('url',thisHref).removeAttr('href').click(function(){
					// animate blocks and load new page
					url=$(this).attr('url');
					li=$('#menu li.'+url);
					if (li.length>0 && !$(li).hasClass('current')) {
						w=$('#menu li.current a span').width()+24;
						$('#content').fadeOut(speed);
						$('#menu li.current .inner').css({'borderRight':'solid 1px'});
						$('#menu li.current').children('div').animate({'width':w },speed,function(){
							$('#menu li.current').removeClass('current');
						});
						$(li).children('div').animate({'width':'176'},speed,function(){
							location.href=url;
						});
					}
				});
			}
		});
	}
	
});