// gebasseerd op jQuery versie 1.2.6 (minified)

$(function() {
	/* reiswijzer functionaliteiten */
	
	if($('#frm_reiswijzer').length > 0) {
		page_id = $('#page_id').val();
	
 		$('#frm_reiswijzer').load('/ajax/laad_reiswijzer_vraag.ajax.php', {page_id: page_id}, 
 			function(data) {
 				$('#frm_reiswijzer').html(data);
				_typeface_js.replaceText(document.getElementById('frm_reiswijzer'));
				$('#frm_reiswijzer .typeface-js').css({visibility : 'visible'});
				init_reiswijzer();
 			});
	}

	
	$('#frm-login_username').focus(function () { 
		if(!$(this).attr("startvalue")) {  
			$(this).attr("startvalue", $(this).val());
		} 
		if($(this).val() == $(this).attr("startvalue")) {
			$(this).val('');	
		}
	});
	$('#frm-login_username').blur(function () { 
		if($(this).val() == '') {
			$(this).val($(this).attr("startvalue"));
		}
	});
	
	$("input[@name='mm_email']").focus(function () { 
		if(!$(this).attr("startvalue")) {  
			$(this).attr("startvalue", $(this).val());
		} 
		if($(this).val() == $(this).attr("startvalue")) {
			$(this).val('');	
		}
	});
	$("input[@name='mm_email']").blur(function () { 
		if($(this).val() == '') {
			$(this).val($(this).attr("startvalue"));
		}
	});
	
	// content blok footer
	$('#staf-btn').css( { display: 'inline'});
	$('#print-btn').css( { display: 'inline'});
	$('#print-btn a').click( function () { window.print(); return false; } );

	
	// login functions 
	$('#login_password').addClass('bg');
	
	$('#login_password').focus(function () { $('#login_password').removeClass('bg'); });
	$('#login_password').blur(function () {
		if($('#login_password').val() == '') { 	
			$('#login_password').addClass('bg')
		}
	});
	
	// agenda block 
	$('#agendalist tr:gt(0):not(.nolink)').hover(function () { $(this).css({ cursor: "pointer" });}, function () { /* do nothing */ } );
	$('#agendalist a').addClass("nohover");
	$('#agendalist tr:gt(0):not(.nolink)').click( function () { document.location = $(this).find('td:first a').attr("href");	});
	
	// profile interest check all on/off
	$('#frm-edit-profile #interest1').click(function() { 
		if($('#interest1').attr("checked")) {
			$('input:checkbox').attr("checked","checked")
			$('#interest1').attr("checked","checked")
		}
	});
	
	$('#frm-edit-profile input:checkbox').click(function() { 
		if ( $(this).attr("id") != 'interest1' && !$(this).attr("checked")) {
			$('#interest1').removeAttr("checked");
		}
	});
	
	// search check all on/off
	$('#frm-search-advanced #interest0').click(function() { 
		if($('#interest0').attr("checked")) {
			$('input:checkbox').attr("checked","checked")
			$('#interest0').attr("checked","checked")
		}
	});
	
	$('#frm-search-advanced input:checkbox').click(function() { 
		if ( $(this).attr("id") != 'interest0' && !$(this).attr("checked")) {
			$('#interest0').removeAttr("checked");
		}
	});
	
	// search check all on/off
	$('#frm-agenda-selectie #interest1').click(function() { 
		if($('#interest1').attr("checked")) {
			$('#frm-agenda-selectie input:checkbox').attr("checked","checked");
			$('#interest1').attr("checked","checked")
		}
	});
	
	$('#frm-agenda-selectie input:checkbox').click(function() { 
		if ( $(this).attr("id") != 'interest1' && !$(this).attr("checked")) {
				$('#interest1').removeAttr("checked");
		}
	});


	contentarchief_blok_alinks();
	
	if ($('#flash_carrousel').attr("id")) {
		load_flashobject("/swf/carrousel.swf", "flash_carrousel", "600", "251")
	}
	if ($('#flash_nieuws_ticker').attr("id")) {
		load_flashobject("/swf/nieuws_ticker.swf?page_id="+$('#flash_nieuws_ticker').attr("page_id"), "flash_nieuws_ticker", "601", "26")
	}
	
	// succesbericht bij wijziging na 2 seconden laten verdwijnen (zoals bij het profiel wijzigen)
	if ($('#successmsg').attr("id")) {
		setTimeout("$('#successmsg').slideUp();", 3000);
	}	


	$(document).ready(function() {
		init_reiswijzer();
		
		var wisseltijd;
		var page_id;
		
		// al de elementen waar (eventueel) een multiple classe aan vast zit een interval geven voor het wisselen van advertenties
		$('.multiple').each(function() {
			page_id = $('#' + $(this).parent().attr('id')).attr('page_id');
			wisseltijd = ($(this).attr('wisseltijd') * 1000);
			setInterval('wissel_advertentie("' + $(this).parent().attr('id') + '", "' + $(this).attr('id') + '", "' + page_id + '")', wisseltijd);
		});
		
	});


});


