
	$(document).ready(function(){
		replace_submit('#frm-news-filter, #frm-vacature-filter, #frm-search-results, form.std-form, #frm-home-newsletter-subscribe, #frm-newsletter-subscribe');
		entireDivClick($('#photo-gallery li, .news-item, .agenda-item, .vacature-item, .search-item'));
		clear_inputs_on_focus();
		 
		// if there is a print option show the button
		if(window.print) { $('a.more.print').show().click( function () { window.print(); return false; } ); }
		
		if($("#photo-album").length){
		
		 //   $('head').append('<link rel="stylesheet" type="text/css" href="/css/jquery.fancybox-1.3.4-1.css" media="screen">');
		    $('head').append('<script type="text/javascript" src="/js/jquery.fancybox-1.3.4.pack.js"></script>');
		
// 			new Multiloader(['/css/jquery.fancybox-1.3.4-1.css','/js/jquery.fancybox-1.3.4.pack.js'], function(){
				 $("#photo-album ul li a").fancybox({
					'transitionIn'	:	'elastic',
					'transitionOut'	:	'elastic',
					'speedIn'		:	600,
					'speedOut'		:	200,
					'overlayColor'	: '#ffffff',
					'overlayShow'	:	true,
					'titleShow'		: true,
					'titlePosition'	: 'inside',
					'titleFormat'	: formatTitle
				});
// 			});
		}
	});
	
	/*
	 * Format the fancy box title
	 */
	function formatTitle(title, currentArray, currentIndex, currentOpts) {
 	   return '<div id="fancy-title"><strong>' + (currentIndex + 1) + ' van ' + currentArray.length + ' </strong>' + (title && title.length ? '<b>' + title + '</b>' : '' ) + '</div>';
	}

	/*
	 * Clear input fields on focus
	 * Removes the values of all text-inputs with class clear on focus and places the value back on blur when it's still empty
	 */
	function clear_inputs_on_focus () {
		$("input[type=text].clear").focus( function () { 
			if ( !$(this).attr("startvalue") ) {  
				$(this).attr("startvalue", $(this).val());
			} 
			if ( $(this).val() == $(this).attr("startvalue") ) {
				$(this).val('');	
			}
		}).blur( function () { 
			if ( $(this).val() == '' ) {
				$(this).val($(this).attr("startvalue"));
			}
		});
	}

	/*
	 * Make an entire element clickable
	 */
	function entireDivClick (jObj) {
		
		jObj.hover( function () { 
						$(this).addClass('hover'); 
					}, 
					function () { 
						$(this).removeClass('hover'); 
					})
			.click( function() {
						if($(this).find("a").attr("target") == '_blank'){
							window.open($(this).find("a").attr("href"));
						}else{
							window.location=$(this).find("a").attr("href");
						}
						return false;
					});
	}
	
	
	/*
	 * Replace standard submit buttons with custom buttons
	 */
	function replace_submit(obj) {
		var obj = $(obj);
		obj.find('input.submit').css({ position: "absolute", top: "-99999px", left: "-99999px" });
		obj.find('a.submit').show().click(function() {
			$(this).closest('form').submit();
			return false;
		});
	
	}
	
	/**
	 * Loader loads javascript on the fly
	 */	 	
	function Loader(src, callback){
		this.loaded = 0;
		this.callback = callback;
		var head= document.getElementsByTagName('head')[0];
		var script= document.createElement('script');
		script.type= 'text/javascript';
		script.async = true;
		script.onreadystatechange= function () {
	   		if (this.readyState == 'complete' || this.readyState == 'loaded') { callback() };
	   	}
		script.onload = this.callback;
		script.src= src;
		head.appendChild(script)
	}
	Loader.prototype.callback = function(){
		if(this.loaded == 0){
			this.loaded = 1;
			this.callback();
		}
	}
	
	/**
	 * Loader loads javascript on the fly
	 */	 	
	function Multiloader(sources, callback){
		this.loaded = 0;
		this.callback = callback;
		this.scripts = [];
		sources = typeof(sources) == 'string' ? Array(sources) : sources ;
		var head= document.getElementsByTagName('head')[0];
		var src = null;
		
		var loader = this;
		for(k in sources){
			src = sources[k];

			if(String(src).substr(-3, 3) == '.js'){
				var script = document.createElement('script');
				script.type= 'text/javascript';
				script.async = true;
	// 			script.onreadystatechange= function () {
	// 		   		if (this.readyState == 'complete' || this.readyState == 'loaded') { callback(script) };
	// 		   	}
				script.onload = function (){ loader.isloaded(script); };
				script.src= src;
				
				this.scripts.push(script);
				head.appendChild(script)
			} else {
				var css = document.createElement("link");
				css.setAttribute("rel", "stylesheet");
				css.setAttribute("type", "text/css");
				css.loaded = true;

// 				css.async = true;
				css.onreadystatechange= function () {
			   		if (this.readyState == 'complete' || this.readyState == 'loaded') { loader.css(script) };
			   	}
			   	
				css.onload = function (){ loader.isloaded(css); };
				
				css.setAttribute("href", src);
				
				this.scripts.push(css);
				head.appendChild(css);
			}
		}
	}
	Multiloader.prototype.isloaded = function(script){
		script.loaded = 1;
		var all_loaded = true;
		for(k in this.scripts){
			scrpt = this.scripts[k];
			if(!scrpt.loaded){
				all_loaded = false;
				break;
			}
		}
		
		if(all_loaded && this.loaded == 0){
			this.loaded = 1;
			this.callback();
		}
	}
