try {
  document.execCommand("BackgroundImageCache", true, true);
} catch(err) {}

/**
 * This file is called at the first request.
 * Holds some global methods and makes sure required scripts are called when using a ajax request.
 */
// A default function to create a dialog.
function showDialog(title, data){
	$('<div>'+data+'</div>').dialog({ 
						show: 'slide', 
						title: title, 
						width: '700px',
						hide: 'fold',
						open: function(){
							var $this=$(this);
							var $dialog=$this.parents('.ui-dialog');
							$dialog.addClass('active');
							$('.ui-dialog:not(.active)').fadeOut('slow', function(){
								$(this).remove();
							});
							$dialog.removeClass('active');
						},
						close: function(){
							$(this).remove();
						}
					});
}
// A function that makes the footer work as expected.
function updateFooter(loc){
	$('.ajax_ul a').each(function(){
		var $this=$(this);
		if($this.attr('href')==loc){
			if(loc=='/index'||loc=='/'){
				loc='home';
			}
			loc=loc.replace('/', '');
			var title=$this.attr('title');
            var s = loc.substring(0,1);
            var l = loc.substring(1);
            loc = s.toUpperCase()+l;
			$('#locationText').html(loc+' / '+title);
		}
	});
	$('#disableJs').remove();
	//$('#footer .location').before('<a href="'+document.location.pathname+'?disableJs=true" id="disableJs">Disable javascript</a>');
}
// 2 functions used to make the flowers disapear when window size becomes to small.
function fixFlowers(){
	flowerResize();
	$(window).resize(function(){
		flowerResize();
	});
	
}
function flowerResize(){
	if($('body').width()<951){
		$('.flowerLeft, .flowerRight').fadeOut();
	}else{
		$('.flowerLeft, .flowerRight').fadeIn();
	}
}
// Fixes the console.log() errors in the non-firebug browsers
function compat(){
	if (!window.console) {
		window.console = {
			log: function() {}
		};
	};
}
// This shows and hides the loader.
function ajaxLoader(show){
	if(show===true){
		$('#head .center').css({background: 'url(/images/layout/logo_loader.gif) left center no-repeat'});
		return;
	}
	$('#head .center').css({background: 'url(/images/layout/logo.png) left center no-repeat'});
}

// Called when ready.
$().ready(function(){
	compat();
	fixFlowers();
	updateFooter(document.location.pathname);
	
	//$(document).pngFix(); 
	//showDialog('Onder constructie', '<div><h3>Website in ontwikkeling</h3><p>Ondanks dat we nu online bereikbaar zijn is deze website nog niet helemaal af.<br />Graag hopen wij dat u even geduld kunt hebben met de laatste puntes op de spreekwoordelijke "i".</p><h3>Todos:</h3><ul><li>Tekst moet worden nagelopen door de content manager</li><li>Nieuws pagina\'s staan nog niet online</li><li>Portfolio pagina\'s staan nog niet online</li><li>IE browser check</li><li>Op dit moment wordt ie6 NIET ondersteund, uiteindelijke beslissing moet worden gemaakt</li><li>nieuws balk geeft w3c foutje</li><ul></div>')
});
