function initializeMap(r){
	
		var region = r;
		var l;
		var backa = false;
		
		if (region == null || region =='' || region == 'undefined' || region =="sweden" || region == 'home') { region = "sweden"; l = "sweden"; }
		else { l = region; showPopup(region); backa=true;}
		
		var image = 'url(/images/map/region-'+region+'_big.png)';
		
		$('#locations').hide();
		
		$('#map').fadeOut(500, function(){
			$('#map').css({
				width: '955px',//955
				height: '550px',
				backgroundImage: image,
				position: 'absolute'
			});
			
			$('#map').empty().fadeIn(1500);
			//$('#content_wrapper').hide().fadeIn(1000);
			$('#content_wrapper').fadeOut(800);
			$('#content').load('/includes/content.php',{'region': l} ,function (){
																					$('#content_wrapper').fadeIn(800);
																				});
			//alert(region);
			$('#dieter').hide().fadeIn(1500);
			loadBullets(region, backa);
		//	log.info('Bullets loaded!');
		
		});
	}

	function addZoomable(id, width, height, top, left, alt){
		$('<img class="zoomable" src="/images/blank.gif" id="' + id + '" alt="'+alt+'" title="Klicka för att zooma in på '+alt+'" />').css({
			border: 'none',
			position: 'absolute',
			width: 1 + 'px',
			height: 1 + 'px',
			top: 300 + 'px',
			left: 350 + 'px',
			cursor: 'pointer'
		}).appendTo('#map');
		
		$('#area_'+id).click(function() {
	$('#dieter').fadeOut(800);
				
			$('#content_wrapper').fadeOut(800).hide();
			
			$('<div id="load" style="display:none"><img src="/images/load.gif" alt="map" style="position:absolute;left:340px;top:516px;z-index:20000;" /><p style="color:#fff;position:absolute;left:432px;top:533px;z-index:20000;">Laden...</p></div>').appendTo('#page').hide().fadeIn(1000);
						
			$('#map').queue(function () {
				$(this).fadeOut(1000);
				$(this).dequeue();
				//log.info('Queue 1!');
			});
			
			$('#map').queue(function () {
				$('#area_highlight').css({backgroundImage: ''});
				$('#area_sormland').unbind('mouseover');
				$('#area_stockholm').unbind('mouseover');
				$('#area_ostergotland').unbind('mouseover');
				$('#area_narke').unbind('mouseover');
				$('#area_vastmanland').unbind('mouseover');
				$(this).dequeue();
				//log.info('Queue 2!');
			});
			
			$('#map').queue(function() {
				$(this).css({backgroundImage: ''});
				$(this).fadeIn(1000);
				//log.info('Queue 3!');
				$(this).dequeue();
				
			});
									
			$(this).siblings().fadeOut();
			
			$('#'+id).fadeOut(500).hide()
				   .attr('src', '/images/map/region-' + id + '_big.png')
				   .fadeIn(1500)

				   .animate({
						width: '670px',
						height: '550px',
						top: '0px',
						left: '0px'
					}, 800, '', function(){
						$('#map')
						.css({backgroundImage: 'url(images/map/region-' + id + '_big.png)'})
						.empty();
						
					
						loadBullets(id, true);
					});
				   
				   return false;
		});
	}
	
	function loadBullets(id, back){
		
			//	$.post(''+id, {ajax: 'true'},  function (data){$('#map').html(data);
			
				
		$('#map').load("/"+id, {ajax: 'true'}, function(){
			

			//add back button
			if(back){
				
				$('<a id="back" href="javascript:void(0)"><span><span>Zurück zur Startseite&nbsp;</span></span></a>')
					.appendTo(this).hide().fadeIn()
					.click(function(){initializeMap()});
			}
			else { // width height top left  --->
				
				addZoomable('sormland',250, 205, 141, 151,'Södermanland');
				addZoomable('ostergotland', 250, 273, 268, 43, 'Östergötland');
				addZoomable('stockholm', 237, 345, 0, 341, 'Stockholm');
				addZoomable('vastmanland', 151, 198, 6, 144, 'Västmanland');		
				addZoomable('narke', 267, 326, 18, 0, 'Närke');
				
			}
			//place bullets
			
			$('#map a.bullet').each(function(){
						//alert('hej');							   
				$(this).hide().fadeIn(500);								   
				$(this).click(function() { return false;} ); // Disable content links
				
				// Hover-effect
				$(this).bind("mouseenter",function(){
					$(this).addClass("buttonH");
     			}).bind("mouseleave",function(){
			      $(this).removeClass("buttonH");
				});
														   
														   
				var coords = $(this).attr('rel').split('-');
				$(this).css({left: coords[0] + 'px', top: coords[1] + 'px', width:'auto'})
					   .hide()
					  .fadeIn()
					  .show()
					  .css({display:'block'})
					   .click(function(){showPopup($(this).attr('id'));});
					  
			});
			//log.info('Bullets ready!');
			$('#load').remove();
			// START
		



	$('#area_sormland').mouseover(function(){
		$('#area_highlight').css({
				background: 'url(/images/map/sormland_hover.png) no-repeat 0px 0px'
				
		});
	});
	
	$('#area_sormland').mouseout(function(){
		$('#area_highlight').css({
				backgroundImage: ''		
		});		
	});
	
	$('#area_ostergotland').mouseover(function(){
		$('#area_highlight').css({
				background: 'url(/images/map/ostergotland_hover.png) no-repeat 0px 0px'
				
		});			
	});
	
	$('#area_ostergotland').mouseout(function(){
		$('#area_highlight').css({
				backgroundImage: ''			
			});
	});
	
	$('#area_narke').mouseover(function(){
		$('#area_highlight').css({
				background: 'url(/images/map/narke_hover.png) no-repeat 0px -1px'			
		});	
	});
	
	$('#area_narke').mouseout(function(){
		$('#area_highlight').css({
				backgroundImage: ''			
		});		
	});
		
	$('#area_stockholm').mouseover(function(){
		$('#area_highlight').css({
				background: 'url(/images/map/stockholm_hover.png) no-repeat 0px 0px'			
		});	
	});
	
	$('#area_stockholm').mouseout(function(){
		$('#area_highlight').css({
				backgroundImage: ''			
		});
				
	});
	
	$('#area_vastmanland').mouseover(function(){
		$('#area_highlight').css({
				background: 'url(/images/map/vastmanland_hover.png) no-repeat 0px 0px'			
		});	
	});
	
	$('#area_vastmanland').mouseout(function(){
		$('#area_highlight').css({
				backgroundImage: ''			
		});	
	});




			// STOP
		});
		//}, 'html');
	}
	
	function showPopup(id){
		$('#map div.popup').fadeOut(); 
		$('#content_wrapper').fadeOut(); 
		var boxid = '#' + id + '-box';
		$('#map').css({opacity: '1'});
		$(boxid).fadeIn(800).find(".gallery").PikaChoose();
		$('a.close').click(function(){
			$(boxid).fadeOut(800, function(){
										   $('#map').css({opacity: '0.9'});
										   $('#content_wrapper').fadeIn(); 
										   });
			
		});
		
	}
//$('#area_ostergotland').mouseover(function(){ alert('hej'); });
	
	//initialize map

//initializeMap();

/*


	
			
	

*/
