
$(document).ready(function() {
	
	//Ochrana e/mailu
	$('a.em').each(function(){
		e = this.rel.replace('/','@');
		this.href = 'mailto:' + e;
		
		e2 = $(this).text().replace('/','@');
		$(this).text(e2);
	});
	
	//vysouvací menu po přejetí
	// var test = 0;
	// 
	// $('ul#menu')
	// 	.hover(function(){
	// 		$(this).animate({'padding-top':'15px'})
	// 		test = 1;
	// 	},function(){
	// 		test = 0;
	// 		// setTimeout(function(){
	// 			if(test == 0){
	// 				$(this).delay(700).animate({'padding-top':0})
	// 			}
	// 			
	// 		// }, 700)
	// })
	
	// rozbalí článek a nascroluje na jeho pozici, je-li nastaven hash
	if(document.location.hash){
		var elem = $(document.location.hash)
		elem.find('.meta p').css('margin-right',- $(this).width() - 200 + 'px')
		elem.find('.toggle-content').slideDown('slow',function(){
			$('body').scrollTo(elem, {
				duration: 600,
				easing: 'myEasing',
				axis: 'y',
				onAfter: function(){
					var meta = $(this).find('.meta p');
					meta.animate({ marginRight: 0 });
				}
				
			});
			
		});
		
	}
	
	//po najetí odkryje náhled vedle článku
	$('.main-thumb').hover(function(){
		var width  = $(this).attr('width');
		var height = $(this).attr('height');
		$(this).stop().animate({
			'width' : width,
			'height': height
		})
		.css('z-index','10')
	},function(){
		// var elem = $(this).find('.project-date');
		$(this).stop().animate({
			'width' : 45,//elem.width() + 10, 
			'height': 45//elem.height() + 10
		}, function(){
			$(this).css('z-index','0')
		})
	});
	
	// rozbalí článek, nascroluje an jeho pozici a vysune popisky – a naopak
	$('.project h2 a.toggle').click(function(){
		var elem = $(this).parents('.project');
		var content = elem.find('.toggle-content');
		
		content.find('.meta p').css('margin-right',- $(this).width() - 200 + 'px')
		
		content.slideToggle("slow",function(){
			$('body').scrollTo(elem, {
				duration: 600,
				easing: 'myEasing',
				axis: 'y',
				onAfter: function(){
					var meta = $(this).find('.meta p');
					meta.animate({ marginRight: 0 });
					document.location.hash = elem.attr('id');
				}

			});
				
		});
		return false;
	});
	
});

