jQuery(function($) {
	
	
	if(window.DD_belatedPNG) { 
		DD_belatedPNG.fix('#nav-main, #nav-main_bg, #nav-main-preview, #content .speechbubble, #content .speechbubble-box img, #nav-main .selected a ,#content-outerbox, #content-innerbox, #content-box, #cta-expert-vsl'); 
		DD_belatedPNG.fix('#frm-search, #frm-search label, #frm-search input.submit');
		DD_belatedPNG.fix('#col-c .banner img, .home-banner img');
		DD_belatedPNG.fix('#partner-vsl');
		DD_belatedPNG.fix('#know-how-vsl .btns img');
		DD_belatedPNG.fix('*');
	}

	$(window).load(function() { 
	
			// show the javascript buttons that were hidden in CSS
			$('#staf-btn, #latest_knowhow_leesonline, .issue a.nvsPopup, #media a, a.nvsAlbum').css('visibility', 'visible');
	
			$('#footer').css('display', 'block');
			if($('#nav-main-preview').length > 0 ) {
			if ($.browser.msie && $.browser.version.substr(0,1)<7) { 
				window.setTimeout(
					function() { 
						p = $('#page-box').offset();
						l = 0 - p.left - parseInt($('#nav-arrow').width());
						$('#nav-arrow').css('left', l);
						
						$('#nav-arrow').animate({ left: '-2px' }, 1500, 'easeOutBounce', function() { 
							$('#nav-main.home li.first a').addClass('iehover'); 
							$('#nav-main.home a').previewAnimation ()
							$('#nav-main a').hover(
								function() {
									$("#nav-main li").removeClass('selected'); 
									$("#nav-main a").removeClass('iehover'); 
									t = $(this).offset();
									$('#nav-arrow').css( 'top', t.top);
									$(this).addClass('iehover'); 
								}, function() { });
							$('#nav-main li:first a').trigger('mouseover');
				
						});	
				}, 1500 );	
			} else {
				window.setTimeout(
					function() { 
						
						p = $('#page-box').offset();
						l = 0 - p.left - parseInt($('#nav-arrow').width());
						$('#nav-arrow').css('left', l);
				
						$('#nav-arrow').animate({ left: '-2px' }, 1500, 'easeOutBounce', function() { 
								$('#nav-main.home li.first a').addClass('mhover'); 
								$('#nav-arrow').remove(); 
								$('#nav-main.home a').previewAnimation ()
								$('#nav-main a').hover(
									function() {
										$("#nav-main li").removeClass('selected'); 
										$("#nav-main a").removeClass('mhover'); 
										$(this).addClass('mhover'); 
									}, function() { });
								$('#nav-main li:first a').trigger('mouseover');
							}  
						); 
					}, 1500 );		
			}
		}
		
		if ($('#nav-okb').length > 0) {
			offset = $('#nav-main-bg').offset();
			height = $('#nav-main-bg').height();
			$('#nav-okb').css({ top: offset.top+height });
		}
		
	})
	
	$(document).ready(function() {
	
    	$("#themelist li").css("cursor", "pointer").hover(function() {
			$(this).children("a").css({ textDecoration: "underline" });
		}, function() {
			$(this).children("a").css({ textDecoration: "none" });
		}).click(entireElemClick);
			
		
		$('div.banner').css('display','block');
		
		if($('#nav-main-preview').length == 0 ) {
			if ($.browser.msie && $.browser.version.substr(0,1)<7) { 
				$('#nav-main a').hover(
					function() {
						$("#nav-main li").removeClass('selected'); 
						$("#nav-main a").removeClass('iehover'); 
						t = $(this).offset();
						$('#nav-arrow').css({ 'top': t.top, 'left': '-1px' });
						$(this).addClass('iehover'); 
					}, function() {
						$("#nav-main a").removeClass('iehover');  
					});
			} else {
				$('#nav-main a').hover(
					function() { 
						$(this).addClass('mhover'); 
					}, function() {
						$("#nav-main a").removeClass('mhover');  
				});
			}
		}
		
		$("#frm-search .autocomplete").autoCompleteSearch();
		$("#frm_onzemensen .autocomplete").autoCompleteSearch();
		
	});

	$('#col-a.home #nav-main a').previewAnimation ()

	$("#frm-search-results").nvsNiceForm({});
	
	if ($('#flash').length > 0) {
		var taal = $('#flash').attr('lang');
	
		var flashvars = { xml_file: '/xml/thema_menu.xml.php', taal: taal };
		var params = { wmode: 'transparent'  };
		var attributes = {};
		
		swfobject.embedSWF("/swf/thema_menu.swf", "flash", "750", "260", "9.0.0", '/swf/expressInstall.swf', flashvars, params, attributes);
	}

	//$("#parallelsessies").nvsNiceForm({});
	$("#frm-search-results").nvsNiceForm({});
	$("#okb_search .filter").nvsNiceForm({});
	$("#frm_onzemensen_filter").nvsNiceForm({ 
// 		changeFunction: function () {
// 			alert("hier een ajax call die de content van #onzemensen_result update !! \n return value <ul><li><a href=\"#\"><img src=\"img/gd/vsl_60x60.png\" alt=\"\" /></a><a href=\"#\" class=\"txt\"><strong>Anneke de Groot</strong><br />Functie naam</a></li></ul> + eventueel paging" ); 
// 		}
	});
	
	$('#diensten-vsl-text-outerbox .more').click( function() {
		$('#diensten-vsl-video').hide();
		$('#diensten-vsl-text *').hide();
		$('#diensten-vsl-text-outerbox').animate( { width:"508px" } , 1000, function() { 
			$('#diensten-vsl-text-content').css({ padding: '0 10px 0 0', overflow : 'auto' }); 
			$('#diensten-vsl-text *:not(.more) ').show(); 
		})
		return false;
	});
	
	$('#diensten-vsl-text-outerbox .less').click( function() {
		$('#diensten-vsl-text *').hide();
		$('#diensten-vsl-text-outerbox').animate( { width:"152px" } , 1000, function() { 
			$('#diensten-vsl-text-content').css({ padding: '0', overflow : 'hidden' }).scrollTop(0); 
			$('#diensten-vsl-text *:not(.less)').show(); 
			$('#diensten-vsl-video').show();
		})
		return false;
	})	

});

