function switchContent(id, target){
	new Effect.Fade(id, { 
		duration: 0.5,
		afterFinish: function(){
			new Ajax.Updater(id, target, { 
				asynchronous: true, 
				evalScripts: true, 
				method: 'get',
				onComplete: function(){
					new Effect.Appear(id, { duration: 0.5 });							
				}
			});	
		}
	});
}

function loadMap(map, image){
	
	var oldURL = $(image).src;
	
	$$('#'+map+' a').each(function(fireState){
		Event.observe(fireState, 'mouseover', function(){
			$(image).src = "/images/maps/"+map+"/" + fireState.id.split("_")[0] + ".jpg";
		});
		Event.observe(fireState, 'mouseout', function(){
			$(image).src = oldURL;
		});
	});
	
	$$('#'+map+' area').each(function(state){
		Event.observe(state, 'mouseover', function(){
			$(image).src = "/images/maps/"+map+"/" + state.id + ".jpg";
		});
		Event.observe(state, 'mouseout', function(){
			$(image).src = oldURL;
		});
	});
	
	$$('#'+map+' area.notification').each(function(notification){
		Event.observe(notification, 'click', function(event){
			var elm = Event.element(event);

			var target = elm.href;
			event.stop();
			
			if (!Prototype.Browser.IE) {
				switchContent('main', target);
			} else {
				new Ajax.Updater('main', target, { 
					asynchronous: true, 
					evalScripts: true, 
					method: 'get'
				});	
			}
					
		});
	});
	
}

Event.observe(window, 'load', function() {
	
	if($('germany')) { loadMap('germany','deutschland');}
	if($('austria')) { loadMap('austria','austriaImage');}
	if($('switzerland')) { loadMap('switzerland','swissImage');}
	
});
