// JQUERY CUSTOM COMMANDS
$(function (){

	// EXTERNAL LINKS
	$('#content a[href^="http://"]').attr({ target: "_blank", title: "Deze link opent in een nieuw venster"	}).addClass('external');
	
	// BUTTON
	$('.button').hover(function() {
		$(this).addClass('button-hover');
	}, function() {
		$(this).removeClass('button-hover');
	});
	
	// Autotab (1/2)
	jQuery('input.autotab').autotab();
	
	
	// viewportSize (1/2)
	$(window).resize(function () {
		viewportSize();
	});
	viewportSize();

	  
});

// viewportSize (2/2)
function viewportSize() {
	var viewportWidth = $(window).width();
	if (viewportWidth < 1050) {
		$('body').css("background-image", "url(images/interface/menu_back_thick.gif)");
	} else {
		$('body').css("background-image", "url(images/interface/menu_back.gif)");
	}
};

// Autotab (2/2)
jQuery.fn.autotab = function (){
	jQuery(this).keyup(function(e){
		switch(e.keyCode){
			// ignore the following keys
			case 9: // tab
				return false;
			case 16: // shift
				return false;
			case 20: // capslock
				return false;
			default: // any other keyup actions will trigger 
				var maxlength = jQuery(this).attr('maxlength'); // get maxlength value
				var inputlength = jQuery(this).val().length; // get the length of the text
				if ( inputlength >= maxlength ){ // if the text is equal of more than the max length
					jQuery(this).next('input[type="text"]').focus(); // set focus to the next text field
				}
		}
	});
}
