var pathExpressInstallFile = escape("/lib/flash/expressInstall.swf");

function initHyperlinks() {
	$("a[rel=external]").each(function() {
		$(this).click(function() { window.open($(this).attr("href")); return false; });
		if ($(this).attr("title") == "") $(this).attr("title", "Deze link wordt in een nieuw venster geopend.")
		else $(this).attr("title", "'" + $(this).attr("title") + "' wordt in een nieuw venster geopend.");
	});
}

function initContentFlash() {
	$('.contentflash').each(function() {
		if($(this).find('a').length > 0)
		{
		var strParams = $(this).find('a').attr('rel').split('|');

		$(this).flashembed({
			src: strParams[0],
			version: [9],
			width: parseFloat(strParams[2]),
			height: parseFloat(strParams[3]),
			expressInstall: pathExpressInstallFile,
			wmode: 'transparent',
			scale: 'noscale',
			onFail: function() {
		    alert("You need version 20.0 to view this content");
	}
		})
		}
	});
}

//geen nieuwe versie NyroModal gebruiken!
function initNyromodal() {

	$.fn.nyroModal.settings.regexImg = '[^\.]\.(jpg|jpeg|png|tiff|gif|bmp)\s*$|image.aspx';
	$.fn.nyroModal.settings.minWidth = 0;
	$.fn.nyroModal.settings.minHeight = 0;
	$.fn.nyroModal.settings.endShowContent = function() {initContentFlash(); fotoboek();};
    if ($.browser.msie && $.browser.version == "6.0") {
        $.fn.nyroModal.settings.minWidth = '500';
        $.fn.nyroModal.settings.minHeight = '500';
    }
    else {
        $.fn.nyroModal.settings.minWidth = '100';
        $.fn.nyroModal.settings.minHeight = '100';
    }

    $("a[href*='#nyro']").click(function() {

        var url = $(this).attr('href');
        if (url.indexOf("googlemaps") > 0) {
            //url = url.substring(0, url.length - 5);
            //speciale template voor IE7 omdat IE7 geen javascript uitvoert bij nyromodal request, en dit is wel vereist voor googlemaps.
            url = "/?template=googlemaps_nyro.htm";
        }
      
        $.nyroModalManual({
            url: url
           
        });
        return false;
    });


	$("a[href*='fid=']").click(function() {
		var PhotoBookURL = $(this).attr('href') + '#nyro';
		$.nyroModalManual({
			url: PhotoBookURL
			,height: '505'
			,width: '790'
		});
		return false;
	});
}

function initIE6() {
	$('#nav li').each(function() {
		$(this).hover(function() {
			$(this).addClass('sfhover');
		}, function() {
			$(this).removeClass('sfhover');
		});
	});
}

$(function () {

	//Preserves the mouse-over on top-level menu elements when hovering over children
	$("#nav ul").each(function (i) {
		$(this).hover(function () {
			$(this).child().find("a").slice(0, 1).addClass("active");
		}, function () {
			$(this).child().find("a").slice(0, 1).removeClass("active");
		});
	});

	$('#nav li.level3').parents('li.level2').addClass('extramenu');

	$('#menu').supersleight();
	$('#contentgedeelte .contentpart .mediaitem').supersleight();
	$('#slogan').supersleight();
	$('#logo').supersleight();
	$('.span.shadow').supersleight();
	$('#contentmenu').supersleight();
	
	


	


});

function initForms() {
    $('form.validatesearch_util').validate();
	$('form.validatesearch').validate();
	$('form.validate').validate();
	$('form.validate_alert').validate({
		onfocusout: false

		,showErrors: function(errorMap, errorList) {
			var error = 'Er zijn ' + this.numberOfInvalids() + ' fouten gevonden:\n\n';
			for (var i in errorList)
			{
				error = error + errorList[i].element.name + ':' + errorList[i].message + '\n';
			}
			alert(error);
	}
	});
}

function initFAQ() {
	$('#faq_select_cat').change(function() {
		$('#faq_cat_form').submit();
		return false;
	});
}

function fotoboek() {
    $('.scrollable .items').css({ 'width': '20000em', 'position': 'absolute', 'clear': 'both' });
    $('.scrollable').css({ 'margin-left': '0', 'height': '90px' });
    $('#photobook_previous').addClass('disabled prev browse left');
    $('#photobook_next').addClass('disabled next browse right');
    $("div.scrollable").scrollable();

    $(".items img").click(function () {
        var url = $(this).parent().attr("href");
        var title = $(this).parent().attr("title");
        var wrap = $("#image_wrap").fadeTo("medium", 0.5);
        var img = new Image();
        img.onload = function () {
            wrap.fadeTo("fast", 0, function () {
                wrap.find("img").attr("src", url);
                wrap.fadeTo("fast", 1);
            });
        };
        img.src = url;
        $('.description').text(title);
        return false;
    }).filter(":first").click();
}

$(document).ready(function () {
    //Initialiseer hier je scripts
    initHyperlinks();
    initIE6();
    initContentFlash();
    initNyromodal();
    initForms();
    initFAQ();
    $('.scroll-pane').jScrollPane();
    paragraphSwitch();
    $('#blokken .col:last').addClass('collast');

    if (!$('.paragraphwrapper .mediaitem').length) $('#submenu').css('top', '0');

    /*vinzzz: hide last > */
    var $lastbreadcrumb = $('#breadcrumbs li.last span.last span').text();
    $('#breadcrumbs li.last span.last').html('<span>' + $lastbreadcrumb + '</span>');

    $('#paragraph_image').empty();
    //alert($('.textparagraaf:first .mediaitem_wrapper').clone().html());
    $('.textparagraaf:first .mediaitem_wrapper').clone().show().appendTo($('#paragraph_image'));
    $('#paragraph_image a.nyroModal').nyroModal();
    //alert($('#paragraph_image').html());
});

function paragraphSwitch() {
    $('#contentmenu a').each(function () {
        var anchor = $(this).attr('href');
        $(this).click(function () {
            var $par = $('.textparagraaf[rel=' + anchor + ']');
            $('.paragraphwrapper').prepend($par);
            $('#paragraph_image').empty();
            //$('.textparagraaf:first .mediaitem_wrapper').show().appendTo($('#paragraph_image'));
            $par.find('.mediaitem_wrapper').clone().show().appendTo($('#paragraph_image'));
            $('#paragraph_image a.nyroModal').nyroModal();
            return false;
        });
    });
}