function init_reiswijzer() {
	$('#reiswijzer a.answer').click( function() { 
		id = $(this).attr('id');
		if($('#'+id+'input').val() == 1) {
			$(this).children('.vsl').children('.checkbox').css({backgroundPosition: 'top left'});
			$('#'+id+'input').val('0');
			
			/**
			 *
			 * Zet de class van de span met de class "checkbox_checked" op "checkbox".
			 * Dit moet om de javascript versie en de non-javascript versie te laten werken.		 
			 *
			 */
			$(this).children('.vsl').children('.checkbox_checked').addClass('checkbox');
			$(this).children('.vsl').children('.checkbox_checked').removeClass('checkbox_checked');
			
		} else {
			$(this).children('.vsl').children('.checkbox').css({backgroundPosition: 'bottom left'});
			$('#'+id+'input').val('1');
		}
		
		/**
		 * Laad het aantal blokje.
		 */		 		
		$.post("/ajax/laad_reiswijzer_totaal.ajax.php",
			$("#frm_reiswijzer").serialize(),
			function(data) {
				$("#totals").html(data)
				_typeface_js.replaceText(document.getElementById('totals')); 
				$('#totals .typeface-js').css({visibility : 'visible'});
			} 
		);
		
		/**
		 * Laad de resultaten onder de reiswijzer.
		 */		 		 		
		if($('#reiswijzerresultaten').length > 0) {
			$("#reiswijzerresultaten").hide();
			$("#reiswijzerresultaten").html('');
			$('#resultatenloader').show();
			$.post("/ajax/laad_reiswijzer_resultaten.ajax.php",
				$("#frm_reiswijzer").serialize(),
				function(data) {
					$("#reiswijzerresultaten").html(data);
					setTimeout(show_reiswijzer_resultaten,500);
				}
			);
		}
		
		return false;
	}).each(function() {
		id = $(this).attr('id');	
		if($('#'+id+'input').val() == 1) {
			$(this).children('.vsl').children('.checkbox').css({backgroundPosition: 'bottom left'});
		}
	});
	
	$('#reiswijzer a.step').click(function() {
		toStep = $(this).attr('id');
		page_id = $('#page_id').val();
		$('#frm_reiswijzer').hide();
		$('#loader').show();
		$("#frm_reiswijzer").serialize();
		$.post(	"/ajax/laad_reiswijzer_vraag.ajax.php?step="+toStep+'&page_id='+page_id, 
				$("#frm_reiswijzer").serialize(),
				function(data){
					$('#frm_reiswijzer').html(data);
					setTimeout(show_reiswijzer,500);
				},
				"html");

		return false;
	});
	
	$('#reiswijzer a.step.staprestart').unbind('click');
	$('#reiswijzer a.step.staprestart').click(function() {
		$('#frm_reiswijzer').hide();
		$('#loader').show();
		$("#frm_reiswijzer").serialize();
		$.post(	"/ajax/laad_reiswijzer_vraag.ajax.php?step=staprestart", 
				$("#frm_reiswijzer").serialize(),
				function(data){
					$('#frm_reiswijzer').html(data);
					setTimeout(show_reiswijzer,500);
					
					/**
					 * Laad de resultaten onder de reiswijzer.
					 */		 		 		
					if($('#reiswijzerresultaten').length > 0) {
						$("#reiswijzerresultaten").hide();
						$("#reiswijzerresultaten").html('');
						$('#resultatenloader').show();
						$.post("/ajax/laad_reiswijzer_resultaten.ajax.php",
							$("#frm_reiswijzer").serialize(),
							function(data) {
								$("#reiswijzerresultaten").html(data);
								setTimeout(show_reiswijzer_resultaten,500);
							}
						);
					}
					
				},
				"html");

		return false;
	});
}
function show_reiswijzer() {
	$('#loader').hide();
	$('#frm_reiswijzer').show();
	_typeface_js.replaceText(document.getElementById('frm_reiswijzer')); 
	$('#frm_reiswijzer .typeface-js').css({visibility : 'visible'});
	init_reiswijzer();
}
function show_reiswijzer_resultaten() {
	$('#resultatenloader').hide();
	$("#reiswijzerresultaten").show();
	
	_typeface_js.replaceText(document.getElementById('aanbiederhdr')); 
	$('#aanbiederhdr').css({visibility : 'visible'});
	
	_typeface_js.replaceText(document.getElementById('reiswijzerresultaten')); 
	$('#reiswijzerresultaten .nobg').css({visibility : 'visible'});
}

