$(document).ready(function(){
	
	// HTML/CSS
	$(".menu li:last, .related-thumbs li:last, .thumb:nth-child(3n)").css("margin-right", "0");
	$(".post:last, .widget:last, .menu li li:last a").css("border-bottom", "none");
	$("li.bypostauthor:not(.depth-2)").append('<span class="shadow"></span>');
	
	// Slider
	$("#slider").easySlider({
		//auto	  : true,
		continuous:	true
	});

	// Scrolling
	$('a[href*=#]').click(function() {
		if ( location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname ) {
			var $target = $(this.hash);
			$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
			
			if ( $target.length ) {
				var targetOffset = $target.offset().top;
				$('html,body').animate({scrollTop: targetOffset}, 600);
				return false;
			}
		}
	});

	/* Fancybox */
	
	function formatTitle(title, href) {
    	return '<span id="fancybox-title-wrap"><span id="fancybox-title-main"><a href="' + href + '">G&aring; til ' + href + '</a></span></span>';
	
	}
	
	$("a[rel^='fancybox'], a.fancybox, a.portfolio-img-small").fancybox({
		'overlayOpacity'  : '0.5',														
		'overlayColor' 	  : '#000',
		'titlePosition'   : 'over'
	});
	
	$("a.inline").fancybox({			
		'transitionIn'		: 'none',
		'transitionOut'		: 'none'
	});
	
	$("a[rel^='portfolio']").fancybox({			
		'overlayOpacity'  : '0.5',														
		'overlayColor' 	  : '#000',
		'titlePosition'   : 'inside'
	});

	$("a.iframe").fancybox({
		'width'				: '80%',
		'height'			: '80%',
		'padding'			: 0,
		'centerOnScroll'	: true,
        'autoScale'     	: false,
		'titleFormat'		: formatTitle,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});
	
	
	$('#portfolio-wrapper').equalHeights();
	$(".tweet p").vAlign();

	// Sidebar
	
	$("#sidebar li a").hover(function() { 
									  
		$(this).stop().animate({
			paddingLeft: "10px"				   
		}, 300);
		
	}, function() {
		
		$(this).stop().animate({
			paddingLeft: "0"				   
		}, 300);
		
	});
	
	// Comment form validation
	$('#commentform').submit(function() {
									   
		$('#submiterror').remove();

		var errors = 0;
		
		$(this).find('textarea, input').each(function () {
													   
			if ( $(this).hasClass('required') && $(this).val() == '' ) {
				$(this).addClass('inputerror');
				errors++;
			}
			
		});
 
		if ( errors > 0 ) {
			$('#comment').after('<div id="submiterror">Skriv venligst b&aring;de navn, email og en kommentar :-)</div>');
			return false;
		}
		
		return true;
	});


	// A nice little thing
	var kkeys = [], kon = "38,38,40,40,37,39,37,39,66,65";
	$(document).keydown(function(e) {
	  kkeys.push(e.keyCode);
	  if(kkeys.toString().indexOf(kon) >= 0 ){
		$(document).unbind('keydown',arguments.callee);
			$('<img src="http://jayj.dk/wp-content/uploads/ninja.png" alt="Ninja" />').insertAfter('#wrapper').fadeIn(1000);
			$('img[alt=Ninja]').click(function() {
				$(this).fadeOut(1000);						   
			});
	  }
	});
	
  

});
