$(document).ready(function(){
    // load flash
    $('.js_flash').each(function(){
        slideshowvars = $(this).find('.js_flashlink').html();
        //strip HTML comment from flash vars
        slideshowvars = slideshowvars.replace(/^<!--/, "");
        slideshowvars = slideshowvars.replace(/-->$/, "");
        slideshowheight = $(this).css('height');
        slideshowwidth = $(this).css('width');
        $(this).html("");
        $(this).flash({
            src: slideshowvars,
            width: slideshowwidth,
            height: slideshowheight,
            wmode: 'transparent',
            allowFullScreen: 'true'
        });
    });
	
	$('.js_colorbox').colorbox('');

    // png fix
    $(document).pngFix();

    //submit form link
    $('.js_submitform').click(function(){
        $(this).parents('form:first').submit();
        return false;
    })

	//AJAX FORMS automatisch
	if (typeof $().ajaxForm == 'function')
	{
		$('form.js_ajaxform').each(function(){
			$(this).append('<input type="hidden" name="ajax_post" value="oke" />');
			var form = $(this);
			$(this).ajaxForm({
				dataType: 'json',
				beforeSerialize: function(){
					form.find('.js_hint').val('');
				},
				beforeSubmit: function(){
					form.parent().find('.js_errormelding').remove();
				},
				success: function(response){
					if (response.success)
					{
						form.html('<p>'+response.message+'</p>');

						if ( typeof _gaq == 'object' )
							_gaq.push(['_trackPageview', location.pathname + '-bedankt']);
						else if ( typeof pageTracker == 'object' )
							pageTracker._trackPageview( location.pathname + '-bedankt' );
					}
					else if (response.message)
					{
						form.before($('<p class="foutmelding js_errormelding">'+response.message+'</p>'));
					}
					form.find('.js_hint').trigger('blur');
				}
			})
		})
	}
   
    $(function () {
        $(".dropdown").each(function () {
            $(this).parent().eq(0).hoverIntent(
            {
                timeout: 100,
                over: function(){
                    var current = $(".dropdown:eq(0)", this);
                    current.slideDown(100);
                },
                out: function(){
                    $(".dropdown:eq(0)", this).hide();
                }
            }
            );         
            $(this).children(':first').css('margin-left' , $(this).parent().offset().left +  'px');
            $(this).children(':first').css('background-position' , (parseInt($(this).parent().width() / 2, 10) - 8) + 'px 0px');
        });
    });
   
    // slideshow 
    $('#rotatingitems').cycle({
        pause: true,
		timeout: 6000,
        fx: 'custom',
        cssBefore: { top: 110 },
        animIn:  { top: 0 },
        animOut: { top: -110 }
    });
	
    
	$('#slideshow a').css('display','block');
    if ($('#slideshow').length > 0)
    {
        $('#slideshow').fadeSlideShow({
            width: 460,
            height: 305,
            autoplay: true,
            NextElement : false,
            PrevElement: false,
            PlayPauseElement: false,
			allowKeyboardCtrl: false,
            ListElement: false
        });
    }
    
	// laatste x pagina's opslaan
    var cLastPages = $.cookie('lastpages');
    var lastPages = new Array();
    if (cLastPages) {
        lastPages = cLastPages.split("\\");
    }
    lastPages.push(document.location);
    while(5 < lastPages.length) {
        lastPages.shift();
    }
    var joined = lastPages.join("\\");
	var date = new Date();
    date.setTime(date.getTime() + (30 * 24 * 60 * 60 * 1000));
    $.cookie('lastpages', joined, {path: '/', expires: date});

    $('.js_lastpagesfield').each( function() {
        $(this).attr('value',joined);
    });
});
