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;
    });
    
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};


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

$(document).ready(function()
{
    $("a[rel='colorbox']").colorbox({ 
        maxHeight: '90%',
        maxWidth: '90%'
    });
    
    $("a[rel='framebox']").colorbox(
    {
        iframe:true, 
        width:500, 
        height:380
    });
    
    $('.youtubeVideo').colorbox({iframe:true, width:800, height:600});
    
    $("#mycarousel").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
    });
    
    $('.innerfade').innerfade({
		speed: 750,
		timeout: 5000,
		type: 'random'
	});
    
    $(".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");
		}
    });
    
    $(".activityLink").click(function() {
        if($(this).hasClass("expanded")) {
            $(this).next('.activityContent').slideUp("medium");
        } else {
            $(this).next('.activityContent').slideToggle("medium");
        };
        $(this).toggleClass("expanded").toggleClass("collapsed");
	});
    
    $("#archive").click(function() {
        if($(this).hasClass('expanded')) {
            $('#archiveList').hide();
            $(this).removeClass('expanded');            
        } else {
            $('#archiveList').show();
            $(this).addClass('expanded');
        }
        return false;
	});
    
    $(".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();
    
    $('#loginButton a').click(function()
    {
        $('#inloggen').slideDown();
        $(this).addClass('expanded');
        return false;
    });
    
    $('#loginLinkOpen').click(function()
    {
        $('#inloggen').slideUp();
        $('#loginButton a').removeClass('expanded');
        return false;
    });
    
    $('#files').MultiFile({
        list: '#fileList',
        STRING: {
            remove: '<img src="images/delete.png" height="14" width="14" alt="delete" align="right"/>'
        }
    });
    
    $('.operariaTop').click(function()
    {
        $('.operariaTop').removeClass('expanded');
        $('.operariaContent').slideUp();
        $(this).addClass('expanded');
        $(this).next('.operariaContent').slideDown(); 
    });
    
});

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