var pathExpressInstallFile = escape("/lib/flash/expressInstall.swf");

function initPopups() {
    $.fn.nyroModal.settings.regexImg = '[^\.]\.(jpg|jpeg|png|tiff|gif|bmp)\s*$|image.aspx';
    $.fn.nyroModal.settings.minWidth = 0;
    $.fn.nyroModal.settings.minHeight = 0;

    $("a[href*='fid=']").click(function() {
    	var PhotoBookURL = $(this).attr('href') + '#nyro';
    	$.nyroModalManual({
    		url: PhotoBookURL
			, height: '505'
			, width: '790'
    	});
    	return false;
    });
}

function initContentFlash() {
    $('.contentflash').each(
        function() {
            var strId = $(this).attr('id');
            var strParams = $(this).find('a').attr('rel').split('|');

            $('#' + strId).flashembed(
            {
                src: strParams[0],
                version: [strParams[1]],
                width: strParams[2],
                height: strParams[3],
                expressInstall: pathExpressInstallFile,
                wmode: 'transparent',
                scale: 'noscale'
            })
        }
    );
}

function initSiteCatMenu() {
    $('#lstSiteCategories').change(
        function() {
            window.location = '/' + taal + '/' + $('#lstSiteCategories').val() + '/default.aspx';
        }
    );
}

function initFaq() {
    $(".faq_container").hide();

    $(".faq").toggle(function() {
        $(this).addClass("active_faq");
    }, function() {
        $(this).removeClass("active_faq");
    });

    $(".faq").click(function() {
    	$(this).next(".faq_container").slideToggle("slow,");
    	return false;
    });
}

function initHeaderFlash() {
	$('.foto_header').flashembed(
    {
    	src: '/lib/flash/header.swf',
    	version: [9],
    	wmode: 'opaque',
    	width: 650,
    	height: 114
    },
    {	//dit zijn flashvars
    	xmlPath: escape('/lib/xml/headerimages.ashx?taal=' + taal + '&id=' + structuurid)
    });
}

function initForm() {
    $('.validateform').validate();
    jQuery.extend(jQuery.validator.messages, {
        required: "Dit veld is verplicht.",
        maxlength: jQuery.format("U kunt niet meer dan {0} karakters invoeren."),
        minlength: jQuery.format("U dient minimaal {0} karakters in te voeren."),
        rangelength: jQuery.format("U dient minimaal {0} en maximaal {1} karakters in te voeren."),
        email: "Een geldig emailadres is verplicht.",
        url: "Een geldig URL is verplicht.",
        date: "Een geldige datum is verplicht.",
        number: "Een geldig getal is verplicht.",
        digits: "Gebruik alleen cijfers.",
        equalTo: "Herhaal de invoer nogmaals.",
        range: jQuery.format("U dient een waarde tussen {0} en {1} in te voeren."),
        max: jQuery.format("U dient een waarde kleiner dan of gelijk aan {0} in te voeren."),
        min: jQuery.format("U dient een waarde groter dan of gelijk aan {0} in te voeren."),
        creditcard: "Een geldig creditcardnummer is verplicht."
    });
}

function initFaqSiteCatMenu() {
    $('#btnShowFaq').click(
        function() {
            window.location = $('#lstFaqSiteCategories').val();
            return false;
           }
    );
}

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.");
    });
}

$(document).ready(function() {
    //Initialiseer hier je scripts
    initContentFlash();
    initPopups();
    initSiteCatMenu();
    initFaq();
    initForm();
    initFaqSiteCatMenu();
    initHeaderFlash();
    initHyperlinks();

    if ($('body[class*=googlemaps]').length > 0) initGoogleMaps();
});

sfHover = function() {
	var sfEl = document.getElementById("nav");
	if (!sfEl == 'undefined') {
		var sfEls = sfEl.getElementsByTagName("LI");

		for (var i = 0; i < sfEls.length; i++) {
			sfEls[i].onmouseover = function() {
				this.className += " sfhover";
			}
			sfEls[i].onmouseout = function() {
				this.className = this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);



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();
}

function slideSwitch() {
	var $active = $('#portalcontainer img.active');

	if ($active.length == 0) $active = $('#portalcontainer img:last');

	// use this to pull the images in the order they appear in the markup
	var $next = $active.next().length ? $active.next()
        : $('#portalcontainer img:first');

	// uncomment the 3 lines below to pull the images in random order

	// var $sibs  = $active.siblings();
	// var rndNum = Math.floor(Math.random() * $sibs.length );
	// var $next  = $( $sibs[ rndNum ] );


	$active.addClass('last-active');

	$next.css({ opacity: 0.0 })
        .addClass('active')
        .animate({ opacity: 1.0 }, 1000, function() {
        	$active.removeClass('active last-active');
        });
}

$(function() {
	setInterval("slideSwitch()", 5000);
});
