$(document).ready(function()
{
	$("a[rel='lightbox']").colorbox({
	   maxHeight: '90%'
	});
    
    $('.innerfade').innerfade({
		speed: 750,
		timeout: 5000,
		type: 'random'
	});
    
    $('#submitVipForm').live('click', function() {
         $(".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");
    		},
            submitHandler: function(form) {
                $.post($('.validateForm').attr('action'), {
                            submitVipForm:  true, 
                            'naam':         $('input[name=name]').val(),
                            'email':        $('input[name=email]').val(),
                            'telefoon':     $('input[name=telefoon]').val(),
                            'aantal':       $('input[name=aantal]').val(),
                            'wensen':       $('textarea[name=wensen]').val(),
                            'captcha':      $('input[name=captcha]').val()
                    }, function(response) {
                         if (response == '2') {
                            $('.notice').hide();
                            $('.error').show();
                            $('.error').html('De verificatie-code is niet goed overgenomen.<br /><br />');
                         } else if (response == '1') {
                            $('.notice').show();
                            $('.error').hide();
                            $('.notice').html('Bedankt voor uw bericht, we nemen contact met u op.<br /><br />');
                            $('.validateForm').hide();
                         }
                    }
                );
                return false;
            }
        });
    });
    
    $(".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");
		}
    });
    
    $.address.init(function() {
        //$.address.state('/bermuda');    
    }).change(function(event) {  
        loadContent(event.value);
    });

    //$('a').live('click', fuction(){
    $('.internal').live('click', function() {
        $.address.value($(this).attr('href'));
        return false;
    }); 
    
    /*
    $('.internal').click(function()
    {
        loadContent(this.href);
        return false;
    });
    */
    $.stratus({
        color: 'e20043',
        auto_play: true,
        links: [
            { url: 'http://soundcloud.com/bermudacuracao/' }
        ],
        randomize: true
    });
});

function loadContent(url)
{ 
    if (url != '/') {
        $.getJSON(root + url, { internal: '1' },  function(data) {
            $.each(data, function(key, val) {
                if (key == 'title')
                {
                    document.title = val;
                }
                else
                {
                    $('#' + key).html(val);
                }
            });
            $("a[rel='lightbox']").colorbox({
                maxHeight: '90%'
            });
            $('.innerfade').innerfade({
        		speed: 750,
        		timeout: 5000,
        		type: 'random'
        	});
            /*            
            $('.internal').click(function()
            {
                loadContent(this.href);
                return false;
            });
            */            
        });
        
    }
}