$.fn.autoCompleteSearch = function()
{
	var	jQueryMatchedObj = this,
		flyOutObj = $('#autoCompleteFlyOut'),
		offset = $(jQueryMatchedObj).parent().offset();
		current = null;
		
		
	$(jQueryMatchedObj).parent().css({ position: 'relative', zIndex: '900' });
	$(jQueryMatchedObj).css({ position: 'relative', zIndex: '900' });

	$(jQueryMatchedObj).keyup(function(objEvent)
	{
		stopbubble = false;
		switch(objEvent.keyCode) { 
			case 13:	stopbubble = true;
						break;
			case 38:	// up
						if(current != null) {
							current =  $("#autoCompleteFlyOut li[selected='true']");
							previous = current.prev();
							if(previous.length != 0) {
								current.attr("selected","false").removeClass("focus");
								previous.attr("selected","true").addClass("focus");
								$(jQueryMatchedObj).val(previous.text());
							}
						}
						stopbubble = true;
						break;
			case 40:	// down
						if(current == null) {
							current =  $("#autoCompleteFlyOut li:first");
							nextone = current;
							if(nextone.length != 0) {
								current.attr("selected","false").removeClass("focus");
								nextone.attr("selected","true").addClass("focus");
								$(jQueryMatchedObj).val(nextone.text());
							}
						} else {
							current =  $("#autoCompleteFlyOut li[selected='true']");
							nextone = current.next();
							if(nextone.length != 0) {
								current.attr("selected","false").removeClass("focus");
								nextone.attr("selected","true").addClass("focus");
								$(jQueryMatchedObj).val(nextone.text());
							}
						}
						stopbubble = true;
						break;
			default:	q = $(jQueryMatchedObj).val();
						site_index = $('#site_index_holder').val();
						$.ajax({
							type: "POST",
							url: "../ajax/se_autocomplete_search.ajax.php",
							data: 'q='+q+'&site_index='+site_index,
							success: function(html)
							{
								current = null;
								$(flyOutObj).css(
								{
									top: offset.top + $(jQueryMatchedObj).height()-3,
									left: offset.left,
									width: parseInt($(jQueryMatchedObj).parent().outerWidth())+"px",
									zIndex: '500'
								})
								.html(html)
								.show();
								$('a', flyOutObj).click(function()
								{
									$(jQueryMatchedObj).val($(this).text());
									return false;
								});
							}
						}); 
		}
		if(stopbubble) { 
			objEvent.stopPropagation();
			objEvent.preventDefault();
		}
	})
	.blur(function()
	{
		setTimeout("$('#autoCompleteFlyOut').hide();", 500);
	});
	
};



function entireElemClick (){
	window.location=$(this).find("a").attr("href");
	return false;
}
	
(function($) {
	
		$.fn.previewAnimation = function(options) { 
			var defaults = {
				speed: 			1000,
				fadeSpeed: 		500,
				activeImage:	0,
				imageCount:		0,
				TO:				'',
				animate:		true,
				animateId:		null
			};	
			
			var options = $.extend(defaults, options);
			var jQueryMatchedObj;
			
			function startAnimation(obj) {
				options.activeImage = 0;
				options.MatchedObj = obj; 
				options.previewObj = "#"+$(options.MatchedObj).attr("id")+"_preview";
				options.previewImagesObj = $(options.previewObj +" div");
				options.imageCount = $(options.previewImagesObj).length;
			
				options.animate = true;
				options.animateId = $(options.MatchedObj).attr("id");
				
				$(options.previewImagesObj).hide();
				$(options.previewObj +" div:first").show();
				$("#nav-main-preview div.preview").css({display: 'none'});
				$(options.previewObj).css({display: 'block'});
				if(options.imageCount > 1){  start(); }
			}
			
			function start() {
				window.clearTimeout(options.TO);
				options.TO = window.setTimeout(function() { animate() }, options.speed); 
			} 	
			
			function animate() {
				if(options.activeImage+1 < options.imageCount) {
					$(options.previewImagesObj[options.activeImage]).fadeOut(options.fadeSpeed*3);
					$(options.previewImagesObj[options.activeImage+1]).fadeIn(options.fadeSpeed*3, endAnimation);
				} else {
					$(options.previewImagesObj[0]).fadeIn(options.fadeSpeed*2);
					$(options.previewImagesObj[options.imageCount-1]).fadeOut(options.fadeSpeed*3, endAnimation);
				}
			}
			
			function endAnimation() {					
				if(options.activeImage+1 < options.imageCount) {
					options.activeImage++;
				} else {
					options.activeImage = 0;	
				}
				if(options.animate) { start(); }
			}
			
			function stopAnimation() { 
				options.animate = false
				window.clearTimeout(options.TO);
				$("#nav-main-preview div.preview div").css({display: 'none'});
				$("#nav1_preview").css({display: 'block'});
			}
			
			return this.unbind('hover').hover(
				function() { 
					if($(this).attr("id") != options.animateId) {
						stopAnimation(this); 
						startAnimation(this); 
					};
				},
				function() { }
			);
		}
})(jQuery);