function wissel_advertentie (positie, placeholder_id, page_id) {

	$.post("/ajax/ad.ajax.php",  {placeholder_id: placeholder_id, positie: positie, page_id: page_id }, function(data) { 
		if(data.match('use_iframe')) {
			
			$('#' + positie + ' #' + placeholder_id).html('');
			$('<iframe frameborder="0"></iframe>').attr({ border: '0', scrolling: 'no', frameborder : '0', marginwidth: '0', marginheight: '0', id: positie + '_' + placeholder_id + '_frame'}).appendTo('#' + positie + ' #' + placeholder_id);

			data_array = data.split('|');
			
			height = 250;
			if(data_array[1]) {
				if (data_array[1] > 0) {
					height = parseInt(data_array[1]);
				}
			}
			
			$('#' + positie + '_' + placeholder_id + '_frame').attr({height: height});

			/**
			 * Pas de hoogte van het iframe aan, aan de inhoud van het iframe
			 */
 			$('#' + positie + '_' + placeholder_id + '_frame').attr({src : '/ajax/ad.ajax.php?placeholder_id='+placeholder_id+'&positie='+positie+'&page_id='+page_id+'&getscript=1'});
			
			
			
		} else {
			$('#' + positie + ' #' + placeholder_id).html(data);
		}
	})

}

function contentarchief_blok_alinks () {
	// contentarchief_blok acties
	$("#contentarchief_blok .paging a").click(function() {
		update_contentarchief_blok($(this).attr("href"));
		return false;
	});
}
	
// update content archief
function update_contentarchief_blok(page) {
	$("#contentarchief_blok").load("/ajax/contentarchief_blok.ajax.php", {doelpagina: page}, function () { contentarchief_blok_alinks (); });
}

function load_flashobject(swf_url, id, width, height) {
	nvsflash = new nvsFlash(swf_url, id, width, height, '8');
	nvsflash.setParam("quality", "high");
	nvsflash.setOption('detectorPath', '/swf/flashdetector.swf');
	nvsflash.loadFlash(id);
}
