$(document).ready(function()
{
	function file_exists (url) {
		// http://kevin.vanzonneveld.net
		// +   original by: Enrique Gonzalez
		// +      input by: Jani Hartikainen
		// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
		// %        note 1: This function uses XmlHttpRequest and cannot retrieve resource from different domain.
		// %        note 1: Synchronous so may lock up browser, mainly here for study purposes. 
		// *     example 1: file_exists('http://kevin.vanzonneveld.net/pj_test_supportfile_1.htm');
		// *     returns 1: '123'
		var req = this.window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
		if (!req) {throw new Error('XMLHttpRequest not supported');}
		// HEAD Results are usually shorter (faster) than GET
		req.open('GET', url, false);
		req.send(null);
		if (req.status == 200){
			return true;
		}
		return false;
	}
	
	$('#bord_small').hide();
	
	/**
	 * get screen resolution to generate background-image
	 */
	if(file_exists("img/bg_"+screen.width+"x"+screen.height+".jpg")==true) {
		$("body").css("backgroundImage", "url(img/bg_"+screen.width+"x"+screen.height+".jpg)");
		$("#bergen").css("backgroundImage", "url(img/bg_"+screen.width+"x"+screen.height+".png)");
	} else {
		$("body").css("backgroundImage", "url(img/bg_2048x1536.jpg)");
		$("#bergen").css("backgroundImage", "url(img/bg_2048x1536.png)");
	}
	
	
	$('#preview').css('height',$(window).height()-40);
	
	
	
	function thisMovie(movieName)
	{
		 if (navigator.appName.indexOf("Microsoft") != -1) {
			 return window[movieName];
		 } else {
			 return document[movieName];
		 }
	}
	
	$('#toDeLijn').click(function() {
		eventUrl	= '';
		eventUrlInfo= '';
		eventType	= '';
		eventId		= '';
		eventName	= '';
		$('#bord').css('zIndex',999);
		$('#flashHolder').css('zIndex',900);
		//thisMovie("flashHolder").toEvent(provincie, eventName);
		thisMovie("flashHolder").toEvent(provincie, provincie);
		return false;
	});
	
	$('#evenementNaam').click(function() {
		eventUrl	= '';
		eventUrlInfo= '';
		eventType	= '';
		eventId		= '';
		eventName	= '';
		$('#bord').css('zIndex',999);
		$('#flashHolder').css('zIndex',900);
		//thisMovie("flashHolder").toEvent(provincie, eventName);
		thisMovie("flashHolder").toEvent(provincie, provincie);
		return false;
	});
	
	$('#newLocation').change(function()
	{
		toNew		= 1;
		provincie	= $('#newLocation').val();
		eventName	= '';
		thisMovie("flashHolder").toEvent(provincie, provincie);
	});
	
	$('.showInIframe').click(function()
	{
		eventUrl	= $(this).attr('href');
		eventUrlInfo= $(this).attr('url_info');
		eventType	= $(this).attr('name');
		eventId		= $(this).attr('id');
		eventName	= $(this).attr('title');
		provincie	= $('#newLocation').val();
		$('#bord').css('zIndex',0);
		$('#flashHolder').css('zIndex',999);
		$('#evenementNaam').html($(this).html());
		thisMovie("flashHolder").toEvent(provincie, eventName);
		return false;
	});
});