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;

}

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 inlogPopUp() {

	var obj = $('<div id="inlogScherm" />');

	$('#loginLink').click(function() {
		if ($(this).text() == "login") {
			obj.load('/default.aspx?template=inloggen.htm&culture=en-GBsic=1& #frmLogin', function() {
				obj.appendTo($('#loginLink').parent())
				$('#inlogScherm').toggle('fast').find('#frmLogin').validate({
					submitHandler: function(form) {
						var data = $('#frmLogin').serialize();
						$.ajax({
							type: 'POST',
							url: '/default.aspx',
							data: data,
							success: function(data) {
								if (data.indexOf('frmLogin') > 0) {
									//fout opgetreden
									var $data = $(data);
									//vinzzz 2011-3-23 snap even niet waarom $data.html() nu alleen de errormelding bevat, maar het werkt
									if ($('#errmessage').length) { }
									else {
										$('#inlogScherm').prepend('<div id="errmessage" />');
									}
									$('#errmessage').html($data.html());
								} else {
									//succesvol gelukt
									form.submit();
								}
							},
							erro: function() { alert('error'); },
							dataType: 'html'
						});


					}
				});

			});
			return false;
		} else {
			return true
		}
	});

}

function initNyromodal() {
	//$.fn.nyroModal.settings.regexImg = '[^\.]\.(jpg|jpeg|png|tiff|gif|bmp)\s*$|image.aspx';
	//$.fn.nyroModal.settings.showBackground = function(elts, settings, callback) { elts.bg.css({ opacity: 0, background: '#000000' }).fadeTo(500, 0.55, callback); }
	//$("a[href*='image.aspx']").nyroModal();
	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*='fid=']").click(function() {
		var PhotoBookURL = $(this).attr('href');// + '#nyro';

		$.nyroModalManual({
			url: PhotoBookURL
		, height: '475'
		, width: '790'
		});
		return false;
	});

}


$(document).ready(function() {

	//Initialiseer hier je scripts
	initContentFlash();
	initPopups();
	initNyromodal();
});

$(function() {

	$('.news-overzicht').find('li:nth-child(even)').addClass('even');

	$('#content div.paragraph:first').each(function() {
		if ($(this).text().length > 15) $(this).addClass('first-paragraph');
	});
	//$('#content p:first').addClass('first-paragraph');

	$('.pi-groups li').hover(function() {
		$(this).find(".item-links").fadeIn();
	},
    function() {
    	$(this).find(".item-links").fadeOut();
    });

	$('.programma_cluster li .extra-info').hide();
	if (cluster_id) {
		$('.programma_cluster li').find('#cluster_' + cluster_id).show();
	}
	$('.programma_cluster .open_close').click(function() {
		$(this).toggleClass('close').parent().find('.extra-info').slideToggle();
		$(this).parent().toggleClass('programma_cluster-innerAddBg')

	});

	if ($('body').hasClass('homepage')) {
		$('#main-page-fader').crossSlide({
			sleep: 5,
			fade: 1
		}, [
	          { src: '/lib/images/fader/Laura.jpg' },
	          { src: '/lib/images/fader/Johan_heemskerk.jpg' },
	          { src: '/lib/images/fader/Tilman.jpg' },
	          { src: '/lib/images/fader/Stephane.jpg' },
	          { src: '/lib/images/fader/Rory.jpg' },
	          { src: '/lib/images/fader/leo.jpg' },
	          { src: '/lib/images/fader/jo.jpg' },
	          { src: '/lib/images/fader/Esther.jpg' },
	          { src: '/lib/images/fader/Coen.jpg' }

	        ]);
	}

	if ($.browser.msie) {
		$('#nav').find('li').hover(function() {
			$(this).addClass('hover');
		}, function() {
			$(this).removeClass('hover');
		});
	}


	var pijltje = $('<img src="/lib/images/pijltje_links.png" class="pijltje" style="float:right; z-index:10; position:relative;" />');
	$('#nav ul').find('li:has(ul) > a').append(pijltje);

	$('.publication-list').find('.more-link').click(function() {
		var pos = $(this).position();
		var left = pos.left + 20;
		var top = pos.top + 20;

		$(this).parent().find('.auteurs').css({
			position: 'absolute',
			left: left + 'px',
			top: top + 'px',
			background: '#fff',
			padding: '5px 10px 5px 10px',
			background: '#144353',
			color: '#fff'
		}).toggle();

		return false
	});

	if ($('body').hasClass('extranet')) {
		$('#header').append('<div id="extranet">extranet</div>')
	}

	inlogPopUp();

	$("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.");
	});

	$('form.validate').validate({
		rules: {
			wachtwoord: "required",
			wachtwoord2: {
				required: true,
				equalTo: '#wachtwoord'
			}
		}
	});

	if ($.browser.msie && jQuery.browser.version == '7.0') {
		var zIndexNumber = 1000;
		// Put your target element(s) in the selector below!
		$(".pi-groups li.persoon").each(function() {
			$(this).css('zIndex', zIndexNumber);
			zIndexNumber -= 10;
		});
	};

	$("#txtPeopleVerjaardag").datepicker({
		dateFormat: 'dd/mm/yy',
		firstDay: 1,
		changeYear: true,
		yearRange: 'c-100:c',
		isRTL: false,
		showMonthAfterYear: false,
		yearSuffix: '',
		showOn: "both",
		buttonImage: "/lib/images/calendar.gif",
		buttonImageOnly: true
	});

	$('.paging a.active').mouseover(function() {
		
	});
	$('.paging a.active').click(function() {
		return false;
	});
});
