(function ($) {
$.fn.vAlign = function($align) 
{
	return this.each(function(i)
    {
    	var ah = $(this).height();
    	var ph = $(this).parent().height();
        
        switch ($align)
        {
            case 'top':
                var mh = 0;
            break;
            case 'middle':
                var mh = Math.ceil((ph-ah) / 2);
            break;
            case 'bottom':
                var mh = Math.ceil(ph-ah);
            break;
        }
    	$(this).css('margin-top', mh);
	});
};
})(jQuery);

function mycarousel_initCallback(carousel) {
    $('.jcarousel-control a').bind('click', function() {
        $('.jcarousel-control a').removeClass('active');
        $(this).addClass('active');
        var temp = $(this).attr('id').split('_');
        
        carousel.scroll($.jcarousel.intval(temp[1]));
        return false;
    });
};

function mycarousel_move(carousel, temp1, temp2, temp3)
{
    $('.jcarousel-control a').removeClass('active');
    $('#counter_'+temp2).addClass('active');
}

$(window).load(function() 
{
    $('#referenties li a').vAlign('middle');
    $('#referenties li img').vAlign('middle'); 
    
});

$(document).ready(function()
{
	$("a[rel='lightbox']").colorbox();
    
    $('.innerfade').innerfade({
		speed: 750,
		timeout: 5000,
		type: 'random'
	});
    
    /*
	$("#subsubmenu > li > span.hasSubmenu").click(function() {
        if($(this).hasClass("expanded")) {
            $(this).parent().find('.submenuLeft').slideUp("medium");
        } else {
            $(this).parent().find('.submenuLeft').slideToggle("medium");
        };
        $(this).toggleClass("expanded").toggleClass("collapsed");
        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");
		}
    });
    
    $("#homeCarousel").jcarousel({
        scroll: 1,
        auto: 5,
        wrap: 'last',
        initCallback: mycarousel_initCallback,
        itemVisibleInCallback: {
            onAfterAnimation: mycarousel_move
        },
        // This tells jCarousel NOT to autobuild prev/next buttons
        buttonNextHTML: null,
        buttonPrevHTML: null
    });
    
    $(".clearInput").focus(function(srcc)
    {
        if ($(this).val() == this.defaultValue)
        {
            $(this).val("");
            $(this).css('color', '#4b4b4b');
        }
    });
    
    $(".clearInput").blur(function()
    {
        if ($(this).val() == "")
        {
            $(this).val(this.defaultValue);
        }
    });
    
    $(".clearInput").blur();
});

function reloadCaptcha()
{
	document.getElementById('captcha').src = document.getElementById('captcha').src+ '?' +new Date();
}
