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();};
    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 initForms()
{
	$('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 initjqueryforms () {
	$('form').jqTransform({ imgPath: '/lib/jqtransformplugin/img' });
		var myW = 375;
		$('input').css("width", myW);
		$('input').parents(".jqTransformInputWrapper").css("width", myW);
		var myW = 40;
		$('input.small').css("width", myW);
		$('input.small').parents(".jqTransformInputWrapper").css("width", myW);
		var myW = 50;
		$('input.smaller').css("width", myW);
		$('input.smaller').parents(".jqTransformInputWrapper").css("width", myW);
		var myW = 100;
		$('input.middle').css("width", myW);
		$('input.middle').parents(".jqTransformInputWrapper").css("width", myW);
		var myW = 30;
		$('input.checkbox').css("width", myW);
		$('input.checkbox').parents(".jqTransformInputWrapper").css("width", myW);
		var myW = 220;
		$('input.captcha').css("width", myW);
		$('input.captcha').parents(".jqTransformInputWrapper").css("width", myW);
		var myW = 80;
		$('input.timeinput').css("width", myW);
		$('input.timeinput').parents(".jqTransformInputWrapper").css("width", myW);
}



function initslider() {

	$(window).load(function() {
		$('#slider').nivoSlider({
			effect: 'fade', //Specify sets like: 'fold,fade,sliceDown'
			slices: 1,
			animSpeed: 900, //Slide transition speed
			pauseTime: 6000,
			startSlide: 0, //Set starting Slide (0 index)
			directionNav: false, //Next & Prev
			directionNavHide: true, //Only show on hover
			controlNav: false, //1,2,3...
			controlNavThumbs: false, //Use thumbnails for Control Nav
			controlNavThumbsFromRel: false, //Use image rel for thumbs
			controlNavThumbsSearch: '.jpg', //Replace this with...
			controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
			keyboardNav: true, //Use left & right arrows
			pauseOnHover: false, //Stop animation while hovering
			manualAdvance: false, //Force manual transitions
			captionOpacity: 0.8, //Universal caption opacity
			beforeChange: function() { },
			afterChange: function() { },
			slideshowEnd: function() { }, //Triggers after all slides have been shown
			lastSlide: function() { }, //Triggers when last slide is shown
			afterLoad: function() { } //Triggers when slider has loaded
		});
	});

}


function inittipsy() {
	$('.example-fade').tipsy({ fade: true });
}



$(document).ready(function() {
	//Initialiseer hier je scripts
	initHyperlinks();
	initIE6();
	initContentFlash();
	initNyromodal();
	initForms();
	initFAQ();
	initslider();
	initjqueryforms();
	inittipsy();
});
