$(document).ready(function()
{
    ddsmoothmenu.init({
    	mainmenuid: "smoothmenu1", //menu DIV id
    	orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v"
    	classname: 'ddsmoothmenu', //class added to menu's outer DIV
    	//customtheme: ["#1c5a80", "#18374a"],
    	contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
    })
    
	$("a[rel='lightbox']").colorbox();
    
    $('.innerfade').innerfade({
		speed: 750,
		timeout: 5000,
		type: 'random'
	});
    
    jQuery('ul#headerimg').innerfade({ 
		speed: 1000,
		timeout: 10000,
		type: 'sequence',
		containerheight: '210px'
	})
    
    $('.hasSubmenu').mouseover(function()
    {
        $(this).children('div.submenu').show();
    });
    
    $('.hasSubmenu').mouseout(function()
    {
        $(this).children('div.submenu').hide();
    });
    
    $(".validateForm").validate({
        errorPlacement: function(error, element) {
			error.prependTo( element.parent().next() );
		},
		// set this class to error-labels to indicate valid fields
		success: function(label) {
			// set &nbsp; as text for IE
			label.html("&nbsp;").addClass("checked");
		}
    });
    
     $('.title').click(function()
    {
        $slider = $(this).next('div');
        if ($slider.is(':visible'))
        {
            $(this).children('img').attr('src', 'images/arrowImage.png');
        }
        else
        {
            $(this).children('img').attr('src', 'images/arrowImageDown.png');
        }
        $slider.slideToggle();
        
    });
    
    jQuery.validator.messages.required = "";
    $("#formContact").validate({});
    
    function checkLength(o,n,min,max) {
		if ( o.val().length > max || o.val().length < min ) {
			o.addClass('ui-state-error');
			return false;
		} else {
			return true;
		}
	}
    
    var voornaam = $("#voornaam"),
        achternaam = $("#achternaam"),
        telefoonnummer = $("#telefoonnummer"),
		allFields = $([]).add(voornaam).add(achternaam).add(telefoonnummer);
    
    $("#bel-mij").dialog({
    	autoOpen: false,
    	modal: true,
        width: 400,
        height: 350,
        buttons: {
			'Reageer': function() {
				var bValid = true;
				allFields.removeClass('ui-state-error');
				voornaamValid = checkLength(voornaam,"voornaam",3,255);
                achternaamValid = checkLength(achternaam,"achternaam",3,255);
				telefoonnummerValid = checkLength(telefoonnummer,"telefoonnummer",3,255);

				if (voornaamValid && achternaamValid && telefoonnummerValid) {
					$.post("belmij.php", $("#belMijForm").serialize(), function(data) {
                        $('#formReactResponse').html(data);
                    });
				}
			},
			Cancel: function() {
				$(this).dialog('close');
			}
		},
    	close: function() {
    		allFields.val('').removeClass('ui-state-error');
    	}
    
    });
    
    $('#belMij').click(function() {
        $('#bel-mij').dialog('open');
    });
});
