
function mycarousel_initCallback(carousel)
{
    // 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();
    });
	
	jQuery('#rechts').bind('click', function() {
        carousel.next();
        return false;
    });

    jQuery('#links').bind('click', function() {
        carousel.prev();
        return false;
    });
};

function showImage(image)
{
	var image  = image.substr(0, image.lastIndexOf('.', image));
	
 	jQuery('#the_text').hide();
	jQuery('#the_text').html('<img src="'+ image +'plaatje.png" style="cursor: pointer" onclick="showPopup(\'/wp-content/themes/timax/popup/contactform.php\')">');
	jQuery('#the_text').fadeIn('slow');		
}

function visibleCallback(carousel, object, index, state){
	var index = index;
	var state = state;
	
	var image = $(object).children('img').attr('src');

	showImage(image);
};


jQuery(document).ready(function() 
{
    jQuery('#carousel').jcarousel({
        auto: 6,
        wrap: 'circular',
		scroll: 1,
		size: 4,
        initCallback: mycarousel_initCallback,
		buttonNextHTML: null,
        buttonPrevHTML: null,
		itemVisibleInCallback: visibleCallback
    });
	jQuery('#contactformlink').click(function() {
		jQuery('.contactform').show();
		jQuery('.contactbg').show();
	});
});

function closePopup(reload_page)
{
	jQuery(".contactform_popup").hide();
	jQuery(".contact_overlay").fadeOut('slow');
	jQuery(".contact_overlay").hide();
	
	if(reload_page) 
	{
	    if(/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)) 
	    {
	        document.location.href=document.location.href
	    }
	    else
	    {
	        window.location.reload();
        }
    }
}

function showPopup(location)
{
	jQuery(".contact_overlay").fadeIn('slow');
	jQuery(".contactform_popup").fadeIn('slow');
	// show loader	
	// load frame
	jQuery("#form_frame").attr('src', location);
}
