jQuery.fn.initBody = function() {	
	// ADD CLASS TO BODY
	$('body').removeClass("no-js");
	$('body').addClass("js");
	$('body').addClass(jQuery.uaMatch(navigator.userAgent).browser);
}

jQuery.fn.evenOddChild = function() {
	// ADD CLASS TO EVEN AND ODD CHILD
	$('tr:nth-child(odd), td:nth-child(odd), th:nth-child(odd), li:nth-child(odd)').addClass('odd');
	$('tr:nth-child(even), td:nth-child(even), th:nth-child(even), li:nth-child(even)').addClass('even');
}

jQuery.fn.firstLastChild = function() {
	// ADD CLASS TO FIRST AND LAST CHILD
	$('li:first-child,th:first-child,td:first-child').addClass('first');
	$('li:last-child,th:last-child,td:last-child').addClass('last');
}

jQuery.fn.formInit = function() {
	// FORM
	$('input').each(function(){
		$(this).addClass($(this).attr('type'));
	});
	
	$('textarea').addClass('textarea');
	
	$("form :input").focus(function() {
	  $("label[for='" + this.id + "']").addClass("labelfocus");
	}).blur(function() {
	  $("label").removeClass("labelfocus");
	});
}
	
jQuery.fn.brokenImage = function() {
	// MISSING IMAGE
	$("img").error(function(){
        $(this).hide();
	});
}

jQuery.fn.konamiCode = function() {
	
	// EASTER EGG - KONAMI CODE
	var kkeys = [], konami = "38,38,40,40,37,39,37,39,66,65";

	$(document).keydown(function(e) {
	
	  kkeys.push( e.keyCode );
	
	  if ( kkeys.toString().indexOf( konami ) >= 0 ) {
	
		$(document).unbind('keydown',arguments.callee);
	
		// do something awesome
		$("body").addClass("konami");
	
	  }
	});
}

jQuery.fn.nudgeLink = function() {	
	// NUDGE LINK
	$("#navigation a").hover(function() {
       $(this).stop().animate({marginLeft : "10px"},200);
	},function() {
		   $(this).stop().animate({marginLeft : "0px"},200);
	});
};

jQuery.fn.backToTop = function(cimke) {
	
	$('body').append('<div id="back-top"><a href="#" title="'+cimke+'">'+cimke+'</a></div>');
	// hide #back-top first
	$("#back-top").hide();
	
	// fade in #back-top
	$(function () {
		$(window).scroll(function () {
			if ($(this).scrollTop() > 100) {
				$('#back-top').fadeIn();
			} else {
				$('#back-top').fadeOut();
			}
		});

		// scroll body to 0px on click
		$('#back-top a').click(function () {
			$('body,html').animate({
				scrollTop: 0
			}, 800);
			return false;
		});
	});
};
