///////////////////////////////////////////////////////////////////////////////
// Debug
///////////////////////////////////////////////////////////////////////////////
var debug = false;
///////////////////////////////////////////////////////////////////////////////
// mapmanager class
///////////////////////////////////////////////////////////////////////////////
var mapmanager = new function() 
{
	// --- Class porperties ---------------------------------------------------
	//this.arrdata = [];
	this.selectedDataId;
	this.selectedDataOffset;
	this.firstLoad = true;
	this.icons = { 'videos':{'nail': 'videos_nail.png'}, 
				   'people':{'nail': 'people_nail.png'},
				   'blogs':{'nail' : 'blogs_nail.png'}, 
				   'discussions':{'nail' : 'discussions_nail.png'}, 
				   'appeals':{'nail': 'appeals_nail.png'},
				   'photos':{'nail':'photos_nail.png'}};
				   
	var scope = this;
	// --- Class constructor --------------------------------------------------
	this.init = function()
	{	
		try{
			// Set height for panelWrapper so it dont "jump".
				jQuery('#panelWrapper').css('height', '45px');
			// ---
			
			scope.insertIconsToMap();
			gmap.init('map');
			gmap.setCenter(59.33231386546924, 18.064441680908203, 4);
			
			G_PHYSICAL_MAP.getMinimumResolution = function () { return 3 };
			G_NORMAL_MAP.getMinimumResolution = function () { return 3 };
			G_SATELLITE_MAP.getMinimumResolution = function () { return 3 };
			G_HYBRID_MAP.getMinimumResolution = function () { return 3 };
	
			G_PHYSICAL_MAP.getMaximumResolution = function () { return 10 };
			G_NORMAL_MAP.getMaximumResolution = function () { return 10 };
			G_SATELLITE_MAP.getMaximumResolution = function () { return 10 };
			G_HYBRID_MAP.getMaximumResolution = function () { return 10 }; 
			
			gmap.map.setMapType(G_PHYSICAL_MAP);
			
			$('<div class="topBorder"></div>').appendTo("#map");
			$('<div class="leftBorder"></div>').appendTo("#map");
			$('<div class="rightBorder"></div>').appendTo("#map");
			$('<div class="bottomBorder"></div>').appendTo("#map");
			
			$('<div class="zoomIn"><span href="#">+</span></div>').click(function(){gmap.map.zoomIn();}).appendTo("#map");
			$('<div class="zoomOut"><span href="#">-</span></div>').click(function(){gmap.map.zoomOut();}).appendTo("#map");
			
					
			//$('#map').hide();
			//$.history.init(mapmanager.anchorCallback);
			//scope.initInfoBox(window.location.hash);
			jQuery.estilo.tools.watcher.watch(window.location, 'hash', function(old_value, new_value){
				if(new_value != null) {
					scope.anchorCallback(new_value);
				}
			});		
		}catch(ex){ if(debug) alert("Method: init \nName: " + ex.name + "\nMessage: " + ex.message + "\nNumber: " + ex.number + "\nDescription: " + ex.description); }
	}
	
	
	this.loadXmlPoints = function(xml)
	{
		$.getJSON(xml, scope.loadXmlPointsComplete);  
	}
		
	// --- Class method: insertIconsToMap -------------------------------------
	this.insertIconsToMap = function()
	{
		try{
			$.each(scope.icons, function(name, icon){
				debugg(mapPluginUri + "/_images/colorElements/" + icon.nail);
				gmap.addIcon(
						mapPluginUri + "/_images/colorElements/" + icon.nail,
					30, 40,
					mapPluginUri + "/_images/colorElements/shadow.png",
					32, 8,
					name
				);
			});		
		}catch(ex){ if(debug) alert("Method: insertIconsToMap \nName: " + ex.name + "\nMessage: " + ex.message + "\nNumber: " + ex.number + "\nDescription: " + ex.description); }
	}

	
	this.numGeo = [];
	this.geoCounter = function(lng, lat) {
		try{
			for(var i = 0; i < this.numGeo.length; i++) {
				if(lng == this.numGeo[i].lng && lat == this.numGeo[i].lat) {
					this.numGeo[i].count++;
					return this.numGeo[i].count;
					break;
				}
			}
			this.numGeo.push({lng:lng, lat:lat, count:0})
			return 0;
		}catch(ex){ if(debug) alert("Method geoCounter \nName: " + ex.name + "\nMessage: " + ex.message + "\nNumber: " + ex.number + "\nDescription: " + ex.description); }
	} 
	
	// --- Class method: loadXmlPointsComplete --------------------------------
	this.loadXmlPointsComplete = function(json) {
		try{
			scope.numGeo = [];
			// clear old points
			gmap.clearMarkers(); 
			//var d = createXMLDocument(xmlstring); 
			//var json = $.xml2json(d); 
			
			scope.unblock();
			
			if(json.rssItems == undefined) {
				scope._updateNrOfStories(0);
				debugg('hiddade inga resultat, vad händer nu?');
				return;
			}
			var rssItems = json.rssItems.rssItem;
			try{
				if(rssItems.length == undefined) {
					scope._updateNrOfStories(1);
					rssItems = [rssItems];
				}else{
					// Update nr of matches
					var nrOfStories = json.rssItems['@attributes'].numItems;
					scope._updateNrOfStories(nrOfStories);
					// ---
				}
			}catch(ex){
				scope._updateNrOfStories(0);
			}
	
			var value = "";
			for (var i=0; i < rssItems.length; i++) {
				var oneMarker = rssItems[i];
				
				
				var d = new Object();
				d.id = oneMarker['@attributes'].id;
				
				d.color = oneMarker.color;
				d.type = oneMarker.iconType;
				d.title = oneMarker.title;
				var stickers = oneMarker.stickers.sticker;
				if(stickers.length == undefined) stickers = [stickers]
				for (var j=0; j < stickers.length; j++) {
					var oneSticker = stickers[j];
					if(oneSticker['@attributes'].lng != undefined) {
						d.lng = oneSticker['@attributes'].lng * 1;
						d.lat = oneSticker['@attributes'].lat * 1;
						
						var numGeo = scope.geoCounter(d.lng, d.lat);
	
						var zlvl = 3;
						if (numGeo > 25) {
							zlvl = 10;
							var randGeo = scope.randomGeo((64000000/10)/3, 64000000/5);
						}
						else if (numGeo > 15) {
							zlvl = 9;
							var randGeo = scope.randomGeo((64000000/5)/3, 64000000/5);
						}
						else if (numGeo > 13) {
							zlvl = 8;
							var randGeo = scope.randomGeo((64000000/5)/3, 64000000/5);
						}
						else if (numGeo > 9) {
							zlvl = 7;
							var randGeo = scope.randomGeo((64000000/4)/3, 64000000/4);
						}
						else if (numGeo > 4) {
							zlvl = 6;
							var randGeo = scope.randomGeo((64000000/3)/3, 64000000/3);
						}
						else if (numGeo > 3) {
							zlvl = 5;
							var randGeo = scope.randomGeo((64000000/2)/3, 64000000/2);
						}
						else if (numGeo > 0) {
							zlvl = 4;
							var randGeo = scope.randomGeo((64000000/2)/2, 64000000/1.5);
						}
						else {
							zlvl = 3;
							var randGeo = {lng:0, lat:0};
						}
						
						d.lat += randGeo.lat;
						d.lng += randGeo.lng;
						
						d.point = new GLatLng(d.lat, d.lng);
						d.centerOffset = new GPoint(-350, 300);
						d.zlvl = zlvl;
						//scope.arrdata[i] = d;
						scope.createMarker(d);
					}
				}
			}
			gmap.updateMarkerManager();
			
			$('#map').show();
			gmap.zoomAndPanToMarkers();
			
			if(scope.firstLoad && scope.selectedMarker !=  undefined) {
				scope.firstLoad = false;
				
				var point = gmap.map.fromLatLngToDivPixel(gmap.map.getCenter());
				point.x += 10;
				point.y += 10;
				var moveToLatLng = gmap.map.fromDivPixelToLatLng(point);
				gmap.map.panTo(moveToLatLng);
				// Center on the marker with the correct offset
				//alert(scope.selectedOffset);
				
				gmap.centerOnMarker(scope.selectedMarker, scope.centerOffset, true);
				gmap.infoBox.openOnMarker(scope.selectedMarker, "ds", true, 475, 600, true, 20);
			}
		}catch(ex){ if(debug) alert("Method loadXmlPointsComplete \nName: " + ex.name + "\nMessage: " + ex.message + "\nNumber: " + ex.number + "\nDescription: " + ex.description); }
	}
	
	this.randomGeo = function(minR, maxR)
	{
		try{
			var r = minR + Math.random()*(maxR-minR);
			var a = Math.random()*Math.PI*2;
			var x = Math.cos(a)*r;
			var y = Math.sin(a)*r;
			/*
			if(Math.random() > 0.5) {
				var lng = (((max/3)*Math.random()) + (max/3))/100000000;
				var lat = (((max/3)*Math.random()) + (max/3))/100000000;	
			}
			else {
				var lng = (((max/3)*Math.random()) + (max/3))/100000000;
				var lat = (((max/3)*Math.random()) + (max/3))/100000000;
			}
			*/
			return {lng:x/100000000, lat:y/100000000};
		}catch(ex){ if(debug) alert("Method randomGeo \nName: " + ex.name + "\nMessage: " + ex.message + "\nNumber: " + ex.number + "\nDescription: " + ex.description); }
	}
	
	
	// --- Class method: loadPointDataComplete ---------------------------------
	this.loadPointDataComplete = function(json)
	{
		try{
			scope.setupInfoBox(json);
			gmap.infoBox.updateWindowPosition();
			
			$("#FWindowcontent").find(".infoBoxBloggContent img").maxSize({maxWidth:220});
			$("#FWindowcontent").find(".infoBoxBloggContent object").maxSize({maxWidth:268});
			$("#FWindowcontent").find(".infoBoxBloggContent embed").maxSize({maxWidth:268});
		}catch(ex){ if(debug) alert("Method loadPointDataComplete \nName: " + ex.name + "\nMessage: " + ex.message + "\nNumber: " + ex.number + "\nDescription: " + ex.description); }
	}

	// --- Class method: createXMLDocument ------------------------------------
	function createXMLDocument(string)
	{
		try{
			var browserName = navigator.appName;
			var doc;
			if (browserName == 'Microsoft Internet Explorer')
			{
				doc = new ActiveXObject('Microsoft.XMLDOM');
				doc.async = 'false'
				doc.loadXML(string);
			} 
			else 
			{
				doc = (new DOMParser()).parseFromString(string, 'text/xml');
			}
			return doc;
		}catch(ex){ if(debug) alert("Method createXMLDocument \nName: " + ex.name + "\nMessage: " + ex.message + "\nNumber: " + ex.number + "\nDescription: " + ex.description); }
	}
	// --- Class method: createMarker -----------------------------------------
	this.createMarker = function (obj)
	{
		try{
			var location = new google.maps.LatLng(obj.lat, obj.lng);
	
			var marker = gmap.insertMarker(location,
							obj.type,
							obj.type,
							obj.title,
							false,
							obj.centerOffset,
							20,
							obj.id,
							obj.zlvl);
			if(scope.selectedDataId == obj.id) {
				scope.selectedMarker = marker;
				scope.centerOffset = obj.centerOffset;
			}
			
			//marker.selectedDataId = markerId;
			marker.getHTML = function(){ return $("#blogginfo").clone().show().attr("id",""); };
		}catch(ex){ if(debug) alert("Method createMarker \nName: " + ex.name + "\nMessage: " + ex.message + "\nNumber: " + ex.number + "\nDescription: " + ex.description); }
	}
	// --- Class method: getPointData (called from fwindow) -------------------
	this.getPointData = function()
	{
		try{
			mapmanager.block();
			window.location.hash='start=' + scope.getUrlParam('start') + '&end=' + scope.getUrlParam('end') + '&ids=' + scope.getUrlParam('ids') + '&selected=' + scope.getUrlParam('selected') + '&currentId=' + scope.selectedDataId;
	
			var priority = null;
			try{
				// Get priority for color
				priority = (scope.getUrlParam('selected').indexOf('discussions') > -1) ? 'discussions' : '';
				priority += (scope.getUrlParam('selected').indexOf('appeals') > -1) ? 'appeals' : '';
			}catch(ex){}
			
			var url = jsBaseUrl + "/api/focus.php?type=item_details&item_id="+scope.selectedDataId+"&priority="+priority+"&output=json&json_wrapper=?";
			debugg('Opens infobox: ' + url);
			$.getJSON(url, scope.loadPointDataComplete);
		}catch(ex){ if(debug) alert("Method getPointData \nName: " + ex.name + "\nMessage: " + ex.message + "\nNumber: " + ex.number + "\nDescription: " + ex.description); }
	}
	this.fwindowClose = function() {
		window.location.hash='start=' + scope.getUrlParam('start') + '&end=' + scope.getUrlParam('end') + '&ids=' + scope.getUrlParam('ids') + '&selected=' + scope.getUrlParam('selected');
	}

	
	
	// --- Class method: setupInfoBox -----------------------------------------
	this.setupInfoBox = function (json)
	{
		try{
			$("#FWindowcontent").empty();
			var clone = $("#infoBoxOriginal").clone().attr("id","").addClass('infoBox');
			$("#FWindowcontent").append(clone).show();
			
			$("#FWindowcontent").find(".infoBoxHeadline").addClass('color_' + json.rssc.item.color).html(json.rssc.item.title);
			$("#FWindowcontent").find(".infoBoxPostedOn").html(json.rssc.item.pubDate);
			$("#FWindowcontent").find(".infoBoxBloggContent").html(json.rssc.item.content);
			if(json.rssc.item.link != undefined) {
				$("#FWindowcontent").find(".readMore").addClass('color_' + json.rssc.item.color).attr("href",json.rssc.item.link).attr("target","_blank").show();
				$("#FWindowcontent").find(".infoBoxHeadline").attr("href",json.rssc.item.link).attr("target","_blank").show();
			}
			else {
				$("#FWindowcontent").find(".readMore").hide();	
			}
			var stickers = '';
			var id = json.rssc.item.author['@attributes'].id;
			var name = json.rssc.item.author['@attributes'].text;
			var ids = {};
			ids["_" + id] = true;
			if(name != "")
				stickers += '<div class="sticker"><a type="text" href="#" onclick="mapmanager.addSticker('+id+');return false;"><span class="label">'+name+'</span></a></div>';
			for(var i = 0; i < json.rssc.item.stickers.sticker.length; i++) {
				name = json.rssc.item.stickers.sticker[i]['@attributes'].name;
				id = json.rssc.item.stickers.sticker[i]['@attributes'].id;
				if (!ids["_" + id]) {
					stickers += '<div class="sticker"><a type="text" href="#" onclick="mapmanager.addSticker('+id+');return false;"><span class="label">'+name+'</span></a></div>';
				}
			}
			$("#FWindowcontent").find(".infoBoxStickers").empty().html(stickers);
			$("#FWindowcontent").find(".infoBoxCurrentUrl").val(window.location);
			debugg('infoBox Color: ' +json.rssc.item.color);
			if(json.rssc.item.color == '') {
				json.rssc.item.color = '0xb7b494';
			}
			$("#FWindowcontent").find(".InfoBoxColor").removeClass("InfoBoxColor").addClass('color_' + json.rssc.item.color);
	
			scope.initInfoBox();
		
			infoBoxCufon('#mapHolder');
			mapmanager.unblock();		
			scope.updateInfoBoxLeftScrollPane();		
			
			scope.loadDiscussion(json.rssc.item["@attributes"].id);
			
			DD_belatedPNG.fix('#FWindowcontent .mainBg, #FWindowcontent .rightBg, #FWindowcontent .small-close-btn, #FWindowcontent .icon');
			DD_belatedPNG.fix('#FWindowcontent .hr');
			DD_belatedPNG.fix('#FWindowcontent .jScrollPaneDrag');
			
		}catch(ex){ if(debug) alert("Method setupInfoBox \nName: " + ex.name + "\nMessage: " + ex.message + "\nNumber: " + ex.number + "\nDescription: " + ex.description); }
	}
	
	this.loadDiscussion = function(bloggId) {
		try{
			$("#FWindowcontent").find("input[name=item_id]").val(bloggId);
			var discussUrl = jsBaseUrl + "/api/focus.php?type=item_discussion&item_id=" + bloggId + 
			'&output=json&json_wrapper=?';
			
			debugg('Loading discussion: ' + discussUrl);
			$.getJSON(discussUrl, scope.loadDiscussionComplete);
			$('#FWindowcontent .infoBox .boxRightContent .discussContent').html('<p>Loading...</p>');
		}catch(ex){ if(debug) alert("Method loadDiscussion \nName: " + ex.name + "\nMessage: " + ex.message + "\nNumber: " + ex.number + "\nDescription: " + ex.description); }
		
	}
	/***
	 * loadDiscussionComplete
	 */
	this.loadDiscussionComplete = function(json)
	{
		try{
			$("#FWindowcontent .boxRightContent .discussContent").empty();
			if(json.rssc == undefined) {
				$("#FWindowcontent .boxRightContent .discussContent").html('<p>No comments yet, be the first that comments.</p>');
				return;	
			}
			else {
				var html = '';
				var discussions = json.rssc.item;
				if(discussions.length == undefined){
					discussions = [discussions];
				}
				for(var i = 0; i < discussions.length; i++) {
					var id = discussions[i].id;
					var pubDate = discussions[i].pubDate;
					var postedBy = discussions[i].postedBy;
					var content = discussions[i].content;
					
					html += '<p>' + content +'</p><br />' +
					'<p>Post #' + (discussions.length-i) + ' ('+ (discussions.length) + ') - ' + postedBy + '</p>' +
					'<img src="'+mapPluginUri+'/_images/infoBox/alphaHR.png" alt="hr" class="hr" />';
				}
				
				$("#FWindowcontent .boxRightContent .discussContent").html(html);
			}
			scope.updateInfoBoxRightScrollPane();
			$('.jScrollPaneContainer').css('width', '245px').css("height", '381px');
		}catch(ex){ if(debug) alert("Method loadDiscussionComplete \nName: " + ex.name + "\nMessage: " + ex.message + "\nNumber: " + ex.number + "\nDescription: " + ex.description); }
	}
	
	
	
	this.searchParams = {start:'', end:'', ids:'', selected:''};
	this.pageParams = {};
	/**
	 * called everytime anchor link changes
	 */
	this.anchorCallback = function (hash) {
		try{
			hash = hash.replace("#", "");
			
			//var prevLink = $('#main_menu a[title=Map view]').attr('href');
			
			$('#main_menu a[title=Map view]').unbind("click").click(function () { 
				window.location.href = $('#main_menu a[title=Map view]').attr('href')+"#"+hash;
				return false;
			});
			$('#main_menu a[title=List view]').unbind("click").click(function () { 
				window.location.href = $('#main_menu a[title=List view]').attr('href')+"#"+hash;
				return false;
			});
	
			
			
			//$('#main_menu a[title=Map view]').attr('href', 'http://google.se');
			scope.pageParams = {};
			var hasChanged = false;
			//gmap.setCenter(59.33231386546924, 18.064441680908203, 4);
			var arrParams = hash.split('&');
			for(var i = 0; i < arrParams.length; i++){
				if(arrParams[i] != "") {
					var oneParam = arrParams[i].split('=');
					var name = oneParam[0];
					var val = oneParam[1];
					scope.pageParams[name] = val;
					if(scope.searchParams[name] != undefined && scope.searchParams[name] != val) {
						scope.searchParams[name] = val;
						hasChanged = true;
					}
					if(name=='currentId') {
						scope.selectedDataId = val;
					}
				}
			}
			if(hasChanged) {
				
				try {
					//panel().refreshFlashPanel();
				}
				catch(e){}
				
				var url = jsBaseUrl + "/api/search.php?type=vis&start="+scope.searchParams.start+"&end="+scope.searchParams.end+"&ids="+scope.searchParams.ids+"&selected="+scope.searchParams.selected+"&output=json&json_wrapper=?";
				
				debugg("Has changed, loading URL: " + url);
				
				scope.loadXmlPoints(url);
				scope.block();
			}
		}catch(ex){ if(debug) alert("Method anchorCallback \nName: " + ex.name + "\nMessage: " + ex.message + "\nNumber: " + ex.number + "\nDescription: " + ex.description); }
	}
	
	this.getHash = function() {
		return window.location.hash;
	}
	
	this.getUrlParam = function(paramName) {
		try{
			if(paramName == null) {
				return scope.pageParams;
			}
			return scope.pageParams[paramName];
		}catch(ex){ if(debug) alert("Method getUrlParam \nName: " + ex.name + "\nMessage: " + ex.message + "\nNumber: " + ex.number + "\nDescription: " + ex.description); }
	}
	
	this.addSticker = function(stickerId) {
		panel().addStickerToFlashPanel(stickerId);
	}


	
	
	
	this.initInfoBox = function() {
		
		initDiscussForm();
		initShareForm();
		$('#FWindowcontent .newDiscussPost').click(function () { 
			$('.infoBox .boxRightContent .discussForm').show();
			$('.infoBox .boxRightContent .discuss').hide();
			if(!isLoggedIn) { 
			    $('.ajaxOutput').html('<div class="error">You must login to post comments.</div>');
			    $('.ajaxOutput').show();
			}
			return false;
		});
		
		$('#FWindowcontent .infoBox ul.tabs li a').click(function () {
			try{
				var anyOpen = false;
				var thisIsOpen = $(this).parent().hasClass("open");
				$('#FWindowcontent .infoBox ul.tabs li a').each(function () {
					if( $(this).parent().hasClass("open") ) {
						anyOpen = true;
						$(this).parent().removeClass("open");
					}
				});
				
				$(this).parent().addClass("open");
			
				if(!anyOpen) {
					openInfoBox();
				}
				else if(thisIsOpen){
					$(this).parent().removeClass("open");
					closeInfoBox();
				}
				
				//$('#FWindowcontent .infoBox .boxRightContent .save').hide();
				$('#FWindowcontent .infoBox .boxRightContent .discuss').hide();
				$('#FWindowcontent .infoBox .boxRightContent .share').hide();
				
				if($(this).hasClass("save") && $(this).parent().hasClass("open")){
					//$('#FWindowcontent .infoBox .boxRightContent .save').show();
				}
				if($(this).hasClass("discuss") && $(this).parent().hasClass("open")){
					$('#FWindowcontent .infoBox .boxRightContent .discuss').show();
					$('#FWindowcontent .infoBox .boxRightContent .discussForm').hide();
				}
				if($(this).hasClass("share") && $(this).parent().hasClass("open")){
					$('#FWindowcontent .infoBox .boxRightContent .share').show();
					$('#FWindowcontent .infoBox .boxRightContent .discussForm').hide();
				}
				
				scope.updateInfoBoxRightScrollPane();
				
				
				return false;
			}catch(ex){ if(debug) alert("Method initInfoBox \nName: " + ex.name + "\nMessage: " + ex.message + "\nNumber: " + ex.number + "\nDescription: " + ex.description); }
		});
		
		$('#FWindowcontent .infoBox .boxRightContent .close').click(function () {
			closeInfoBox();
			$('#FWindowcontent .infoBox .boxRightContent .discuss').hide();
			$('#FWindowcontent .infoBox .boxRightContent .share').hide();
			return false;
		});
		
		function closeInfoBox() {
			try{
				$('#FWindowcontent .infoBox ul.tabs li a').each(function () {
					$(this).parent().removeClass("open");
				});
				
				$('#FWindowcontent .infoBox .rightBg').removeClass('rightBgMaximized');
				$('#FWindowcontent .infoBox .mainBg').animate({width:"278px"},200);
			}catch(ex){ if(debug) alert("Method closeInfoBox \nName: " + ex.name + "\nMessage: " + ex.message + "\nNumber: " + ex.number + "\nDescription: " + ex.description); }
		}
		function openInfoBox() {
			try{
				$('#FWindowcontent .infoBox .rightBg').addClass('rightBgMaximized');
				$('#FWindowcontent .infoBox .mainBg').animate({width:"543px"},400);
			}catch(ex){ if(debug) alert("Method openInfoBox \nName: " + ex.name + "\nMessage: " + ex.message + "\nNumber: " + ex.number + "\nDescription: " + ex.description); }
		}
		
		
		

	}
	this.updateInfoBoxRightScrollPane = function() {
		try{
			$('#FWindowcontent .infoBox .boxRightContent .scroll-pane').jScrollPane({
				scrollbarWidth:23,	//the width of the generated scrollbar in pixels
				scrollbarMargin:3,	//the amount of space to leave on the side of the scrollbar in pixels
				//wheelSpeed:xxx,	//The speed the pane will scroll in response to the mouse wheel in pixels
				showArrows:false,	//Whether to display arrows for the user to scroll with
				//arrowSize:20,		//The height of the arrow buttons if showArrows=true
				//animateTo		-	//Whether to animate when calling scrollTo and scrollBy
				dragMinHeight:45,	//The minimum height to allow the drag bar to be
				dragMaxHeight:45,	//The maximum height to allow the drag bar to be
				animateInterval:100,//The interval in milliseconds to update an animating scrollPane (default 100)
				animateStep:5,		//The amount to divide the remaining scroll distance by when animating (default 3)
				maintainPosition:true, //Whether you want the contents of the scroll pane to maintain it's position when you re-initialise it - so it doesn't scroll as you add more content (default true)
				scrollbarOnLeft:false, //Display the scrollbar on the left side?  (needs stylesheet changes, see examples.html)
				reinitialiseOnImageLoad:true // - Whether the jScrollPane should automatically re-initialise itself when any contained images are loaded
			});
			$('.jScrollPaneContainer').css('width', '245px').css("height", '381px'); //stupid html, should net be needed
		}catch(ex){ if(debug) alert("Method updateInfoBoxRightScrollPane \nName: " + ex.name + "\nMessage: " + ex.message + "\nNumber: " + ex.number + "\nDescription: " + ex.description); }
	}
	
	this.updateInfoBoxLeftScrollPane = function() {
		try{
			$('#FWindowcontent .infoBox .boxLeftContent .scroll-pane').jScrollPane({
				scrollbarWidth:23,	//the width of the generated scrollbar in pixels
				scrollbarMargin:3,	//the amount of space to leave on the side of the scrollbar in pixels
				//wheelSpeed:xxx,	//The speed the pane will scroll in response to the mouse wheel in pixels
				showArrows:false,	//Whether to display arrows for the user to scroll with
				//arrowSize:20,		//The height of the arrow buttons if showArrows=true
				//animateTo		-	//Whether to animate when calling scrollTo and scrollBy
				dragMinHeight:45,	//The minimum height to allow the drag bar to be
				dragMaxHeight:45,	//The maximum height to allow the drag bar to be
				animateInterval:100,//The interval in milliseconds to update an animating scrollPane (default 100)
				animateStep:5,		//The amount to divide the remaining scroll distance by when animating (default 3)
				maintainPosition:true, //Whether you want the contents of the scroll pane to maintain it's position when you re-initialise it - so it doesn't scroll as you add more content (default true)
				scrollbarOnLeft:false, //Display the scrollbar on the left side?  (needs stylesheet changes, see examples.html)
				reinitialiseOnImageLoad:true // - Whether the jScrollPane should automatically re-initialise itself when any contained images are loaded
			});
			$('.jScrollPaneContainer').css('width', '245px').css("height", '381px'); //stupid html, should net be needed
		}catch(ex){ if(debug) alert("Method updateInfoBoxLeftScrollPane \nName: " + ex.name + "\nMessage: " + ex.message + "\nNumber: " + ex.number + "\nDescription: " + ex.description); }
	}
	
	
	this.block = function(){  
		try{
			$('#map').block({ 
				message: $('#displayBox'),  
				css: { 
					border: '0px none', 
					background: 'transparent' 
				},
				fadeOut:10
			});
		}catch(ex){ if(debug) alert("Method block \nName: " + ex.name + "\nMessage: " + ex.message + "\nNumber: " + ex.number + "\nDescription: " + ex.description); }
	}
	
	this.unblock = function(){     
		$('#map').unblock();
	}	
	this._updateNrOfStories = function(nrOf){
		try{
			setTimeout(function(){
				panel().setNrOfStories(nrOf);
			}, 200);
		}catch(ex){ /* Error on init */ }
	};
}

//////////////////////////////////////////
// Run mapmanager when map loaded
//////////////////////////////////////////

try {
	google.load("maps", "2");
	google.setOnLoadCallback(mapmanager.init);
}
catch(err)
{
	txt = "There was an error on this page.\n\n";
	txt += err;
	if(debug) {
		//alert(txt);
	}
}
