( function($) {
$(document).ready(function() {
	var validator = $("#parkeringForm").validate({
		invalidHandler: function() {
			error = validator.numberOfInvalids();
			
			if ( jQuery('#personaliaTab .error').size() > 0) {
				showTab("personaliaTab", "personalia");
				jQuery('input.error:first').focus();
			} else if (jQuery('#reiseDetaljerTab .error').size() > 0) {
				showTab("reiseDetaljerTab", "reiseDetaljer");
				jQuery('input.error:first').focus();
			} else if (jQuery('#tjensterTab .error').size() > 0) {
				showTab("tjensterTab", "tjenster");
				jQuery('input.error:first').focus();
			} else {
				showTab("personaliaTab", "personalia");
				jQuery('input.error:first').focus();
			}
			
			return false;
		}
	});
	
    $('.level1Faq:first').css("border-top", "solid 1px #dadada");
    $('.level1Faq:first').css("border-left", "solid 1px #dadada");
    $('.level1Faq:first').css("border-right", "solid 1px #dadada");
    $('.level1Faq:first').css("border-bottom", "solid 1px #eeeeee");
    $('.level1Holder:first').show();

	$('.level1Faq').click(function() {
		var clickedID = $(this).attr("id");

		$('#theQuestions' + clickedID).show();
		$('#theQuestions' + clickedID).siblings().hide();

		$(this).siblings().css("border", "none");
		$(this).siblings().removeClass("currentTab");
		$(this).css("border-top", "solid 1px #dadada");
		$(this).css("border-left", "solid 1px #dadada");
		$(this).css("border-right", "solid 1px #dadada");
		$(this).css("border-bottom", "solid 1px #eeeeee");

		$(this).addClass("currentTab");
		
		var layout = jQuery("#layout");
	    var layoutHeightCheck = jQuery("#layoutHeightCheck");

	    var textHeight = layoutHeightCheck[0].offsetTop - layout[0].offsetTop;

	    if(textHeight > 222) {
	        jQuery('.scroll').show();
	    }
		
	});

	$('.question h2').click(function() {
		if ($(this).hasClass('up')) {
			$(this).removeClass('up').addClass('down'); 
			$(this).next().slideDown('slow');
			$(this).removeClass('downArrow').addClass('upArrow'); 
		}
		else {
			$(this).removeClass('down').addClass('up'); 
			$(this).next().slideUp('slow');
			$(this).removeClass('upArrow').addClass('downArrow'); 
		}
	});
	
	jQuery('.ui-datepicker-unselectable').live('click', function(){
    	    $('#block-message').css('font-weight', 'bold');
                          $('#block-message').css('color', 'red');
                          $('#block-message').show();
	});
        
                        jQuery('a.ui-state-default').live('click', function(){
    	    $('#block-message').hide();
	});
	
	$(".tipTip").tipTip();

});
} ) ( jQuery );

