$(document).ready(function()
{
	$("a[rel='lightbox']").colorbox();

    $(".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");
		}
    });
    
    $('.innerfade').innerfade({
		speed: 750,
		timeout: 5000
	});
    
    $width = $('.menuBackground').next('a').width() + 20;
    $('.menuBackground').width($width);
    
    initPagination();
    
    $('.changeSubmit').change(function()
    {
        $(this).parent('form').submit();
    });
    
    $('.tab').click(function()
    {
        $('.tabContent').hide();
        $('.tab').removeClass('active');
        $(this).addClass('active');
        $($(this).attr('href')).show();
        
        if ($(this).attr('href') == '#plattegrond')
        {
            $("#map").css({'width':'580px', 'height':'345px'});
            onLoadmap(); 
        }
        
        return false;
    });
    
    pq = $('.homePagination');
    if (pq)
    {
        setInterval(function()
        {
            if (pq.data('current_page') == '6')
            {
                pq.trigger('setPage', [0]);
            }
            else
            {
                pq.trigger('nextPage');
            }
        }, 5000);
    }
});

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

function imagePageselectCallback(page_index, jq) {
    
    $('#results ul li:visible').hide();
    for (i = (page_index * 4); i < (page_index * 4 + 4); i++)
    {
        $('#results ul li:eq(' + i + ')').show();
    }
    $.get('includes/save_session.php?page_index=' + page_index, function(data){});
    return false;     
}

function imageHomePageselectCallback(page_index, jq) {
    
    $('#home ul li:visible').hide();
    for (i = (page_index * 3); i < (page_index * 3 + 3); i++)
    {
        $('#home ul li:eq(' + i + ')').show();
    }
    return false;     
}

/** 
 * Initialisation function for pagination
 */
function initPagination() {
    $(".searchPagination").pagination($('#results ul li').length, {
        current_page: $('#current_page').val(),
        callback: imagePageselectCallback,
        items_per_page: 4
    });
    
    $(".homePagination").pagination($('#home ul li').length, {
        callback: imageHomePageselectCallback,
        items_per_page: 3
    });
 }
