var broken = Class.create();
broken.googleMaps = Class.create();
broken.googleMaps.core =
{

	isInitialized: false,
	lastPOIZIndex: 0,
	lastImportance: 0,

	/* 
	function broken.googleMaps.core.initialize
	*/
	initialize: function(target, lat, lng, zoom) {
		var currentLat = broken.visitSite.map.getPositionCookie('currentLat');
		var currentLng = broken.visitSite.map.getPositionCookie('currentLng');
		var currentZoom = broken.visitSite.map.getPositionCookie('currentZoom');

		this.orgLat = lat;
		this.orgLng = lng;
		this.orgZoom = zoom;

		var completedZoom = 0;
		var compledZoomToAcc = 0;

		this.lat = (currentLat == "" || currentLat == null) ? lat : currentLat;
		this.lng = (currentLng == "" || currentLng == null) ? lng : currentLng;
		this.zoom = currentZoom == null ? zoom : parseInt(currentZoom);

		this.currentPoiMarker = false;

		if (GBrowserIsCompatible() && $(target)) {

			this.map = new GMap2($(target));

			GEvent.addListener(this.map, 'load', function() {
				if ((broken.visitSite.map.isSmallMap || broken.visitSite.map.isRegularMap) && $('HiddenPageID')) {
					if (broken.visitSite.page.mapOpenState == 'true')
						broken.visitSite.map.configHandle();
					broken.visitSite.map.loadPageMapData();
				}
				if (broken.visitSite.map.isCoordinatePickerMap) {
					broken.visitSite.map.configHandle();
					broken.visitSite.map.loadPageMapData();
					broken.visitSite.map.addPickerMarker();
				}

				if (broken.visitSite.map.isSearchMap) {
					broken.visitSite.map.configHandle();
					broken.visitSite.map.loadSearchMapData();
				}
			});

			this.map.setCenter(new GLatLng(parseFloat(this.lat), parseFloat(this.lng)), this.zoom);
			this.map.addControl(new GOverviewMapControl());



			var isInitialized = false;
			var isZoomed = false;

			GEvent.addListener(this.map, 'zoomend', function(oldLevel, newLevel) {

				//a boolean to prevent unnessecary placemarker call
				var fire = true;
				if (isZoomed) {

					isInitialized = true;
				}
				else {
					fire = false;
					isZoomed = true;
				}
				broken.visitSite.map.slider.setValue(broken.visitSite.map.map.getZoom());

				//				if (!$('staticWrapper')) {
				//					broken.visitSite.map.unloadPoi();
				//}

				if (fire) {
					//console.log("zoomend");
					broken.visitSite.map.placeMarkers();
				}
			});

			GEvent.addListener(this.map, 'moveend', function() {

				if (!broken.visitSite.map.isSearchMap) {

					if (isInitialized || !isZoomed) {

						var latLng = broken.visitSite.map.map.getCenter();
						var bounds = broken.visitSite.map.map.getBounds();
						var mapzoom = broken.visitSite.map.map.getZoom();
						var expandedBounds = broken.visitSite.map.expandBounds(bounds, mapzoom);
						broken.visitSite.map.loadDynamicMapData(expandedBounds, mapzoom);
					} else {
						isInitialized = true;
					}
					if (typeof broken.visitSite.map.currentPoiMarker != 'boolean') {
						// fortfarande problem med anchor på icon.
						//console.log("moveend");
						broken.visitSite.map.placeMarkers();
					}
				}
			});

			_this = this;

			this.markerAdded = false;
			this.activeMarkersOld = {};
			this.mm = new MarkerManager(this.map);
			this.mmCollection = {};
			this.activeMarkers = {};

			//This variable is used to only zoom to the area ONCE
			this.isZoomed = false;
		}
	},

	/* 
	function broken.googleMaps.core.expandBounds
	*/
	expandBounds: function(bounds, zoom) {
		var _latNE = bounds.getNorthEast().lat();
		var _lngNE = bounds.getNorthEast().lng();
		var _latSW = bounds.getSouthWest().lat();
		var _lngSW = bounds.getSouthWest().lng();

		var _latAddon = 0.05;
		var _lngAddon = 0.05;

		var _bounds = {
			latNE: parseFloat(_latNE + ((_latNE - _latSW) * (zoom * _latAddon))),
			lngNE: parseFloat(_lngNE + ((_lngNE - _lngSW) * (zoom * _lngAddon))),
			latSW: parseFloat(_latSW - ((_latNE - _latSW) * (zoom * _latAddon))),
			lngSW: parseFloat(_lngSW - ((_lngNE - _lngSW) * (zoom * _lngAddon)))
		}

		return new GLatLngBounds(new GLatLng(_bounds.latSW, _bounds.lngSW), new GLatLng(_bounds.latNE, _bounds.lngNE));
	},

	/* 
	function broken.googleMaps.core.changeZoom
	*/
	changeZoom: function(way) {
		if (way == 'in')
			this.map.zoomIn();
		else
			this.map.zoomOut();
	},

	/* 
	function broken.googleMaps.core.changeMapType
	*/
	changeMapType: function(type, sender) {
		$$('.mapType .map')[0].removeClassName('active0');
		$$('.mapType .satellite')[0].removeClassName('active1');
		$$('.mapType .terrain')[0].removeClassName('active2');

		if (type == 'n') {
			this.map.setMapType(G_NORMAL_MAP);
			$(sender).addClassName('active0');
		} else if (type == 's') {
			this.map.setMapType(G_SATELLITE_MAP);
			$(sender).addClassName('active1');
		} else if (type == 't') {
			this.map.setMapType(G_PHYSICAL_MAP);
			$(sender).addClassName('active2');
		}
	},

	/* 
	function broken.googleMaps.core.changePoiType
	*/
	changePoiType: function(sender, classId, typeId) {
		if ($(sender).hasClassName('active' + classId)) {
			sender.removeClassName('active' + classId);
			if (broken.util.isIE6)
				sender.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/ui/images/map.category.icon.inactive.png', sizingMethod='crop')";

			if (typeId == '10') {
				($('yrUrl')).hide();
			}
			broken.visitSite.map.mapDataTypes[typeId] = 'false';
		} else {
			sender.addClassName('active' + classId);

			if (broken.util.isIE6)
				sender.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/ui/images/map.category.icon.active." + classId + ".png', sizingMethod='crop')";
			if (typeId == '10') {
				($('yrUrl')).show();
			}
			broken.visitSite.map.mapDataTypes[typeId] = 'true';
		}

		this.getMarkers(true);
	},

	/* 
	function broken.googleMaps.core.resetZoom
	*/
	resetZoom: function() {
		this.map.setCenter(new GLatLng(this.orgLat, this.orgLng), this.orgZoom);
		if (typeof broken.visitSite.map.placeMarkers != 'undefined')
			broken.visitSite.map.placeMarkers();
	},

	/* 
	function broken.googleMaps.core.importanceOrder
	*/
	importanceOrder: function(marker, b) {
		return GOverlay.getZIndex(marker.getPoint().lat()) + marker.importance * 1000000;
	},

	/* 
	function broken.googleMaps.core.createMarker
	*/
	createMarker: function(position, icon, opt, isDrag, isClickable, label, show) {

		var markerIcon = new GIcon();
		markerIcon.iconSize = new GSize(icon.sw, icon.sh);
		markerIcon.iconAnchor = new GPoint(icon.ax, icon.ay);
		markerIcon.image = icon.image;
		var point = new GLatLng(position.lat, position.lng);

		if (show) {
			opts = {
				"icon": markerIcon,
				"clickable": true,
				"labelText": show ? label + "&deg;" : "",
				"labelOffset": new GSize(5, -29),
				"draggable": isDrag,
				"zIndexProcess": this.importanceOrder
			}
			var marker = new LabeledMarker(point, opts);
		}
		else if (!isClickable) { //This is a photomarker
			opts = {
				"icon": markerIcon,
				"clickable": isClickable,
				"draggable": isDrag,
				"zIndexProcess": this.importanceOrder
			}

			var marker = new GMarker(point, opts);
		}
		else {
			opts = {
				"icon": markerIcon,
				"clickable": isClickable,
				"draggable": isDrag
			}
			var marker = new GMarker(point, opts);
		}

		for (var i in opt) {
			marker[i] = opt[i];
		}
		return marker;
	},

	/* 
	function broken.googleMaps.core.addMarkers
	Function used to add markers to the map. 
	*/
	addMarkers: function() {
		//console.log("addMarkers()");
		/* Itterate through the JSON object. */
		for (var j in this.mapDataJSON) {
			/* Check if the marker isnt already included in the array */
			if (typeof this.mapDataJSON[j].marker == 'undefined') {
				/* Make a instance of the current JSON object */
				var m = this.mapDataJSON[j];
				/* Declare and populate the categories */
				var categories = m.categories.split(',');
				/* Declare the current zoom level, if not set, use default (0). */
				var _zoomToLevel = (typeof m.zoomToLevel == 'undefined' || m.zoomToLevel == 'undefined' ? '0' : m.zoomToLevel);
				/* Declare and populate the point. */
				var p = { lat: m.lat, lng: m.lng };

				/* Handle the vaious types  */
				switch (m.typeId) {
					/* The type is normal POI-Article */ 
					case "1":
						/* Handle the tilt. */
						switch (m.tilt) {
							/* The POI's tilt is to the left */ 
							case "1":
								/* Declare and populate the icon-image. Take notice of any zoom-level exceptions. */
								var _poiImage = (parseInt(_zoomToLevel) > 0 && this.map.getZoom() < _zoomToLevel ? '/UI/Images/googlemaps/p.zoomtoarea.png' : '/UI/Images/googlemaps/p.38.left.png');
								/* Declare and populate the icon. */
								var ic = (parseInt(m.zoomToLevel) > 0 && this.map.getZoom() < m.zoomToLevel ? { sh: 40, sw: 26, ax: 13, ay: 35, image: _poiImage} : { sh: 40, sw: 26, ax: 0, ay: 35, image: _poiImage });
								/* Exit the case. */
								break;
							/* The POI's tilt is to the right */ 
							case "2":
								/* Declare and populate the icon-image. Take notice of any zoom-level exceptions. */
								var _poiImage = (parseInt(_zoomToLevel) > 0 && this.map.getZoom() < _zoomToLevel ? '/UI/Images/googlemaps/p.zoomtoarea.png' : '/UI/Images/googlemaps/p.38.right.png');
								/* Declare and populate the icon. */
								var ic = (parseInt(m.zoomToLevel) > 0 && this.map.getZoom() < m.zoomToLevel ? { sh: 40, sw: 26, ax: 13, ay: 35, image: _poiImage} : { sh: 40, sw: 26, ax: 26, ay: 35, image: _poiImage });
								/* Exit the case. */
								break;
							/* The POI's doesn't have any tilt. */ 
							default:
								/* Declare and populate the icon-image. Take notice of any zoom-level exceptions. */
								var _poiImage = (parseInt(_zoomToLevel) > 0 && this.map.getZoom() < _zoomToLevel ? '/UI/Images/googlemaps/p.zoomtoarea.png' : '/UI/Images/googlemaps/p.38.png');
								/* Declare and populate the icon. */
								var ic = { sh: 40, sw: 26, ax: 13, ay: 35, image: _poiImage };
								/* Exit the case. */
								break;
						}
						/* Exit the case. */
						break;
					/* The type is a Mini POI */ 
					case "2":
						/* Declare and populate the icon-image. */
						var _poiImage = '/UI/Images/googlemaps/p.mini.png';
						/* Declare and populate the icon. */
						var ic = { sh: 26, sw: 18, ax: 8, ay: 28, image: _poiImage };
						/* Exit the case. */
						break;
					/* The type is a Group POI*/ 
					case "3":
						/* Declare and populate the icon-image. */
						var _poiImage = '/UI/Images/googlemaps/p.big.png';
						/* Declare and populate the icon. */
						var ic = { sh: 52, sw: 38, ax: 20, ay: 48, image: _poiImage };
						/* Exit the case. */
						break;
					/* The type is a transportation POI */ 
					case "4":
						/* Declare and populate the icon-image. */
						var _poiImage = '/UI/Images/googlemaps/p.transportation.png';
						/* Declare and populate the icon. */
						var ic = { sh: 26, sw: 18, ax: 8, ay: 28, image: _poiImage };
						/* Exit the case. */
						break;
					/* The type is a accomodation POI */ 
					case "6":
						/* Declare and populate the icon-image. */
						var _poiImage = '/UI/Images/googlemaps/p.acc.png';
						/* Declare and populate the icon. */
						var ic = { sh: 26, sw: 18, ax: 8, ay: 28, image: _poiImage };
						/* Exit the case. */

						break;
					/*The type is an accommodation group poi*/ 
					case "8":
						var _poiImage = '/UI/Images/googlemaps/p.accg.png';
						var ic = { sh: 40, sw: 26, ax: 14, ay: 35, image: _poiImage };
						//var ic = { sh: 40, sw: 26, ax: 26, ay: 35, image: _poiImage };
						break;
					/*START Alex tillägg*/ 
					case "10":
						/* Handle the Weathericons */
						switch (m.icon) {
							case "1":
								/* Declare and populate the icon-image. Take notice of any zoom-level exceptions. */
								var _poiImage = '/UI/Images/weather/weatherpoi_1.png';
								/* Declare and populate the icon. */
								var ic = { sh: 41, sw: 58, ax: 13, ay: 35, image: _poiImage };
								/* Exit the case. */
								break;
							case "2":
								/* Declare and populate the icon-image. Take notice of any zoom-level exceptions. */
								var _poiImage = '/UI/Images/weather/weatherpoi_2.png';
								/* Declare and populate the icon. */
								var ic = { sh: 41, sw: 58, ax: 13, ay: 35, image: _poiImage };
								/* Exit the case. */
								break;
							case "3":
								/* Declare and populate the icon-image. Take notice of any zoom-level exceptions. */
								var _poiImage = '/UI/Images/weather/weatherpoi_3.png';
								/* Declare and populate the icon. */
								var ic = { sh: 41, sw: 58, ax: 13, ay: 35, image: _poiImage };
								/* Exit the case. */
								break;
							case "4":
								/* Declare and populate the icon-image. Take notice of any zoom-level exceptions. */
								var _poiImage = '/UI/Images/weather/weatherpoi_4_15.png';
								/* Declare and populate the icon. */
								var ic = { sh: 41, sw: 58, ax: 13, ay: 35, image: _poiImage };
								/* Exit the case. */
								break;
							case "5":
								/* Declare and populate the icon-image. Take notice of any zoom-level exceptions. */
								var _poiImage = '/UI/Images/weather/weatherpoi_5_7_8.png';
								/* Declare and populate the icon. */
								var ic = { sh: 41, sw: 58, ax: 13, ay: 35, image: _poiImage };
								/* Exit the case. */
								break;
							case "6":
								/* Declare and populate the icon-image. Take notice of any zoom-level exceptions. */
								var _poiImage = '/UI/Images/weather/weatherpoi_6_11_14.png';
								/* Declare and populate the icon. */
								var ic = { sh: 41, sw: 58, ax: 13, ay: 35, image: _poiImage };
								/* Exit the case. */
								break;
							case "7":
								/* Declare and populate the icon-image. Take notice of any zoom-level exceptions. */
								var _poiImage = '/UI/Images/weather/weatherpoi_5_7_8.png';
								/* Declare and populate the icon. */
								var ic = { sh: 41, sw: 58, ax: 13, ay: 35, image: _poiImage };
								/* Exit the case. */
								break;
							case "8":
								/* Declare and populate the icon-image. Take notice of any zoom-level exceptions. */
								var _poiImage = '/UI/Images/weather/weatherpoi_5_7_8.png';
								/* Declare and populate the icon. */
								var ic = { sh: 41, sw: 58, ax: 13, ay: 35, image: _poiImage };
								/* Exit the case. */
								break;
							case "9":
								/* Declare and populate the icon-image. Take notice of any zoom-level exceptions. */
								var _poiImage = '/UI/Images/weather/weatherpoi_9_10.png';
								/* Declare and populate the icon. */
								var ic = { sh: 41, sw: 58, ax: 13, ay: 35, image: _poiImage };
								/* Exit the case. */
								break;
							case "10":
								/* Declare and populate the icon-image. Take notice of any zoom-level exceptions. */
								var _poiImage = '/UI/Images/weather/weatherpoi_9_10.png';
								/* Declare and populate the icon. */
								var ic = { sh: 41, sw: 58, ax: 13, ay: 35, image: _poiImage };
								/* Exit the case. */
								break;
							case "11":
								/* Declare and populate the icon-image. Take notice of any zoom-level exceptions. */
								var _poiImage = '/UI/Images/weather/weatherpoi_6_11_14.png';
								/* Declare and populate the icon. */
								var ic = { sh: 41, sw: 58, ax: 13, ay: 35, image: _poiImage };
								/* Exit the case. */
								break;
							case "12":
								/* Declare and populate the icon-image. Take notice of any zoom-level exceptions. */
								var _poiImage = '/UI/Images/weather/weatherpoi_13_12.png';
								/* Declare and populate the icon. */
								var ic = { sh: 41, sw: 58, ax: 13, ay: 35, image: _poiImage };
								/* Exit the case. */
								break;
							case "13":
								/* Declare and populate the icon-image. Take notice of any zoom-level exceptions. */
								var _poiImage = '/UI/Images/weather/weatherpoi_13_12.png';
								/* Declare and populate the icon. */
								var ic = { sh: 41, sw: 58, ax: 13, ay: 35, image: _poiImage };
								/* Exit the case. */
								break;
							case "14":
								/* Declare and populate the icon-image. Take notice of any zoom-level exceptions. */
								var _poiImage = '/UI/Images/weather/weatherpoi_6_11_14.png';
								/* Declare and populate the icon. */
								var ic = { sh: 41, sw: 58, ax: 13, ay: 35, image: _poiImage };
								/* Exit the case. */
								break;
							case "15":
								/* Declare and populate the icon-image. Take notice of any zoom-level exceptions. */
								var _poiImage = '/UI/Images/weather/weatherpoi_4_15.png';
								/* Declare and populate the icon. */
								var ic = { sh: 41, sw: 58, ax: 13, ay: 35, image: _poiImage };
								/* Exit the case. */
								break;
							/*END Alex tillägg*/ 
						}

						/* Exit the case. */
						break;

				}

				/* Desclate and populate the options-array. */
				var o = {
					/* Latitude. */
					lat: m.lat,
					/* Longitude. */
					lng: m.lng,
					/* Importance, take notice of the type and zoomLevel. */
					importance: (m.typeId == "6" ? 15 : (m.typeId == "8" ? 15 : (m.typeId == "3" ? 15 : (m.typeId == "4" ? 15 : (parseInt(_zoomToLevel) > 0) ? 5 : 5)))),
					/* Region id - geographical. */
					regionId: m.regionId,
					/* Coord Id - usually the EPi-PageID.  */
					coordId: m.coordId,
					/* Name of the POI, with trimmed whitespaces. */
					name: broken.util.trim(m.name),
					/* PageId = EPi.PageID */
					pageId: m.id,
					/* Maximum Zoom, default value if not set. */
					maz: (m.maxZoom > 0 ? m.maxZoom : 17),
					/* Minimum Zoom, default value if not set. */
					mz: (m.minZoom > 0 ? m.minZoom : 4),
					/* CategoryId, the first category in the array. */
					categoryId: categories[0],
					/* Categories, all categories. */
					categories: categories,
					/* Id, a unique id, build it. */
					id: 'm' + m.id + '_' + m.typeId,
					/* TypeId: 1=normal, 2=mini, 3=group, 4=transportation, Accomodation = 6, AccommodationGroup = 8  */
					typeId: m.typeId,
					/* Tilt: 1=left, 2=right, 3=none. */
					tilt: m.tilt,
					/* The elvel to zoom to when clicked. */
					zoomToLevel: _zoomToLevel
				};

				/* Declare and populate the marker. */

				var marker = this.createMarker(p, ic, o, false, true, m.temp, m.typeId == "10");

				/* Handle the markers click-event. */
				GEvent.addListener(marker, 'click', function() {
					/* Check if the current map is backend-EPI. */
					if (broken.visitSite.map.isCoordinatePickerMap) {
						/* Handle the type. */
						switch (this.typeId) {
							/* The type is a Group POI*/ 
							case "3":
								/* Unload all active POIs */
								broken.visitSite.map.unloadPoi();
								/* Move and zoom to point and zoom-level. */
								broken.visitSite.map.gotoPoint(this.lat, this.lng, parseInt(this.zoomToLevel));
								/* Exit the case. */
								break;
						}
					}
					else {
						/* Check if the map has a photomarker lit.  */
						if (broken.visitSite.map.photoMarker != null) {
							/* Remove the photomarker. */
							broken.visitSite.map.photoMarker = null;
						}
						/* Check if a marker already is active on the map. */
						if (broken.visitSite.map.currentPoiMarker != false) {
							/* Unload the marker. */
							broken.visitSite.map.unloadPoiKeepWidget();
						}

						/* Make a instance of the map */
						var m = broken.visitSite.map.map;
						/* Declare and populate the current zoom of the map. */
						var zoom = m.getZoom();

						/* Find the pixel of the current projection. */
						var pixels = m.getCurrentMapType().getProjection().fromLatLngToPixel(new GLatLng(this.lat, this.lng), zoom);

						/* Handle the type. */
						switch (this.typeId) {
							/* The type is normal POI-Article */ 
							case "1":
								/* Handle the tilt. */
								switch (this.tilt) {
									/* The POI's tilt is to the left */ 
									case "1":
										/* Activate the icon-image, take notice of the zoom-level. */
										this.setImage(parseInt(this.zoomToLevel) > 0 && broken.visitSite.map.map.getZoom() < this.zoomToLevel ? '/UI/Images/googlemaps/p.a.zoomtoarea.png' : (parseInt(this.zoomToLevel) > 0 ? '/UI/Images/googlemaps/p.a.png' : '/UI/Images/googlemaps/p.a.left.png'));
										/* Exit the case. */
										break;
									/* The POI's tilt is to the right */ 
									case "2":
										/* Activate the icon-image, take notice of the zoom-level. */
										this.setImage(parseInt(this.zoomToLevel) > 0 && broken.visitSite.map.map.getZoom() < this.zoomToLevel ? '/UI/Images/googlemaps/p.a.zoomtoarea.png' : (parseInt(this.zoomToLevel) > 0 ? '/UI/Images/googlemaps/p.a.png' : '/UI/Images/googlemaps/p.a.right.png'));
										/* Exit the case. */
										break;
									/* The POI's doesn't have any tilt. */ 
									default:
										/* Activate the icon-image, take notice of the zoom-level. */
										this.setImage(parseInt(this.zoomToLevel) > 0 && broken.visitSite.map.map.getZoom() < this.zoomToLevel != "0" ? '/UI/Images/googlemaps/p.a.zoomtoarea.png' : '/UI/Images/googlemaps/p.a.png');
										/* Exit the case. */
										break;
								}
								break;
							/* The type is a Mini POI */ 
							//accommodation                                                                                                     
							//Transportation                                                                                                      
							//poi mini                                                                                                     
							case "6":
							case "4":
							case "2":
								/* Activate the icon-image. */
								this.setImage('/UI/Images/googlemaps/p.mini.a.png');
								/* Exit the case. */
								break;
						}

						/* Make the POI active. */
						this.active = true;

						/* Set the importance of the marker. */
						marker.importance = 4;

						/* Remember the zoom-level. */
						this.lastPOIZIndex = $('mtgt_' + this.id).style.zIndex;
						/* Make the POI appear infront of everything else. */
						//$('mtgt_' + this.id).style.zIndex = '1000000';

						/* Remember this POI as the current. */
						broken.visitSite.map.currentPoiMarker = this;
						/* Remeber the current POI's Id. */
						broken.visitSite.map.currentPageID = $('HiddenPageID').value;
						/* Remember the current language code. */
						broken.visitSite.map.currentEpsLanguageCode = $('HiddenLanguageCode').value;

						/* Itterate through the labels. */
						while ($('poiLabel')) {
							/* Remove the label. */
							$('poiLabel').remove();
						}

						/* Declare and populate the vertical pixel. */
						var _y = pixels.y;
						/* Declare and populate the horisontal pixel. */
						var _x = parseInt(pixels.x - 100);

						/* Handle the type. */
						switch (this.typeId) {
							/* The type is normal POI-Article */ 
							case "1":
								/* Declare and set the point. */
								var point = m.getCurrentMapType().getProjection().fromPixelToLatLng(new GPoint(_x, _y), zoom);
								/* Pan to the point. */
								broken.visitSite.map.map.panTo(new GLatLng(point.lat(), point.lng()));
								/* Load the widget source. */

								broken.visitSite.page.loadWidget('/UI/scripts/widgets/poiArticle.js');
								/* Exit the case. */
								break;
							/* The type is a Mini POI */ 
							case "2":
								/* Update the horisontal variable, this is done since the mini-widget is smaller then the article. */
								_x = (!broken.visitSite.map.isSearchMap) ? parseInt(pixels.x) : parseInt(pixels.x - 120);
								/* Declare and set the point. */
								var point = m.getCurrentMapType().getProjection().fromPixelToLatLng(new GPoint(_x, _y), zoom);
								/* Pan to the point. */
								broken.visitSite.map.map.panTo(new GLatLng(point.lat(), point.lng()));
								/* Load the widget source. */
								broken.visitSite.page.loadWidget('/UI/scripts/widgets/poiLight.js');
								/* Exit the case. */
								break;
							/* The type is a Group POI */ 
							case "8":
							case "3":
								/* Unload the current POI. */

								broken.visitSite.map.unloadPoi();
								/* Move to and zoom into the new location. */
								
								broken.visitSite.map.gotoPoint(this.lat, this.lng, parseInt(this.zoomToLevel));
								
								/* Exit the case. */
								break;
							/* The type is a transportation POI */ 
							case "4":
								/* Update the horisontal variable, this is done since the mini/transportation-widget is smaller then the article. */
								_x = (!broken.visitSite.map.isSearchMap) ? parseInt(pixels.x) : parseInt(pixels.x - 120);
								/* Declare and set the point. */
								var point = m.getCurrentMapType().getProjection().fromPixelToLatLng(new GPoint(_x, _y), zoom);
								/* Pan to the point. */
								broken.visitSite.map.map.panTo(new GLatLng(point.lat(), point.lng()));
								/* Load the widget source. Notice that the transportation POI's share the poiLight source! */
								broken.visitSite.page.loadWidget('/UI/scripts/widgets/poiLight.js');
								/* Exit the case. */
								break;
							/* The type is a booking POI */ 
							case "6":
								/* Update the horisontal variable, this is done since the mini/transportation-widget is smaller then the article. */
								_x = (!broken.visitSite.map.isSearchMap) ? parseInt(pixels.x) : parseInt(pixels.x - 120);
								/* Declare and set the point. */
								var point = m.getCurrentMapType().getProjection().fromPixelToLatLng(new GPoint(_x, _y), zoom);
								/* Pan to the point. */
								broken.visitSite.map.map.panTo(new GLatLng(point.lat(), point.lng()));
								/* Load the widget source. Notice that the transportation POI's share the poiLight source! */
								broken.visitSite.page.loadWidget('/UI/scripts/widgets/PoiAccomodation.js');
								/* Exit the case. */
								break;
							/* The type is a weather POI */ 
							case "10":
								/* Update the horisontal variable, this is done since the mini/transportation-widget is smaller then the article. */
								_x = (!broken.visitSite.map.isSearchMap) ? parseInt(pixels.x) : parseInt(pixels.x - 120);
								/* Declare and set the point. */
								var point = m.getCurrentMapType().getProjection().fromPixelToLatLng(new GPoint(_x, _y), zoom);
								/* Pan to the point. */
								broken.visitSite.map.map.panTo(new GLatLng(point.lat(), point.lng()));
								/* Load the widget source. Notice that the transportation POI's share the poiLight source! */
								broken.visitSite.page.loadWidget('/UI/scripts/widgets/poiWeather.js');
								/* Exit the case. */
								break;
						}
					}
				});
				//Check if type is PoiWeather, no mouseover on PoiWeather
				//if (m.typeId != "10") {
				/* Handle the markers mouseover-event. */
				GEvent.addListener(marker, 'mouseover', function() {
					/* Check if the POI is a normal POI-Article and the current POI is active. */
					/* Update the z-index. */

					if (this.typeId != 10) {
						this.oz = GOverlay.getZIndex(this.getPoint().lat());

						/* Declare and populate the DOM-marker. */
						var DOMMarker = $('mtgt_' + this.id);
						/* Check if the POI is active. */
						if (!this.active) {
							/* Remember the z-index. */
							this.lastPOIZIndex = this.oz; //DOMMarker.style.zIndex;
						}
						/* Make sure the z-index is above everything else in the DOM. */
						DOMMarker.style.zIndex = '7';
						/* Make sure the z-index on the actual object is above everything else in the DOM. */
						$('mtgt_' + this.id).style.zIndex = '7';
					}
					else {
						return true;
						//						this.oz = GOverlay.getZIndex(this.getPoint().lat());

						//						/* Declare and populate the DOM-marker. */
						//						var DOMMarker = $('mtgt_' + this.id);
						//						/* Check if the POI is active. */
						//						if (!this.active) {
						//							/* Remember the z-index. */
						//							this.lastPOIZIndex = this.oz; //DOMMarker.style.zIndex;
						//						}
						//						/* Make sure the z-index is above everything else in the DOM. */
						//						DOMMarker.style.zIndex = '7';
						//						/* Make sure the z-index on the actual object is above everything else in the DOM. */
						//						$('mtgt_' + this.id).style.zIndex = '7';
					}


					if (this.typeId == "1" && this.active == true) {
						/* Handle the tilt. */
						switch (this.tilt) {
							/* The POI's tilt is to the left */ 
							case "1":
								/* Activate the icon-image, take notice of the zoom-level. */
								this.setImage(parseInt(this.zoomToLevel) > 0 && broken.visitSite.map.map.getZoom() < this.zoomToLevel ? '/UI/Images/googlemaps/p.on.a.zoomtoarea.png' : (parseInt(this.zoomToLevel) > 0 ? '/UI/Images/googlemaps/p.on.a.png' : '/UI/Images/googlemaps/p.on.a.left.png'));
								/* Exit the case. */
								break;
							/* The POI's tilt is to the right. */ 
							case "2": // right
								/* Activate the icon-image, take notice of the zoom-level. */
								this.setImage(parseInt(this.zoomToLevel) > 0 && broken.visitSite.map.map.getZoom() < this.zoomToLevel ? '/UI/Images/googlemaps/p.on.a.zoomtoarea.png' : (parseInt(this.zoomToLevel) > 0 ? '/UI/Images/googlemaps/p.on.a.png' : '/UI/Images/googlemaps/p.on.a.right.png'));
								/* Exit the case. */
								break;
							/* The POI's doesnt tilt. */ 
							default:
								/* Activate the icon-image, take notice of the zoom-level. */
								this.setImage(parseInt(this.zoomToLevel) > 0 && broken.visitSite.map.map.getZoom() < this.zoomToLevel ? '/UI/Images/googlemaps/p.on.a.zoomtoarea.png' : '/UI/Images/googlemaps/p.on.a.png');
								/* Exit the case. */
								break;
						}
					}
					/* Check if the POI is a POI-mini and that the current POI is active. */
					else if ((this.typeId == "2" || this.typeId == "6") && this.active == true) {
						/* Activate the icon-image. */
						this.setImage('/UI/Images/googlemaps/p.mini.on.a.png');
					}
					/* Check if the POI is a POI-mini. */
					else if (this.typeId == "2") {
						/* Activate the icon-image. */
						this.setImage('/UI/Images/googlemaps/p.mini.on.png');
					}
					/* Check if the POI is a POI-acc. */
					else if (this.typeId == "6") {
						/* Activate the icon-image. */
						this.setImage('/UI/Images/googlemaps/p.acc.on.png');
					}
					/* Check if the POI is a POI-group. */
					else if (this.typeId == "3") {
						/* Activate the icon-image. */
						this.setImage('/UI/Images/googlemaps/p.big.on.png');

					}
					/* Check if the POI is a POI-accommodation-group. */
					else if (this.typeId == "8") {
						/* Activate the icon-image. */
						this.setImage('/UI/Images/googlemaps/p.accg.on.png');
					}
					/* Check if the POI is a POI-transportation and that the current POI is active. */
					else if (this.typeId == "4" && this.active == true) {
						/* Activate the icon-image. */
						this.setImage('/UI/Images/googlemaps/p.mini.on.a.png');
					}
					/* Check if the POI is a POI-transportation. */
					else if (this.typeId == "4") {
						/* Activate the icon-image. */
						this.setImage('/UI/Images/googlemaps/p.on.transportation.png');
					}
					/* Otherwise, thus the POI is a inactivated POI-Article. */
					else if (this.typeId == "1") {
						switch (this.tilt) {
							case "1":
								/* Activate the icon-image, take notice of the zoom-level. */
								this.setImage(parseInt(this.zoomToLevel) > 0 && broken.visitSite.map.map.getZoom() < this.zoomToLevel ? '/UI/Images/googlemaps/p.on.zoomtoarea.png' : (parseInt(this.zoomToLevel) > 0 ? '/UI/Images/googlemaps/p.on.38.png' : '/UI/Images/googlemaps/p.on.38.left.png'));
								/* Exit the case. */
								break;
							case "2":
								/* Activate the icon-image, take notice of the zoom-level. */
								this.setImage(parseInt(this.zoomToLevel) > 0 && broken.visitSite.map.map.getZoom() < this.zoomToLevel ? '/UI/Images/googlemaps/p.on.zoomtoarea.png' : (parseInt(this.zoomToLevel) > 0 ? '/UI/Images/googlemaps/p.on.38.png' : '/UI/Images/googlemaps/p.on.38.right.png'));
								/* Exit the case. */
								break;
							default:
								/* Activate the icon-image, take notice of the zoom-level. */
								this.setImage(parseInt(this.zoomToLevel) > 0 && broken.visitSite.map.map.getZoom() < this.zoomToLevel ? '/UI/Images/googlemaps/p.on.zoomtoarea.png' : '/UI/Images/googlemaps/p.on.38.png');
								/* Exit the case. */
								break;
						}
					}


					/* Declare and populate the suffix - used to disable the png-fix for IE6.  */
					var _suffix = (broken.util.isIE6 ? 'gif' : 'png');

					/* Handle the type. */
					switch (this.typeId) {
						/* The type is normal POI-Article */ 
						case "1":
							/* Build the label for the DOMMarker. */
							DOMMarker.parentNode.appendChild(Builder.node('span', { id: 'poiLabel', style: 'line-height:16px;font-family: Arial; white-space: nowrap;font-size: 11px; background-repeat: no-repeat; background-position: center right; background-image: url(/ui/images/googlemaps/pin.label.' + _suffix + '); color: #009fdc; height:22px; padding: 4px 15px 0 3px;position: absolute; z-index: 5; top: ' + (parseInt(DOMMarker.style.top) + 2) + 'px; left: ' + (parseInt(DOMMarker.style.left) + 26) + 'px' }, this.name));
							/* Exit the case. */
							break;
						case "2":
							/* Build the label for the DOMMarker. */
							DOMMarker.parentNode.appendChild(Builder.node('span', { id: 'poiLabel', style: 'line-height:14px;font-family: Arial; white-space: nowrap;font-size: 10px; background-repeat: no-repeat; background-position: center right; background-image: url(/ui/images/googlemaps/pin.mini.label.' + _suffix + '); color: #009fdc; height:22px; padding: 0px 12px 0 3px;position: absolute; z-index: 5; line-height:15px; top: ' + (parseInt(DOMMarker.style.top) + 2) + 'px; left: ' + (parseInt(DOMMarker.style.left) + 16) + 'px' }, this.name));
							/* Exit the case. */
							break;
						case "3":
							/* Build the label for the DOMMarker. */
							DOMMarker.parentNode.appendChild(Builder.node('span', { id: 'poiLabel', style: 'line-height:16px;font-family: Arial; white-space: nowrap;font-size: 14px; background-repeat: no-repeat; background-position: center right; background-image: url(/ui/images/googlemaps/pin.big.label.' + _suffix + '); color: #009fdc; height:30px; padding: 9px 15px 0 3px;position: absolute; z-index: 5; top: ' + (parseInt(DOMMarker.style.top)) + 'px; left: ' + (parseInt(DOMMarker.style.left) + 36) + 'px' }, this.name));
							/* Exit the case. */
							break;
						case "4":
							/* Build the label for the DOMMarker. */
							DOMMarker.parentNode.appendChild(Builder.node('span', { id: 'poiLabel', style: 'line-height:14px;font-family: Arial; white-space: nowrap;font-size: 10px; background-repeat: no-repeat; background-position: center right; background-image: url(/ui/images/googlemaps/pin.mini.label.' + _suffix + '); color: #009fdc; height:22px; padding: 0px 15px 0 3px;position: absolute; z-index: 5; top: ' + (parseInt(DOMMarker.style.top) + 2) + 'px; left: ' + (parseInt(DOMMarker.style.left) + 16) + 'px' }, this.name));
							/* Exit the case. */
							break;
						case "6":
							/* Build the label for the DOMMarker. */
							DOMMarker.parentNode.appendChild(Builder.node('span', { id: 'poiLabel', style: 'line-height:14px;font-family: Arial; white-space: nowrap;font-size: 10px; background-repeat: no-repeat; background-position: center right; background-image: url(/ui/images/googlemaps/pin.mini.label.' + _suffix + '); color: #009fdc; height:22px; padding: 0px 12px 0 3px;position: absolute; z-index: 5; line-height:15px; top: ' + (parseInt(DOMMarker.style.top) + 2) + 'px; left: ' + (parseInt(DOMMarker.style.left) + 16) + 'px' }, this.name));
							/* Exit the case. */
							break;
						case "8":
							/* Build the label for the DOMMarker. */
							DOMMarker.parentNode.appendChild(Builder.node('span', { id: 'poiLabel', style: 'line-height:16px;font-family: Arial; white-space: nowrap;font-size: 11px; background-repeat: no-repeat; background-position: center right; background-image: url(/ui/images/googlemaps/pin.label.' + _suffix + '); color: #009fdc; height:22px; padding: 4px 15px 0 3px;position: absolute; z-index: 5; top: ' + (parseInt(DOMMarker.style.top) + 2) + 'px; left: ' + (parseInt(DOMMarker.style.left) + 26) + 'px' }, this.name));
							/* Exit the case. */
							break;
					}

				});
				//}

				/* Handle the markers mouseout-event. */
				GEvent.addListener(marker, 'mouseout', function() {
					/* Check if the POI is a normal POI-Article and the current POI is active. */
					if (this.typeId == "1" && this.active == true) {
						/* Handle the tilt. */
						switch (this.tilt) {
							/* The POI's tilt is to the left. */ 
							case "1":
								/* Update the icon-image, take notice of the zoom-level. */
								this.setImage(parseInt(this.zoomToLevel) > 0 && broken.visitSite.map.map.getZoom() < this.zoomToLevel ? '/UI/Images/googlemaps/p.a.zoomtoarea.png' : (parseInt(this.zoomToLevel) > 0 ? '/UI/Images/googlemaps/p.a.png' : '/UI/Images/googlemaps/p.a.left.png'));
								/* Exit the case. */
								break;
							/* The POI's tilt is to the right. */ 
							case "2":
								/* Update the icon-image, take notice of the zoom-level. */
								this.setImage(parseInt(this.zoomToLevel) > 0 && broken.visitSite.map.map.getZoom() < this.zoomToLevel ? '/UI/Images/googlemaps/p.a.zoomtoarea.png' : (parseInt(this.zoomToLevel) > 0 ? '/UI/Images/googlemaps/p.a.png' : '/UI/Images/googlemaps/p.a.right.png'));
								/* Exit the case. */
								break;
							/* The POI doesn't tilt. */ 
							default:
								/* Update the icon-image, take notice of the zoom-level. */
								this.setImage(parseInt(this.zoomToLevel) > 0 && broken.visitSite.map.map.getZoom() < this.zoomToLevel ? '/UI/Images/googlemaps/p.a.zoomtoarea.png' : '/UI/Images/googlemaps/p.a.png');
								/* Exit the case. */
								break;
						}
					}
					/* Check if the POI is a POI-mini and the current POI is active. */
					else if ((this.typeId == "2" || this.typeId == "6") && this.active == true) {
						/* Update the icon-image. The icon is still active. */
						this.setImage('/UI/Images/googlemaps/p.mini.a.png');
					}
					/* Check if the POI is a POI-mini. */
					else if (this.typeId == "2") {
						/* Deactivate the icon-image. */
						this.setImage('/UI/Images/googlemaps/p.mini.png');
					}
					else if (this.typeId == "6") {
						/* Deactivate the icon-image. */
						this.setImage('/UI/Images/googlemaps/p.acc.png');
					}
					/* Check if the POI is a POI-Group. */
					else if (this.typeId == "3") {
						/* Deactivate the icon-image. */
						this.setImage('/UI/Images/googlemaps/p.big.png');

					}
					/* Check if the POI is a POI-Accommodation-Group. */
					else if (this.typeId == "8") {
						/* Deactivate the icon-image. */
						this.setImage('/UI/Images/googlemaps/p.accg.png');
					}
					/* Check if the POI is a POI-Transportation and the current POI is active. */
					else if (this.typeId == "4" && this.active == true) {
						/* Update the icon-image. The icon is still active. */
						this.setImage('/UI/Images/googlemaps/p.mini.a.png');
					}
					/* Check if the POI is a POI-transportation. */
					else if (this.typeId == "4") {
						/* Deactivate the icon-image. */
						this.setImage('/UI/Images/googlemaps/p.transportation.png');
					}
					/* Otherwise, thus the POI is a inactivated POI-Article. */
					else if (this.typeId == "1") {
						/* Handle the tilt. */
						switch (this.tilt) {
							/* The POI's tilt is to the left. */ 
							case "1":
								/* Deactivate the icon-image. */
								this.setImage(parseInt(this.zoomToLevel) > 0 && broken.visitSite.map.map.getZoom() < this.zoomToLevel ? '/UI/Images/googlemaps/p.zoomtoarea.png' : (parseInt(this.zoomToLevel) > 0 ? '/UI/Images/googlemaps/p.38.png' : '/UI/Images/googlemaps/p.38.left.png'));
								/* Exit the case. */
								break;
							/* The POI's tilt is to the right. */ 
							case "2":
								/* Deactivate the icon-image. */
								this.setImage(parseInt(this.zoomToLevel) > 0 && broken.visitSite.map.map.getZoom() < this.zoomToLevel ? '/UI/Images/googlemaps/p.zoomtoarea.png' : (parseInt(this.zoomToLevel) > 0 ? '/UI/Images/googlemaps/p.38.png' : '/UI/Images/googlemaps/p.38.right.png'));
								/* Exit the case. */
								break;
							/* The POI doesn't tilt. */ 
							default:
								/* Deactivate the icon-image. */
								this.setImage(parseInt(this.zoomToLevel) > 0 && broken.visitSite.map.map.getZoom() < this.zoomToLevel ? '/UI/Images/googlemaps/p.zoomtoarea.png' : '/UI/Images/googlemaps/p.38.png');
								/* Exit the case. */
								break;
						}
					}

					/* Check if the POI is active. */
					if (!this.active) {
						/* Reset the z-index. */

						$('mtgt_' + this.id).style.zIndex = this.lastPOIZIndex;
					}

					/*Itterate through the labels*/
					while ($('poiLabel')) {
						/* Remove the label. */
						$('poiLabel').remove();
					}
				});

				/* Include the marker to the array */
				this.mapDataJSON[j].marker = marker;
			};

			/* As it is now the mapdata object is never undefined and the map will pane to its original position */
			if (this.isZoomed == false) {
				if (typeof this.mapData.page != 'undefined') {
					var currentPage = this.mapData.page;
					if (currentPage.zoom != 'null') {

						if (typeof broken.visitSite.map.pickerMarkerTimeout == 'undefined' && broken.visitSite.map.pickerMarkerTimeout == null) {
							this.gotoPoint(currentPage.lat, currentPage.lng, currentPage.zoom);
						}
						this.orgLat = currentPage.lat;
						this.orgLng = currentPage.lng;
						this.orgZoom = currentPage.zoom;

						this.isZoomed = true;
					}
				}
			}
		}

		/* Build the markers. */
		this.getMarkers(true);
	},

	/* 
	function broken.googleMaps.core.gotoPoint
	*/
	gotoPoint: function(lat, lng, zoom) {
		///alert(lat + "," + lng + "," + zoom); 
		
		this.map.setCenter(new GLatLng(lat, lng), parseInt(zoom));
	},

	/* 
	function broken.googleMaps.core.setPositionCookie
	*/
	setPositionCookie: function(name, value, days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
			var expires = "; expires=" + date.toGMTString();
		}
		else var expires = "";

		document.cookie = name + "=" + value + expires + "; path=/";
	},

	/* 
	function broken.googleMaps.core.getPositionCookie
	*/
	getPositionCookie: function(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for (var i = 0; i < ca.length; i++) {
			var c = ca[i];
			while (c.charAt(0) == ' ') c = c.substring(1, c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
		}
		return null;
	},
	/* Does the pageTracker Exist in that case add Accommodation/hotelname to the variable*/
	poiaccomodation_function: function(tabname) {
		//        if (pageTracker != null) {
		//            /* Add the hotelname to the tracker. if its not already counted */
		////            if ($('HiddenPoiName').value != this.name) {
		////                var lang = $('HiddenLanguageSegment').value;
		////                var stripped = this.name.replace("/", " ");
		////                pageTracker._trackPageview("/" + lang + "/POIAC/" + stripped);
		////            }
		//        }
		var bookPageId = $('HiddenBookPageId').value;
		//We are not on the booking page redirect
		if (broken.visitSite.map.currentPageID != bookPageId) {
			//We saved the url to the booking page in a hidden field on the scripts.ascx
			var landingPage = $('HiddenBookUrl').value;
			//Append the correct id
			var query = broken.visitSite.map.currentPoiMarker.id.substring(1, broken.visitSite.map.currentPoiMarker.id.length - 2);
			//We need to be able to reproduce the zoom level so we save it
			var z = broken.visitSite.map.map.getZoom(); // zoom;
			document.location = landingPage + "?pid=" + query + "&z=" + z + "&tab=" + tabname;

		}
		else {

			broken.visitSite.page.iframeIsToggled = false;
			var firstLoad = true;
			//Remove poitype _6 from string and split
			var clean = broken.visitSite.map.currentPoiMarker.id.substring(1, broken.visitSite.map.currentPoiMarker.id.length - 2);

			//save the pid to hidden field for beeing able to save to favorites
			$('HiddenPoiId').value = clean;
			$('HiddenPoiName').value = broken.visitSite.map.currentPoiMarker.name;
			$('HiddenZoom').value = broken.visitSite.map.map.getZoom();
			pidAndOnlineId = clean.split("-");
			pidAndOnlineId.randomize();

			var querystring = "";
			//Inject the hotell name into the HTML
			$('h1Heading').innerHTML = $('HiddenPageName').value + " " + $('HiddenPoiName').value;
			$('pProvider').innerHTML = $('HiddenPoiName').value + " " + $('HiddenProviderText').value;

			for (var i = 0; i < pidAndOnlineId.length; i++) {

				split = pidAndOnlineId[i].split("_");

				querystring += "onlineid" + i + "=" + split[1] + "&";
				//Add &amp;tab=vBook if you want to open book tab
				if (tabname == "book") {
					var iframeurl = "http://online2.citybreak.com/Accommodation/Details.aspx?onlineid=" + split[1] + "&amp;pid=" + split[0] + "&amp;show=book&amp;tab=vBook";
				}
				else {
					var iframeurl = "http://online2.citybreak.com/Accommodation/Details.aspx?onlineid=" + split[1] + "&amp;pid=" + split[0] + "&amp;show=book";
				}

				if (i == 0) {
					$('visitTIFrame').src = iframeurl;
				}
				if (i == 1) {
					$('visitTIFrame1').src = iframeurl;
				}
				if (i == 2) {
					$('visitTIFrame2').src = iframeurl;
				}
			}
			//Empty name and hide the li:s
			$('h2Organizer1').innerHTML = "";
			$('h2Organizer2').innerHTML = "";
			$('h2Organizer3').innerHTML = "";
			$('li1').style.display = "none";
			$('li2').style.display = "none";
			$('li3').style.display = "none";
			var requestURL = '/ui/services/GetOrganizerData.ashx?' + querystring;
			//Make Ajax request and get the name of the organizer inject into correct tag
			var expandElement = $('h2Organizer1');
			var expandIFrame = $('visitTIFrame');
			broken.visitSite.page.closeAllBookings('bookings');


			new Ajax.Request(requestURL, {
				onSuccess: function(data) {
					var organizerData = data.responseText.evalJSON();
					var index = 0;

					for (var x in organizerData.organizers) {
						if (index == 0) {
							$('li1').style.display = "block";
							$('h2Organizer1').innerHTML = organizerData.organizers[x];
						}
						if (index == 1) {
							$('li2').style.display = "block";
							$('h2Organizer2').innerHTML = organizerData.organizers[x];
							expandElement = $('h2Organizer2');
							expandIFrame = $('visitTIFrame1');
						}
						if (index == 2) {
							$('li3').style.display = "block";
							$('h2Organizer3').innerHTML = organizerData.organizers[x];
							expandElement = $('h2Organizer3');
							expandIFrame = $('visitTIFrame2');
						}
						index++;
					}

					expandElement.setStyle({ backgroundImage: 'url(/ui/images/list.arrow.animated.gif)' });

				}

			});


			Event.stopObserving($('visitTIFrame'), 'load');
			Event.stopObserving($('visitTIFrame1'), 'load');
			Event.stopObserving($('visitTIFrame2'), 'load');

			Event.observe(expandIFrame, 'load', function(event) {
				if (!broken.visitSite.page.iframeIsToggled)
					broken.visitSite.page.toggleBookings(expandElement, 'bookings', true);
				broken.visitSite.page.iframeIsToggled = true;
			});

			/* Update the horisontal variable, this is done since the mini/transportation-widget is smaller then the article. */
			//_x = (!broken.visitSite.map.isSearchMap) ? parseInt(broken.googleMaps.core.addMarkerspixels.x) : parseInt(broken.googleMaps.core.addMarkerspixels.x - 120);
			/* Declare and set the point. */
			var point = broken.visitSite.map.map.getCurrentMapType().getProjection().fromPixelToLatLng(new GPoint(broken.visitSite.map.activateMarker._x, broken.visitSite.map.activateMarker._y), broken.visitSite.map.activateMarker.zoom);
			/* Pan to the point. */
			broken.visitSite.map.map.panTo(new GLatLng(broken.visitSite.map.currentPoiMarker.lat, broken.visitSite.map.currentPoiMarker.lng));
			/* Load the widget source. Notice that the transportation POI's share the poiLight source! */
			broken.visitSite.page.loadWidget('/UI/scripts/widgets/PoiAccomodation.js');

			/* Exit the case. */
		}
	}
};

broken.visitSite = Class.create();
window.newRequest = true;
broken.visitSite.map = Object.extend(broken.googleMaps.core,
{
    latestBoundsX1: null, /* broken.visitSite.map.latestBoundsX1 */
    latestBoundsX2: null, /*broken.visitSite.map.latestBoundsX2 */
    latestBoundsY1: null, /*  broken.visitSite.map.latestBoundsY1 */
    latestBoundsY2: null, /* broken.visitSite.map.latestBoundsY2 */
    latestZoom: null, /* broken.visitSite.map.latestZoom */
    mapDataJSON: {}, /* broken.visitSite.map.mapDataJSON */
    mapDataCategories: {}, /* broken.visitSite.map.mapDataCategories */
    mapDataTypes: {}, /* broken.visitSite.map.mapDataTypes */
    isRegularMap: false, /* broken.visitSite.map.isRegularMap */
    isSearchMap: false, /* broken.visitSite.map.isSearchMap */
    isCoordinatePickerMap: false, /* broken.visitSite.map.isCoordinatePickerMap */
    isSmallMap: false,
    pickerMarker: null,

    /* 
    function broken.visitSite.map.init
    */
    init: function() {

        this.isRegularMap = ($('ctl00_FullRegion_MapRegion_MapControl_gmap') ? true : false);
        this.isSearchMap = ($$('div.searchMap').size() == 1);
        this.isCoordinatePickerMap = ($$('div.coordinatePickerMap').size() == 1);
        this.isSmallMap = ($('ctl00_FullRegion_MainRegion_smallMapControl_gmap') ? true : false);

        if (this.isRegularMap && broken.visitSite.page.mapOpenState == 'true' && typeof GBrowserIsCompatible != 'undefined') {

            this.initialize('ctl00_FullRegion_MapRegion_MapControl_gmap', 62.5, 19, 4);
        }
        else if (this.isSmallMap && typeof GBrowserIsCompatible != 'undefined') {
            this.isSearchMap = false; //Since searchmap looks for the div that is present on smallmap also
            this.initialize('ctl00_FullRegion_MainRegion_smallMapControl_gmap', 63.74, 18, 4);
        }
        else if (this.isSearchMap && typeof GBrowserIsCompatible != 'undefined') {
            this.initialize('ctl00_FullRegion_MainRegion_SerchMapControl_gmap', 63.74, 18, 4);
        }
        else if (this.isCoordinatePickerMap && typeof GBrowserIsCompatible != 'undefined') {
            this.initialize('gmap', 62.5, 19, 4);
        }



    },



    /* 
    function broken.visitSite.map.loadPageMapData
	
	*/
    loadPageMapData: function() {
        var pageId = $('HiddenPageID').value;
        var _this = this;

        var isPoiLight = false;
        var poiid = "";

        if ($('HiddenPoiId') != null && $('HiddenPoiId').value != "") {
            
            poiid = "&pid=" + $('HiddenPoiId').value;
        }
        if ($('HiddenIsPoiLight') != null) {
            isPoiLight = $('HiddenIsPoiLight').value;

        }
        var z = 0;
        var url = window.location.toString();
        //get the parameters
        url.match(/\?(.+)$/);
        var params = RegExp.$1;
        // split up the query string and store in an
        // associative array
        var params = params.split("&");
        var queryStringList = {};

        for (var i = 0; i < params.length; i++) {
            var tmp = params[i].split("=");
            queryStringList[tmp[0]] = unescape(tmp[1]);
        }


        z = queryStringList["z"];

        if (typeof z == 'undefined')
            z = broken.visitSite.map.map.getZoom(); // zoom;
        
        compledZoomToAcc = 0;
        var requestURL = '/ui/services/GetCurrentPois.ashx?PageID=' + pageId + poiid + "&z=" + z; ;

        new Ajax.Request(requestURL, {
            onSuccess: function(data) {
                var pageMapData = data.responseText.evalJSON();

                for (var x in pageMapData.categories) {
                    _this.mapDataCategories[x] = pageMapData.categories[x];
                }

                broken.visitSite.map.map.setCenter(new GLatLng(parseFloat(pageMapData.page.lat), parseFloat(pageMapData.page.lng)), pageMapData.page.zoom);
                //console.log("ldat: " + pageMapData.page.lat + " Lng: " + pageMapData.page.lng + " zoom: " + pageMapData.page.zoom);
            }
        });
    },

    /* 
    function broken.visitSite.map.loadDynamicMapData
    */
    loadDynamicMapData: function(bounds, zoom) {
        var northEast = bounds.getNorthEast();
        var southWest = bounds.getSouthWest();

        // Yeah yeah, we know this is twisted.
        var x1 = southWest.lat().toFixed(2);
        var y1 = southWest.lng().toFixed(2);
        var x2 = northEast.lat().toFixed(2);
        var y2 = northEast.lng().toFixed(2);

        var z = broken.visitSite.map.map.getZoom(); // zoom;

        if (this.latestBoundsX1 != x1 &&
			this.latestBoundsX2 != x2 &&
			this.latestBoundsY1 != y1 &&
			this.latestBoundsY2 != y2) {

            if (x1 < 0) x1 = 0;
            if (y1 < 0) y1 = 0;

            this.latestBoundsX1 = x1;
            this.latestBoundsX2 = x2;
            this.latestBoundsY1 = y1;
            this.latestBoundsY2 = y2;
            this.latestZoom = z;

            var pageId = $('HiddenPageID').value;
            var isPoiLight = false;
            var poiid = "";

            //So we can center on the poilight and accomodation is set in script.ascx
            if ($('HiddenPoiId') != null) {
                poiid = $('HiddenPoiId').value;
            }
            //so we know if inte is a zoom to the poiid
            if ($('HiddenIsPoiLight') != null) {
                isPoiLight = $('HiddenIsPoiLight').value;

            }
            var poiType = "";
            if (broken.visitSite.map.isSmallMap)
                poiType = "&poiType=10";
            else if ($('HiddenPoiType') != null) {
                poiType = "&poiType=" + $('HiddenPoiType').value;
            }
            var _this = this;

            var requestURL = '/ui/services/GetCurrentPoisNew.ashx?PageID=' + pageId + '&x1=' + x1 + '&x2=' + x2 + '&y1=' + y1 + '&y2=' + y2 + "&z=" + z + "&pid=" + poiid + poiType;

            new Ajax.Request(requestURL, {
                onSuccess: _this.storeMapData.bind(this)
            });
        }
    },

    /* 
    function broken.visitSite.map.loadMapData
    */
    loadMapData: function() {
        var pageId = $('HiddenPageID').value;
        var _this = this;


        var requestURL = '/ui/services/GetCurrentPoisNew.ashx?PageID=' + pageId + "&times=" + times;
        new Ajax.Request(requestURL, {
            onSuccess: _this.storeMapData.bind(this)
        });
    },

    /* 
    function broken.visitSite.map.loadSearchMapData
    */
    loadSearchMapData: function() {
        var searchQuery = window.location.href.parseQuery();
        if (Prototype.Browser.IE)
            var sq = broken.util.encode(searchQuery.q);
        else
            var sq = searchQuery.q;

        var metaData = 'meta%3ApageType';
        var requestURL = '/ui/pages/PoiJsonCreate.aspx?query=' + sq;

        var _this = this;

        new Ajax.Request(requestURL, {
            onSuccess: _this.storeMapData.bind(this)
        });
    },


    /* 
    function broken.visitSite.map.storeMapData
    */
    storeMapData: function(data) {
        this.mapData = data.responseText.evalJSON();

        for (var x in this.mapData.pois) {
            if (typeof this.mapDataJSON[x] == 'undefined')
                this.mapDataJSON[x] = this.mapData.pois[x];
        }

        this.addMarkers();
    },

    /* 
    function broken.visitSite.map.configHandle
    */
    configHandle: function() {
        this.slider = new Control.Slider(
			'handle',
			'track',
			{
			    range: $R(18, 3),
			    values: [18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3],
			    axis: 'vertical',
			    onChange: function(v) {
			        broken.visitSite.map.map.setZoom(v);
			    }
			}
		);
        this.slider.setValue(broken.visitSite.map.map.getZoom());
    },

    /* 
    function broken.visitSite.map.changeCategory
    */
    changeCategory: function(sender, classId, id) {
        if ($(sender).hasClassName('active' + classId)) {
            sender.removeClassName('active' + classId);
            if (broken.util.isIE6)
                sender.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/ui/images/map.category.icon.inactive.png', sizingMethod='crop')";

            this.mapDataCategories[id] = 'false';
            var _add = false;
        } else {
            sender.addClassName('active' + classId);

            if (broken.util.isIE6)
                sender.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/ui/images/map.category.icon.active." + classId + ".png', sizingMethod='crop')";

            this.mapDataCategories[id] = 'true';
            var _add = true;
        }

        this.getMarkers(_add);
    },

    /* 
    function broken.visitSite.map.getMarkers
    */
    getMarkers: function(_add) {
        //console.log("getMarkers()");
        this.inActiveMarkers = {};
        this.newActiveMarkers = {};

        var _categoriesCount = 0;

        //Set the Airports to visible
        if (typeof broken.visitSite.map.mapDataTypes[4] == 'undefined' && $('HiddenMiscCategories'))
            broken.visitSite.map.mapDataTypes[4] = ($('HiddenMiscCategories').value.indexOf('52') > -1 ? 'true' : 'false');
        if (broken.visitSite.map.isSearchMap)
            broken.visitSite.map.mapDataTypes[4] = true;

        //Set the Accommodation to visible when map is loaded
        if (typeof broken.visitSite.map.mapDataTypes[6] == 'undefined' && $('HiddenMiscCategories'))
            broken.visitSite.map.mapDataTypes[6] = ($('HiddenMiscCategories').value.indexOf('53') > -1 ? 'true' : 'false');
        if (broken.visitSite.map.isSearchMap)
            broken.visitSite.map.mapDataTypes[6] = true;

        for (var x in this.mapDataCategories) {
            if (this.mapDataCategories[x] == 'true')
                _categoriesCount++;
        }

        for (var x in this.mapDataJSON) {

            var _this = this;
            var _show = (function() {
                var _categories = _this.mapDataJSON[x].categories.split(',');
                // Handle changeMapType() (ie: POITransportation on/off from the 'Show On Map'-box)
                if (typeof _this.mapDataTypes[_this.mapDataJSON[x].typeId] != 'undefined' && _this.mapDataTypes[_this.mapDataJSON[x].typeId] == 'false')
                    return false;
                // Otherwise: show POIGroups and POITransportation or accommodation
                else if ((_this.mapDataJSON[x].marker.typeId == '8' && broken.visitSite.map.mapDataTypes[6] == 'true') || (_this.mapDataJSON[x].marker.typeId == '3' && _categoriesCount > 0) || (_this.mapDataJSON[x].marker.typeId == '4' && broken.visitSite.map.mapDataTypes[4] == 'true') || (_this.mapDataJSON[x].marker.typeId == '6' && broken.visitSite.map.mapDataTypes[6] == 'true') || (_this.mapDataJSON[x].marker.typeId == '10' && broken.visitSite.map.mapDataTypes[10] == 'true'))
                    return true;

                if (broken.visitSite.map.isSmallMap && _this.mapDataJSON[x].marker.typeId == '10') {
                    return true;
                }

                if (!broken.visitSite.map.isSmallMap && !broken.visitSite.map.isSearchMap && !broken.visitSite.map.isCoordinatePickerMap) {
                    // Är det här verkligen rätt månne?
                    // Om en POI ligger i fler kategorier blir det stök - södra sverige, flippa family och outdoor - kolla console.
                    for (var i = 0; i < _categories.length; i++) {

                        if (_this.mapDataCategories[_categories[i]] == 'true') {
                            return true;
                        }
                    }
                } else {
                    return true;
                }

                return false;
            })();

            if (_show) {
                if (this.activeMarkers[x] == null && _add) {
                    this.newActiveMarkers[x] = this.mapDataJSON[x].marker;
                }
            } else {
                this.inActiveMarkers[x] = this.mapDataJSON[x].marker;
            }
        }
        this.placeMarkers();
    },

    lastAddedIndex: 0,

    /* 
    function broken.visitSite.map.placeMarkers
    */
    placeMarkers: function() {

        var _change = true;
        var _updateLastAddedIndex = false;
        for (var x in this.inActiveMarkers) {
            if (typeof this.activeMarkers[x] == 'object') {
                this.activeMarkers[x] = null;
                this.mm.removeMarker(this.inActiveMarkers[x]);
                _change = true;
            }
        }

        for (var x in this.newActiveMarkers) {
            if (typeof this.activeMarkers[x] == 'undefined' || this.activeMarkers[x] == null) {
                this.activeMarkers[x] = this.newActiveMarkers[x];

                /* Should the markers be placed on top of all markers? */
                if (this.activeMarkers[x].importance > 10) {
                    this.activeMarkers[x].importance = 90 + broken.visitSite.map.lastAddedIndex;
                    _updateLastAddedIndex = true;
                }

                this.mm.addMarker(this.activeMarkers[x], parseFloat(this.activeMarkers[x].mz), parseFloat(this.activeMarkers[x].maz));
                _change = true;
            }
        }

        /* Update the broken.visitSite.map.lastAddedIndex to make sure that the next set of markers will have higher z-index.*/
        if (_updateLastAddedIndex)
            broken.visitSite.map.lastAddedIndex += 1;

        if (typeof this.photoMarker != 'undefined' && this.photoMarker != null) {
            if (typeof this.photoMarker != 'undefined') {
                this.mm.removeMarker(this.photoMarker);
            }

            this.mm.addMarker(this.photoMarker, parseFloat(this.photoMarker.mz), parseFloat(this.photoMarker.maz));
            _change = true;
        }

        if (typeof this.textMarker != 'undefined' && this.textMarker != null) {
            if (typeof this.textMarker != 'undefined') {
                this.mm.removeMarker(this.textMarker);
            }

            this.mm.addMarker(this.textMarker, parseFloat(this.textMarker.mz), parseFloat(this.textMarker.maz));
            _change = true;
        }

        if (typeof this.pickerMarker != 'undefined' && this.pickerMarker != null) {
            if (typeof this.pickerMarker != 'undefined') {
                this.mm.removeMarker(this.pickerMarker);
            }

            this.mm.addMarker(this.pickerMarker, parseFloat(this.pickerMarker.mz), parseFloat(this.pickerMarker.maz));
            _change = true;
        }

        if (_change) {


            //Istället för refresh() - verkar lösa dubbelrendering för kategorier..
            //if (typeof this.pickerMarkerTimeout == 'undefined' && this.pickerMarkerTimeout == null)
            this.mm.updateMarkers_();
        }
        //console.log("placeMarkers");
        broken.googleMaps.core.isInitialized = true;
        //Tor added support for activatemarker from poi if a booking is loaded.
        // get the current URL must add so it only use the activate marker from poi once and not keep doing it everytime it replaces
        // markers on the map
        if (compledZoomToAcc == 0) {
            var url = window.location.toString();
            //get the parameters
            url.match(/\?(.+)$/);
            var params = RegExp.$1;
            // split up the query string and store in an
            // associative array
            var params = params.split("&");
            var queryStringList = {};

            for (var i = 0; i < params.length; i++) {
                var tmp = params[i].split("=");
                queryStringList[tmp[0]] = unescape(tmp[1]);
            }
            var pid = "";
            var z = "";
            for (var i in queryStringList) {
                if (i == "pid") {
                    pid = queryStringList[i];
                }
                else if (i = "z")
                    z = queryStringList[i];
            }
            if (pid != "") {
                broken.visitSite.map.activateMarkerFromPOI(pid);
            }
            compledZoomToAcc = 1; //Set to zero when loads getcurrentpois
        }

    },

    /* 
    function broken.visitSite.map.addPhotoMarker
    */
    addPhotoMarker: function(lat, lng, zoom) {
        //console.log("addPhotoMarker");
        if (broken.visitSite.map.currentPoiMarker != false) {
            broken.visitSite.map.unloadPoi();
        }

        var p = { lat: lat, lng: lng };
        //var ic = { sh: 59, sw: 37, ax: 19, ay: 53, image: '/UI/Images/googlemaps/photoicon.png' };
        var ic = { sh: 49, sw: 45, ax: 32, ay: 0, image: '/UI/Images/googlemaps/arrow_large.png' };
        var o = { lat: lat, lng: lng, importance: 999999, maz: 17, mz: 4 };
        var marker = this.createMarker(p, ic, o, false, false);

        //Added by Tor Andersson
        var currentZoom = this.map.getZoom();
        this.gotoPoint(lat, lng, currentZoom);
        //this.gotoPoint(lat, lng, parseInt(zoom));
        if (typeof this.textMarker != 'undefined' && this.textMarker != null) {
            this.mm.removeMarker(this.textMarker);
            this.textMarker = null;
        }

        if (typeof this.photoMarker != 'undefined' && this.photoMarker != null) {
            this.mm.removeMarker(this.photoMarker);
            this.photoMarker = null;
        }

        this.photoMarker = marker;
        this.placeMarkers();

    },

    /* 
    function broken.visitSite.map.addTextMarker
    */
    addTextMarker: function(lat, lng, zoom) {
        //console.log("addTextMarker");
        if (broken.visitSite.map.currentPoiMarker != false) {
            broken.visitSite.map.unloadPoi();
        }
        var p = { lat: lat, lng: lng };
        var ic = { sh: 49, sw: 45, ax: 32, ay: 0, image: '/UI/Images/googlemaps/arrow_large.png' };
        var o = { lat: lat, lng: lng, importance: 999999, maz: 17, mz: 4 };
        var marker = this.createMarker(p, ic, o, false, false);

        //Added by Tor Andersson
        var currentZoom = this.map.getZoom();
        this.gotoPoint(lat, lng, currentZoom);
        //this.gotoPoint(lat, lng, parseInt(zoom));

        if (typeof this.textMarker != 'undefined' && this.textMarker != null) {
            this.mm.removeMarker(this.textMarker);
            this.textMarker = null;
        }

        if (typeof this.photoMarker != 'undefined' && this.photoMarker != null) {
            this.mm.removeMarker(this.photoMarker);
            this.photoMarker = null;
        }

        this.textMarker = marker;
        this.placeMarkers();

        broken.util.scrollToTop(0);

    },

    /* 
    function broken.visitSite.map.addPickerMarker
    */
    addPickerMarker: function() {
        //console.log("addPickerMarker()");
        if (typeof this.mm != 'undefined') {
            var lat = $("HiddenLat").value;
            var lng = $("HiddenLng").value;
            var zoom = $("HiddenZoom").value;
            var p = { lat: lat, lng: lng };
            var ic = { sh: 40, sw: 26, ax: 13, ay: 35, image: '/UI/Images/googlemaps/p.a.png' };
            var o = { lat: lat, lng: lng, importance: 999999, maz: 17, mz: 4 };
            var marker = this.createMarker(p, ic, o, true, true);
            var _this = this;

            this.gotoPoint(lat, lng, parseInt(zoom));

            var point = marker.getPoint();

            GEvent.addListener(marker, "dragend", function(point) {
                $("lat").value = point.lat();
                $("lng").value = point.lng();
                $("curZoom").value = _this.map.getZoom();
                if ($("maxZoom").value == "")
                    $("maxZoom").value = 17;
                if ($("minZoom").value == "")
                    $("minZoom").value = _this.map.getZoom();

                broken.visitSite.map.gotoPoint(point.lat(), point.lng(), parseInt(_this.map.getZoom()));
            });

            GEvent.addListener(_this.map, "zoomend", function() {
                $("curZoom").value = _this.map.getZoom();
            });

            if (typeof this.pickerMarker != 'undefined' && this.pickerMarker != null) {
                this.mm.removeMarker(this.pickerMarker);
                this.pickerMarker = null;
            }
            this.pickerMarker = marker;
            this.placeMarkers();
        } else {
            this.pickerMarkerTimeout = setTimeout('broken.visitSite.map.addPickerMarker()', 100);
        }
    },

    /* 
    function broken.visitSite.map.movePickerMarker
    */
    movePickerMarker: function(point) {
        point = this.map.getCurrentMapType().getProjection().fromPixelToLatLng(point, _this.map.getZoom());
        broken.visitSite.map.pickerMarker.setPoint(point);
    },

    /* 
    function broken.visitSite.map.findPickerLocation
    */
    findPickerLocation: function(address) {
        if (typeof this.pickerMarker != 'undefined' && this.pickerMarker != null) {
            var coder = new GClientGeocoder();
            coder.getLatLng(address, function(point) {
                if (point) {
                    broken.visitSite.map.gotoPoint(point.lat(), point.lng(), parseInt(11));
                    broken.visitSite.map.pickerMarker.setPoint(point);
                } else {
                    alert(address + " not found.");
                }
            });
        } else {
            alert('The pickerMarker hasn\'t been initialized yet.\nPlease try again!');
        }
    },

    /* 
    function broken.visitSite.map.getPickerPreset
    */
    getPickerPreset: function(sel) {
        preset = sel.options[sel.selectedIndex].value;
        if (preset != 'null') {
            var maxMin = preset.split('|');

            $("maxZoom").value = maxMin[0];
            $("minZoom").value = maxMin[1];
            sel.selectedIndex = 0;
        }
    },

    /* 
    function broken.visitSite.map.placePickerMarker
    */
    placePickerMarker: function() {
        //console.log("placePickerMarker()");
        var point = this.map.getCenter();
        broken.visitSite.map.pickerMarker.setPoint(point);
        this.placeMarkers();
    },

    /* 
    function broken.visitSite.map.activateMarker
    */
    activateMarker: function(id, isStatic) {


        if (broken.visitSite.map.currentPoiMarker != false) {
            broken.visitSite.map.unloadPoiKeepWidget();
        }

        var m = broken.visitSite.map.map;

        if (typeof this.activeMarkers['poi' + id] == 'undefined') {
            m.setZoom(11);
        }
        else {
            var marker = this.activeMarkers['poi' + id];

            var zoom = m.getZoom();

            var pixels = m.getCurrentMapType().getProjection().fromLatLngToPixel(new GLatLng(marker.lat, marker.lng), zoom);

            var _y = pixels.y;
            var _x = parseInt(pixels.x - 100);
            var point = m.getCurrentMapType().getProjection().fromPixelToLatLng(new GPoint(_x, _y), zoom);

            switch (marker.typeId) {
                case "1":
                    switch (marker.tilt) {
                        case "1":
                            marker.setImage(parseInt(marker.zoomToLevel) > 0 && broken.visitSite.map.map.getZoom() < marker.zoomToLevel ? '/UI/Images/googlemaps/p.a.zoomtoarea.png' : (parseInt(marker.zoomToLevel) > 0 ? '/UI/Images/googlemaps/p.a.png' : '/UI/Images/googlemaps/p.a.left.png'));
                            break;
                        case "2":
                            marker.setImage(parseInt(marker.zoomToLevel) > 0 && broken.visitSite.map.map.getZoom() < marker.zoomToLevel ? '/UI/Images/googlemaps/p.a.zoomtoarea.png' : (parseInt(marker.zoomToLevel) > 0 ? '/UI/Images/googlemaps/p.a.png' : '/UI/Images/googlemaps/p.a.right.png'));
                            break;
                        default:
                            marker.setImage(parseInt(marker.zoomToLevel) > 0 && broken.visitSite.map.map.getZoom() < marker.zoomToLevel ? '/UI/Images/googlemaps/p.a.zoomtoarea.png' : '/UI/Images/googlemaps/p.a.png');
                            break;
                    }
                    break;
                case "4":
                case "2":
                case "6":
                    marker.setImage('/UI/Images/googlemaps/p.mini.a.png');
                    break;
            }

            marker.active = true;
            this.lastImportance = marker.importance;
            marker.importance = 9999999;

            this.lastPOIZIndex = $('mtgt_' + marker.id).style.zIndex;
            $('mtgt_' + marker.id).style.zIndex = '1';



            broken.visitSite.map.currentPoiMarker = marker;
            broken.visitSite.map.currentPageID = $('HiddenPageID').value;
            broken.visitSite.map.currentEpsLanguageCode = $('HiddenLanguageCode').value;

            switch (marker.typeId) {
                case "1":
                    broken.visitSite.map.map.panTo(new GLatLng(point.lat(), point.lng()));
                    if (!isStatic) broken.visitSite.page.loadWidget('/UI/scripts/widgets/poiArticle.js');
                    break;
                case "2":
                    broken.visitSite.map.map.panTo(new GLatLng(point.lat(), (point.lng())));
                    if (!isStatic) broken.visitSite.page.loadWidget('/UI/scripts/widgets/poiLight.js');
                    break;
                case "3":
                    broken.visitSite.map.unloadPoi();
                    broken.visitSite.map.gotoPoint(this.lat, this.lng, parseInt(this.zoomToLevel));
                    break;
                case "4":
                    broken.visitSite.map.map.panTo(new GLatLng(point.lat(), point.lng()));
                    if (!isStatic) broken.visitSite.page.loadWidget('/UI/scripts/widgets/poiLight.js');
                    break;
                case "6":
                    broken.visitSite.map.map.panTo(new GLatLng(marker.lat, marker.lng));
                    if (!isStatic) broken.visitSite.page.loadWidget('/UI/scripts/widgets/PoiAccomodation.js');
                    break;

            }
        }
    },

    /*
    function broken.visitSite.map.activateMarkerFromPOI()
    Parameter number id: PageID of the widget in EPiServer
    Function is called from the onload-event in POIArticle.aspx (ie: staticpoi=true)
    Used to make sure that the map is fully initiated before activating a marker.
    */
    activateMarkerFromPOI: function(id) {
        /* Check if everything is populated as supposed. */

        if (typeof this.activeMarkers != 'undefined' && typeof this.activeMarkers['poi' + id] != 'undefined') {

            /* Execute the broken.visitSite.map.activateMarker() passing the id and a bool telling the function that the call is isStatic == true. */
            this.activateMarker(id, true);
        } else {
            /* Retry with a 100ms delay */

            setTimeout('broken.visitSite.map.activateMarkerFromPOI(' + id + ')', 100);
        }
    },

    /*
    function broken.visitSite.map.unloadPoi()
    Function is triggered when any POI-widget is closed 
    Both via click on button and programatically from various places in code.
    */
    unloadPoi: function() {
        //console.log("unloadPoi()");
        /* Check if there is a object in the DOM called mappoi (used with the POI) exists and unload the widget. */
        if ($('mappoilight')) {
            broken.visitSite.page.unLoadWidget('mappoilight');
        }

        /* Make sure that the currentPoiMarker is populated */
        if (typeof broken.visitSite.map.currentPoiMarker != 'boolean') {
            /* Use the var m as a reference to the currentPoiMarker */
            var m = broken.visitSite.map.currentPoiMarker;

            /* Check what type of POI we're handeling... */
            switch (m.typeId) {
                /* The type is a regular POIArticle (Visit calls them POI Premium) */ 
                case "1":
                    /* Find out if the icon should be tilted... */
                    switch (m.tilt) {
                        case "1": /* left */
                            /* If the poi has a valid zoomToLevel-value and the map isn't zoomed-in the image should be a icon with 'babies',  */
                            /* Otherwise, check if the zoomToLevel-value is set and use a regular icon... if not, use a image tilted to the left */
                            m.setImage(parseInt(m.zoomToLevel) > 0 && broken.visitSite.map.map.getZoom() < m.zoomToLevel ? '/UI/Images/googlemaps/p.zoomtoarea.png' : (parseInt(m.zoomToLevel) > 0 ? '/UI/Images/googlemaps/p.38.png' : '/UI/Images/googlemaps/p.38.left.png'));
                            break;
                        case "2": /* right */
                            /* If the poi has a valid zoomToLevel-value and the map isn't zoomed-in the image should be a icon with 'babies',  */
                            /* Otherwise, check if the zoomToLevel-value is set and use a regular icon... if not, use a image tilted to the right */
                            m.setImage(parseInt(m.zoomToLevel) > 0 && broken.visitSite.map.map.getZoom() < m.zoomToLevel ? '/UI/Images/googlemaps/p.zoomtoarea.png' : (parseInt(m.zoomToLevel) > 0 ? '/UI/Images/googlemaps/p.38.png' : '/UI/Images/googlemaps/p.38.right.png'));
                            break;
                        default:
                            /* If the poi has a valid zoomToLevel-value and the map isn't zoomed-in the image should be a icon with 'babies',  */
                            /* Otherwise, use a regular icon */
                            m.setImage(parseInt(m.zoomToLevel) > 0 && broken.visitSite.map.map.getZoom() < m.zoomToLevel ? '/UI/Images/googlemaps/p.zoomtoarea.png' : '/UI/Images/googlemaps/p.38.png');
                            break;
                    }
                    break;
                /* The type is a POILight (Visit calls them POI) */ 
                case "2":
                    m.setImage('/UI/Images/googlemaps/p.mini.png');
                    break;
                /* The type is a POIAccomodation (Visit calls them Accomodation) */ 
                case "6":
                    m.setImage('/UI/Images/googlemaps/p.acc.png');
                    break;
                /* The type is a POIGroup (Main cities) */ 
                case "3":
                    m.setImage('/UI/Images/googlemaps/p.big.png');
                    break;
                /* The type is a POITransportation (Airports etc) */ 
                case "4":
                    m.setImage('/UI/Images/googlemaps/p.transportation.png');
                    break;
                case "6":
                    m.setImage('/UI/Images/googlemaps/p.acc.png');
                    break;
                case "8":
                    m.setImage('/UI/Images/googlemaps/p.acc.png');
                    break;

            }

            /* Check if the marker exists, if so: reset the zIndex */
            try {
                if ($('mtgt_' + m.id))
                    $('mtgt_' + m.id).style.zIndex = m.oz;
            }
            catch (ex) { }
            /* Reset the active switch */
            m.active = false;

            /* Kill the currentPoiMarker */
            broken.visitSite.map.currentPoiMarker = false;

            /* Check if there is a object in the DOM called mappoi (used with the POIArticle) exists and unload the widget. */
            if ($('mappoi')) broken.visitSite.page.unLoadWidget('mappoi');
            /* Check if there is a object in the DOM called mappoi (used with the POI) exists and unload the widget. */
            if ($('mappoilight')) broken.visitSite.page.unLoadWidget('mappoilight');
        }
    },

    /* 
    function broken.visitSite.map.unloadPoi()
    Function is triggered when any POI-widget is closed 
    Mainly triggered from other POI-markers.
    */
    unloadPoiKeepWidget: function() {
        var m = broken.visitSite.map.currentPoiMarker;

        try {
            switch (m.typeId) {
                case "1":
                    switch (m.tilt) {
                        case "1": /* left */
                            m.setImage(parseInt(m.zoomToLevel) > 0 && broken.visitSite.map.map.getZoom() < m.zoomToLevel ? '/UI/Images/googlemaps/p.zoomtoarea.png' : (parseInt(m.zoomToLevel) > 0 ? '/UI/Images/googlemaps/p.38.png' : '/UI/Images/googlemaps/p.38.left.png'));
                            break;
                        case "2": /* right */
                            m.setImage(parseInt(m.zoomToLevel) > 0 && broken.visitSite.map.map.getZoom() < m.zoomToLevel ? '/UI/Images/googlemaps/p.zoomtoarea.png' : (parseInt(m.zoomToLevel) > 0 ? '/UI/Images/googlemaps/p.38.png' : '/UI/Images/googlemaps/p.38.right.png'));
                            break;
                        default:
                            m.setImage(parseInt(m.zoomToLevel) > 0 && broken.visitSite.map.map.getZoom() < m.zoomToLevel ? '/UI/Images/googlemaps/p.zoomtoarea.png' : '/UI/Images/googlemaps/p.38.png');
                            break;
                    }
                    break;
                case "2":
                    m.setImage('/UI/Images/googlemaps/p.mini.png');
                    break;
                case "6":
                    m.setImage('/UI/Images/googlemaps/p.acc.png');
                    break;
                case "3":
                    m.setImage('/UI/Images/googlemaps/p.big.png');
                    break;
                case "4":
                    m.setImage('/UI/Images/googlemaps/p.transportation.png');
                    break;
            }

        } catch (err) { };

        try {
            if ($('mtgt_' + m.id))
                $('mtgt_' + m.id).style.zIndex = m.oz;
        }
        catch (ex) { }

        m.active = false;
        m = false;

        broken.visitSite.map.currentPoiMarker = m;
    }
});


broken.cookie = {
    set: function(name, value, days, path, domain, secure) {
        if (days) {
            var date = new Date();
            date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
            var expires = "; expires=" + date.toGMTString();
        }
        else var expires = "";

        var curCookie = name + "=" + escape(value) +
		    ((expires) ? "; expires=" + expires : "") +
		    ((path) ? ";path=/" : ";path=/") +
		    ((domain) ? "; domain=" + domain : "") +
		    ((secure) ? "; secure" : ";");

        document.cookie = curCookie;

        return this.get(name);
    },

    get: function(name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for (var i = 0; i < ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0) == ' ') c = c.substring(1, c.length);
            if (c.indexOf(nameEQ) == 0) return unescape(c.substring(nameEQ.length, c.length));
        }
        return null;
    }

};

/* 
function broken.visitSite.page
*/
broken.visitSite.page = {

	/* 
	function broken.visitSite.page.mapOpenState()
	*/
	mapOpenState: (broken.cookie.get('ShowMap') == null ? 'true' : broken.cookie.get('ShowMap')),
	iframeIsToggled: false,

	/* 
	function broken.visitSite.page.init()
	*/
	init: function() {
		if ($('mySavedFavorites'))
			this.loadFavorites();

		this.observeQuickSearch();

		if ($('ctl00_FullRegion_MainRegion_searchForm_SearchQuery'))
			this.observeSearch();

		if ($('allItemsOnMap'))
			this.observeAllItemsOnMap();

		if ($('bookingsWrapper'))
			this.initializeBooking();

		this.initializeSWFObjects();

		this.observeLinks();
	},

	initializeSWFObjects: function() {


		if ($('ClockWithText') != null) {
			var currentTime = new Date();
			var flashvars = {
				gmt: '1',
				time: currentTime.getTime()
			};
			var params = {
				wmode: 'opaque'
			};
			var attributes = {};
			swfobject.embedSWF("/UI/Flash/ClockWithText.swf", "ClockWithText", "220", "30", "8.0.0", "expressInstall.swf", flashvars, params, attributes);
		}

		if ($('RichContentBrowser') != null) {

			var hidXmlPath = $('xmlPath').value;
			var hidSwfFilePath = $('swfFilePath').value;
			var hidShowOnMap = false;

			if ($('showOnMap') != null) {
				var hidShowOnMap = $('showOnMap').Value;
			}
			var flashvars = {
				xmlPath: hidXmlPath
			};
			var params = { wmode: 'transparent' };
			var attributes = {};
			swfobject.embedSWF(hidSwfFilePath, "RichContentBrowser", "450", "395", "8.0.0", "", flashvars, params, attributes);
		}
		if ($('StartPageFlash') != null) {
			var startFlashValues = $('startFlashValues').value.split('|');
			var startXmlPath = startFlashValues[0];
			var startSwfFilePath = startFlashValues[1];
			var startImage = startFlashValues[3];
			var startHighJackPath = startFlashValues[2];

			var flashvars = {
				xmlPath: startXmlPath,
				imagePath: startImage,
				xflashPath: startHighJackPath
			};
			var params = { wmode: 'transparent' };
			var attributes = {};
			swfobject.embedSWF(startSwfFilePath, "StartPageFlash", startFlashValues[5], startFlashValues[4], "8.0.0", "http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=6a253b75", flashvars, params, attributes, callbackFn = function(e) { if (!e.success) { $(imgFallback).style.display = "block" } });
		}


	},



	/* 
	function broken.visitSite.page.initializeBooking()
	*/
	initializeBooking: function() {

		var element = $('h2Organizer1');

		if ($('h2Organizer2').innerHTML.length > 0)
			element = $('h2Organizer2');

		if ($('h2Organizer3').innerHTML.length > 0)
			element = $('h2Organizer3');


		Event.observe($('visitTIFrame'), 'error', function(event) { alert(0); });
		Event.observe($('visitTIFrame1'), 'error', function(event) { alert(1); });
		Event.observe($('visitTIFrame2'), 'error', function(event) { alert(2); });



		broken.visitSite.page.toggleBookings(element, 'bookings', false);

		broken.util.scrollToTop(137, 0, 1);


	},

	/* 
	function broken.visitSite.page.observeLinks()
	*/
	observeLinks: function() {
		$$('a[rel="external"]').each(function(link) {
			if (link.readAttribute('href') != '' && link.readAttribute('href') != '#' && link.readAttribute('href') != 'javascript:void(0)') {
				link.writeAttribute('target', '_blank');
			}
		});
	},


	/* 
	function broken.visitSite.page.observeQuickSearch()
	*/
	observeQuickSearch: function() {
		if ($('ctl00_QuickSearch_quickSearchBox')) {
			this.quickSearchDefaultValue = $('ctl00_QuickSearch_quickSearchBox').value;

			Event.observe($('ctl00_QuickSearch_quickSearchBox'), 'focus', function(event) {
				if ($('ctl00_QuickSearch_quickSearchBox').value == broken.visitSite.page.quickSearchDefaultValue)
					$('ctl00_QuickSearch_quickSearchBox').value = '';
			});

			Event.observe($('ctl00_QuickSearch_quickSearchBox'), 'blur', function(event) {
				if ($('ctl00_QuickSearch_quickSearchBox').value == '')
					$('ctl00_QuickSearch_quickSearchBox').value = broken.visitSite.page.quickSearchDefaultValue;
			});

			Event.observe($('ctl00_QuickSearch_quickSearchBoxPost'), 'click', function(event) {
				if ($('ctl00_QuickSearch_quickSearchBox').value == broken.visitSite.page.quickSearchDefaultValue) {
					event.preventDefault();
					$('ctl00_QuickSearch_quickSearchBox').focus();
				}
			});
		}
	},


	/* 
	function broken.visitSite.page.observeSearch()
	*/
	observeSearch: function() {
		Event.observe($('ctl00_FullRegion_MainRegion_searchForm_SearchQuery'), 'keypress', function(event) {
			if (event.keyCode == Event.KEY_RETURN) {
				event.preventDefault();
				window.location.href = '/searchpage/?q=' + $('ctl00_FullRegion_MainRegion_searchForm_SearchQuery').value;
			}
		});
	},


	/* 
	function broken.visitSite.page.observeAllItemsOnMap()
	*/
	observeAllItemsOnMap: function() {
		$$('#allItemsOnMap a').each(function(item) {
			if (item.hasClassName('poi')) {

				item.observe('click', function(event) {

					event.preventDefault();
					if (broken.visitSite.page.mapOpenState != 'true')
						broken.visitSite.page.toggleMap();

					var pageId = this.id.split('|')[0];
					var coordId = this.id.split('|')[1];

					broken.visitSite.map.activateMarker(pageId);
					broken.util.scrollToTop(0);
					broken.visitSite.page.currentPoiPageId = pageId;
					//broken.visitSite.page.loadWidget('/UI/scripts/widgets/poiArticle.js');
				});
			}
		});
	},

	isBookingMaxHeight: false,

	/* 
	function broken.visitSite.page.toggleBookings()
	OverrideOpen overrides the var open otherwise we cant close all lis when we load the diffrent IFrames
	*/
	toggleBookings: function(sender, target, fastClose) {


		//console.log(sender.id)


		var l = $$('#' + target + ' li');

		var p = sender.parentNode;

		var sh = 19;
		var shAdd = 19;

		var dur = (fastClose ? 0 : 0.4);


		if (p.hasClassName('active')) {
			var isClosed = false;
		}
		else {
			var isClosed = true;
		}


		l.each(function(item) {
			if (item.hasClassName('active')) {
				new Effect.Morph(item, {
					beforeStart: function() {
						//console.log('close start ' + item.id);
					},
					duration: dur,
					style: { height: sh + 'px' },
					queue: { scope: 'sliderscope' },
					afterFinish: function() {
						item.getElementsByClassName('information')[0].style.display = 'none';
						item.removeClassName('active');
						isClosed = true;
						//console.log('close end ' + item.id);
					}
				});
			}
		});


		function doShow() {
			//console.log('doShow in' + isClosed);
			if (typeof isClosed != 'undefined' && isClosed) {

				if (!p.hasClassName('active')) {
					p.getElementsByClassName('information')[0].style.display = 'block';
					var h = sh + shAdd;

					if (broken.util.isIE)
						h += parseInt(p.getElementsByClassName('information')[0].getHeight());
					else
						h += parseInt(p.getElementsByClassName('information')[0].clientHeight);

					new Effect.Morph(p, {
						beforeStart: function() {
							p.addClassName('active');
							//console.log('open start ' + p.id);
						},
						duration: 0.7,
						style: { height: h + 'px' },
						queue: { position: 'end', scope: 'sliderscope' },
						afterFinish: function() {
							//console.log('open end ' + p.id);
						}
					});
				}

				clearInterval(si);
			}
		}


		/* Declare the interval, one call per millisecond. */
		var si = setInterval(doShow, 1);



		sender.setStyle({ backgroundImage: '' });
	},


	/*
	function broken.visitSite.page.closeAllBookings();
	*/
	closeAllBookings: function(closeTarget) {

		var lCloseTarget = $$('#' + closeTarget + ' li');
		lCloseTarget.each(function(item) {
			if (item.hasClassName('active')) {

				new Effect.Morph(item, {
					beforeStart: function() {
						//console.log('close start ' + item.id);
					},
					duration: 0.1,
					style: { height: '19px' },
					afterFinish: function() {
						item.getElementsByClassName('information')[0].style.display = 'none';
						item.removeClassName('active');
						//console.log('close end ' + item.id);
					}
				});

			}
		});
	},

	/* 
	function broken.visitSite.page.toggleEvents()
	*/
	toggleEvents: function(sender, target, closeTarget) {
		var l = $$('#' + target + ' li');
		var lCloseTarget = $$('#' + closeTarget + ' li');

		var p = sender.parentNode;

		var sh = 0;
		var shAdd = 0;

		if (target == 'startPageEvents' || target == 'contactList1' || target == 'contactList2') {
			sh = 16;
			shAdd = 19;
		}
		else {
			sh = 32;
			shAdd = 20;
		}
		//var sh = target == 'startPageEvents' ? 16 : 32;
		//var shAdd = target == 'startPageEvents' ? 19 : 20;

		if (p.hasClassName('active'))
			var open = false;
		else
			var open = true;

		lCloseTarget.each(function(item) {
			if (item.hasClassName('active')) {
				item.removeClassName('active');
				item.getElementsByClassName('information')[0].style.display = 'none';

				new Effect.Morph(item, { duration: 0.5, style: { height: sh + 'px'} });
			}
		});

		l.each(function(item) {
			if (item.hasClassName('active')) {
				item.removeClassName('active');
				item.getElementsByClassName('information')[0].style.display = 'none';

				new Effect.Morph(item, { duration: 0.5, style: { height: sh + 'px'} });
			}
		});

		if (open) {
			p.addClassName('active');
			p.getElementsByClassName('information')[0].style.display = 'block';

			var h = sh + shAdd;

			if (broken.util.isIE)
				h += parseInt(p.getElementsByClassName('information')[0].getHeight());
			else
				h += parseInt(p.getElementsByClassName('information')[0].clientHeight);


			new Effect.Morph(p, { duration: 0.5, style: { height: h + 'px'} });
		}
	},

	/* 
	function broken.visitSite.page.toggleMap()
	*/
	toggleMap: function() {
		if (this.mapOpenState == 'true') {
			if (broken.util.isIE)
				var morphStyle = { height: '0px', paddingBottom: '0px', paddingTop: '1px' };
			else
				var morphStyle = { height: '0px', paddingBottom: '0px', paddingTop: '3px' };
			this.mapOpenState = 'false';
			$('showMapLabel').show();
			$('hideMapLabel').hide();
		} else {
			if (broken.util.isIE)
				var morphStyle = { height: '442px', paddingBottom: '5px', paddingTop: '5px' };
			else
				var morphStyle = { height: '442px', paddingBottom: '7px', paddingTop: '7px' };
			this.mapOpenState = 'true';
			$('showMapLabel').hide();
			$('hideMapLabel').show();
		}

		broken.cookie.set('ShowMap', this.mapOpenState, 9999, '/', false, false);

		new Effect.Morph('map-holder', {
			duration: 0.3,
			style: morphStyle,
			afterFinish: function() {
				if (typeof broken.visitSite.map.map != 'object' && broken.visitSite.page.mapOpenState == 'true')
					broken.visitSite.map.init();
			}
		});
	},

	/* 
	function broken.visitSite.page.loadWidget()
	*/
	loadWidget: function(src) {
		//this.unLoadWidget('mappoi');

		new Ajax.Request(src, {
			method: 'get',
			evalJS: true
		});
	},

	/* 
	function broken.visitSite.page.loadPostCardWidget()
	*/
	loadPostCardWidget: function(imageId) {
		this.epslanguage = $('HiddenLanguageCode').value;
		this.storeImageId = imageId;
		this.loadWidget('/ui/scripts/widgets/postcard.js');
	},

	/* 
	function broken.visitSite.page.unLoadWidget()
	*/
	unLoadWidget: function(wrapperId) {


		var m = broken.visitSite.map.currentPoiMarker;

		if (wrapperId == 'mappoi' || wrapperId == 'mappoilight') {
			try {
				if (m != false) {
					switch (m.typeId) {
						case "1":
							switch (m.tilt) {
								case "1": // left
									m.setImage(parseInt(m.zoomToLevel) > 0 && broken.visitSite.map.map.getZoom() < m.zoomToLevel ? '/UI/Images/googlemaps/p.zoomtoarea.png' : (parseInt(m.zoomToLevel) > 0 ? '/UI/Images/googlemaps/p.38.png' : '/UI/Images/googlemaps/p.38.left.png'));
									break;
								case "2": // right
									m.setImage(parseInt(m.zoomToLevel) > 0 && broken.visitSite.map.map.getZoom() < m.zoomToLevel ? '/UI/Images/googlemaps/p.zoomtoarea.png' : (parseInt(m.zoomToLevel) > 0 ? '/UI/Images/googlemaps/p.38.png' : '/UI/Images/googlemaps/p.38.right.png'));
									break;
								default:
									m.setImage(parseInt(m.zoomToLevel) > 0 && broken.visitSite.map.map.getZoom() < m.zoomToLevel ? '/UI/Images/googlemaps/p.zoomtoarea.png' : '/UI/Images/googlemaps/p.38.png');
									break;
							}
							break;
						case "2":
							m.setImage('/UI/Images/googlemaps/p.mini.png');
							break;
						case "3":
							m.setImage('/UI/Images/googlemaps/p.big.png');
							break;
						case "4":
							m.setImage('/UI/Images/googlemaps/p.transportation.png');
							break;
					}

					m = false;
					broken.visitSite.map.currentPoiMarker.active = m;
				}
			} catch (err) { };
		}

		var w = wrapperId;

		if ($(w)) {
			if (broken.util.isIE) {
				$(w).remove();
			} else {
				new Effect.Fade(w, { duration: 0.5,
					afterFinish: function() {
						try { $(w).remove(); }
						catch (err) { }
					}
				});
			}
		}
	},

	/* 
	function broken.visitSite.page.handleZoomInPOIArticle()
	*/
	handleZoomInPOIArticle: function(zoomTo) {
		if ($('btnZoom')) {
			if (broken.googleMaps.core.isInitialized) {
				if (broken.visitSite.map.map.getZoom() >= zoomTo) {
					$('btnZoom').hide();
				}
				else {
					$('btnZoom').show();
				}
			}
			else {
				setTimeout('broken.visitSite.page.handleZoomInPOIArticle(' + zoomTo + ')', 10);
			}
		}
	},

	/* 
	function broken.visitSite.page.loadFavorites()
	*/
	loadFavorites: function() {
		$('favoritesLoader').hide();
		var index = $$('#mySavedFavorites li').length;
		var clientCookie = broken.cookie.get('favorites');
		if (clientCookie != '{}' && clientCookie != null && clientCookie != 'undefined') {
			var cookieHash = $H(clientCookie.evalJSON());
			cookieHash.each(function(cookie, c) {
				if (c % 2 == 0)
					var liProperties = Prototype.Browser.IE ? { style: 'filter: alpha(opacity: 0)', className: 'alt'} : { style: 'opacity: 0', className: 'alt' };
				else
					var liProperties = Prototype.Browser.IE ? { style: 'filter: alpha(opacity: 0)'} : { style: 'opacity: 0' };

				var aProperties = cookie.value.href.indexOf('showstaticpoi=true') == -1 ? { href: cookie.value.href} : { className: 'poi', href: cookie.value.href };

				var listItem = Builder.node('li', liProperties, [
	                Builder.node('a', aProperties, cookie.value.pageName),
	                Builder.node('span', [
	                    Builder.node('a', { href: 'javascript:void(0)', onclick: 'broken.visitSite.page.removeFavorite(this, ' + c + ')', className: 'remove' }, 'Remove')
	                ])
	            ]);
				$('mySavedFavorites').appendChild(listItem);

				new Effect.Appear(listItem);
			});

		}
	},

	/* 
	function broken.visitSite.page.saveToFavorites()
	*/
	saveToFavorites: function(sender, poiName, poiURL) {

		var bookPageId = $('HiddenBookPageId').value;

		var index = $$('#mySavedFavorites li').length;

		var pageName = typeof poiName == 'undefined' ? $('HiddenPageName').value : poiName;

		if ($('HiddenPageID').value == bookPageId) {
			var zoom = 11; //Default zoomlvl for poiAccommodation
			if ($('HiddenZoom').value != "")
				zoom = $('HiddenZoom').value;
			var cookieString = '{"cookie' + index + '":{"href": "' + $('HiddenBookUrl').value + "?pid=" + $('HiddenPoiId').value + "&tab=book&z=" + zoom + '", "pageName": "' + $('HiddenPoiName').value + '"}}';

			pageName = $('HiddenPoiName').value;

		}
		else if (typeof poiName == 'undefined') {

			var cookieString = '{"cookie' + index + '":{"href": "' + window.location.href.replace("showstaticpoi=true", "") + '", "pageName": "' + pageName + '"}}';
		}
		else
			var cookieString = '{"cookie' + index + '":{"href": "' + poiURL + '", "pageName": "' + pageName + '"}}';

		var clientCookie = broken.cookie.get('favorites');
		if (clientCookie == '{}' || clientCookie == null) {
			var hashCookie = new Hash(cookieString.evalJSON());
			var cookies = hashCookie.toJSON();
			var addListItem = true;
		} else {
			var jsonCookie = clientCookie.evalJSON();
			var hashCookie = new Hash(jsonCookie);

			var exists = false;

			hashCookie.each(function(cookie, c) {

				if (cookie.value.pageName == pageName)
					exists = true;
			});
			if (!exists) {
				var addListItem = true;
				hashCookie = hashCookie.merge(cookieString.evalJSON());
				var cookies = hashCookie.toJSON();
			} else {
				var addListItem = false;
			}
		}

		if (addListItem) {
			broken.cookie.set('favorites', cookies, 9999, '/', false, false);
			var h = hashCookie.get('cookie' + index).href;
			var n = hashCookie.get('cookie' + index).pageName;

			if (hashCookie.get('cookie' + index).poiId)
				var sPoiId = hashCookie.get('cookie' + index).poiId;

			if (index % 2 == 0)
				var liProperties = Prototype.Browser.IE ? { style: 'filter: alpha(opacity: 0)', className: 'alt'} : { style: 'opacity: 0', className: 'alt' };
			else
				var liProperties = Prototype.Browser.IE ? { style: 'filter: alpha(opacity: 0)'} : { style: 'opacity: 0' };

			var aProperties = h.indexOf('showstaticpoi=true') == -1 ? { href: h} : { className: 'poi', href: h };

			var listItem = Builder.node('li', liProperties, [
	            Builder.node('a', aProperties, n),
	            Builder.node('span', [
	                Builder.node('a', { href: 'javascript:void(0)', onclick: 'broken.visitSite.page.removeFavorite(this, ' + index + ')', className: 'remove' }, 'Remove')
	            ])
	        ]);
			$('mySavedFavorites').appendChild(listItem);

			new Effect.Appear(listItem);
		}

		if (broken.visitSite.map.currentPageID != bookPageId)
			Effect.Fade(sender.id, { duration: 0.2 });


	},

	/* 
	function broken.visitSite.page.removeFavorite()
	*/
	removeFavorite: function(sender, index) {
		var clientCookie = broken.cookie.get('favorites');
		var cookieHash = $H(clientCookie.evalJSON());
		var hashCookie = new Hash();

		cookieHash.unset('cookie' + index);
		cookieHash.each(function(item, index) {
			hashCookie.set('cookie' + index, item.value);
		});
		var cookies = hashCookie.toJSON();

		broken.cookie.set('favorites', cookies, 9999, false, false, false);
		new Effect.DropOut(sender.parentNode.parentNode, { afterFinish:
	        function() {
	        	$(sender.parentNode.parentNode).remove();

	        	$$('#mySavedFavorites li').each(function(item, index) {
	        		var newClassName = index % 2 == 0 ? 'alt' : '';
	        		item.className = newClassName;
	        	});
	        }
		});
	},

	/* 
	function broken.visitSite.page.loadFavoriteWidget()
	*/
	loadFavoriteWidget: function(poiId) {
		broken.visitSite.page.currentPoiPageId = poiId;
		broken.visitSite.page.loadWidget('/UI/scripts/widgets/poiArticle.js');
		if (this.mapOpenState != 'true') {
			this.toggleMap();
		}
		broken.util.scrollToTop(0);
	},

	/* 
	function broken.visitSite.page.loadPhoto()
	*/
	loadPhoto: function(id) {
		this.epslanguage = $('HiddenLanguageCode').value;
		this.rcbPhotoId = id;
		this.loadWidget('/UI/scripts/widgets/viewphoto.js');
	},

	/* 
	function broken.visitSite.page.loadPostCard()
	*/
	loadPostCard: function() {
		this.storeImageId = arguments[0].split(',')[0];
		this.epslanguage = arguments[0].split(',')[3];
		this.loadWidget('/ui/scripts/widgets/postcard.js');
	},

	/* 
	function broken.visitSite.page.showPhotoOnMap()
	*/
	showPhotoOnMap: function(lat, lng, zoom) {
		if (this.mapOpenState != 'true') {
			this.toggleMap();
		}

		broken.visitSite.map.addPhotoMarker(lat, lng, zoom);
		broken.util.scrollToTop(0);
	},

	//Tor Andersson adds for translate after showPhotoOnMap

	/*
	function broken.visitSite.page.showTextOnMap()
	*/
	showTextOnMap: function(lat, lng, zoom) {
		if (this.mapOpenState != 'true') {
			this.toggleMap();
		}

		broken.visitSite.map.addTextMarker(lat, lng, zoom);
		broken.util.scrollToTop(0);
	},

	/* 
	function broken.visitSite.page.translater()
	*/
	translater: function() {

		var container = document.getElementById("bottomslider");
		//alert(container.innerHTML);

		google.language.translate(container.innerHTML, "en", "fr", function(result) {

			if (!result.error) {

				container.innerHTML = result.translation;
			}
		});
		return true;
	},

	/* 
	function broken.visitSite.page.setCursor()
	Function to handle a cursors destiny a x-browser way.
	*/
	setCursor: function(dom, remove) {
		/* Should we remove it? */
		if (remove) {
			/* Set the cursor to 'default' */
			dom.style.cursor = 'default';
		}
		/* Show it! */
		else {
			/* Since FF throws errors with cursor:hand; we handle it here. */
			/* Is the browser IE?*/
			if (document.all) {
				/* Set the cursor to 'hand' */
				dom.style.cursor = 'hand';
			}
			else {
				/* Set the cursor to 'pointer' */
				dom.style.cursor = 'pointer';
			}
		}
	},

	/* 
	function broken.visitSite.page.sentPostCard()
	*/
	sentPostCard: function() {
		var postBodyExtra = '';

		if ($('FriendEmail2').value == c9.visitSite.sendToFriend.sFriendsEmail) {
			$('FriendName2').value = '';
			$('FriendEmail2').value = '';
		}

		if ($('FriendEmail3').value == c9.visitSite.sendToFriend.sFriendsEmail) {
			$('FriendName3').value = '';
			$('FriendEmail3').value = '';
		}
		if (!$('ReceiveCopy').checked) postBodyExtra += '&ReceiveCopy=';
		if (!$('NewsletterSignup').checked) postBodyExtra += '&NewsletterSignup=';

		$('postCardForm').MailBody.value = $('postCardForm').MailBody.value.replace(/\n/g, '<br />');

		var sPostCard = $('postCardForm').serialize();
		new Ajax.Request('/UI/services/Postcard.asmx/SendMail', {
			postBody: sPostCard + postBodyExtra,
			onSuccess: function(response) {
				broken.widgetCollection.activeWidget.closeWidget();
			}
		});
	},
	/*
	function broken.visitSite.page.switchTempAndCookie()
	*/
	switchTempAndCookie: function(sender, tempType) {
		if (tempType == 'C') {
			$('lblFToday', 'lblFDay1', 'lblFDay2', 'lblFDay3', 'lblFDay4', 'lblFDay5').invoke('hide');
			$('lblCToday', 'lblCDay1', 'lblCDay2', 'lblCDay3', 'lblCDay4', 'lblCDay5').invoke('show');
			$('aCelsius').removeClassName('active');
			$('aFahrenheit').removeClassName('border');
			$('aCelsius').addClassName('border');
			$('aFahrenheit').addClassName('active');
			broken.cookie.set('visitswedentemp', 'C', 9999, '/', false, false);
		}
		else if (tempType == 'F') {
			$('lblFToday', 'lblFDay1', 'lblFDay2', 'lblFDay3', 'lblFDay4', 'lblFDay5').invoke('show');
			$('lblCToday', 'lblCDay1', 'lblCDay2', 'lblCDay3', 'lblCDay4', 'lblCDay5').invoke('hide');
			$('aCelsius').removeClassName('border');
			$('aFahrenheit').removeClassName('active');
			$('aCelsius').addClassName('active');
			$('aFahrenheit').addClassName('border');
			broken.cookie.set('visitswedentemp', 'F', 9999, '/', false, false);
		}
	}

};

broken.widgetCollection = Class.create();
    broken.widgetCollection.poiArticle = {

    /* The width of the text columns. */
    diff: 218,
    /* The height of the column divs */
    divHeight: 135,
    /* The number of characters to start looking for spaces in (lastIndexOf(' ') ). */
    charCount: 400,
    /* The temporary string used when parsing the innerHTML into the columns. */
    tempString: "",

    /* 
    function broken.widgetCollection.poiArticle.parseText()
    Parameter string text = The text of the POI-Article
    Used to parse text into the textcolumns.
    */
    parseText: function(text) {
        /* Set the itteration counter to 0. */
        var iter = 0;

        /* Set the initial value of the text into theis splittable variable. */
        text = text.unescapeHTML();

        /* Replace all whitespace with spacesigns.*/
        var textSplitable = text.replace(/^\s*/, "").replace(/\s*$/, "") + ' ';

        /* Set the initial style.left value of the parsed textcolumns. */
        var left = 0;

        /* Itterate through the text blocks, one block is charCount long. */
        for (i = 0; i <= Math.floor(text.length / this.charCount); i++) {
            /* Set the current block of text */
            var textCurrent = textSplitable.substring(0, this.charCount);
            /* Set the current block of text to end with the last space found. */
            textCurrent = textCurrent.substring(0, textCurrent.lastIndexOf(' '));

            /* Populate the splittable variable with the leftovers. */
            textSplitable = textSplitable.substring(textCurrent.lastIndexOf(' ') + 1, textSplitable.length);

            /* Remove the leading word. (it can be found in the end of the textCurrent variable) */
            textSplitable = textSplitable.substring(textSplitable.indexOf(' '), textSplitable.length);

            /* Find the new left value */
            left = (i * this.diff);

            /* Check that the textCurrent isnt empty. */
            if (textCurrent != "") {
                /* Parse the new textcolumn. */
                $('bottomslider').appendChild(Builder.node('div', { id: 'text' + i, className: 'poitext', style: ('left:' + left + 'px') }, textCurrent));
            }

            /* Set the tempString to empty. */
            this.tempString = "";
            /* Set the textSplittable via the checkDivHeight-functioncall. */
            textSplitable = this.checkDivHeight('text' + i) + textSplitable;

            /* Add one to the iterator. */
            iter++;
        }

        /* Check that the textSplittabe isnt empty.  */
        if (textSplitable.length > 1) {
            /* Add another columndiv to the POI. */
            $('bottomslider').appendChild(Builder.node('div', { id: 'text' + iter, className: 'poitext', style: ('left:' + iter * this.diff + 'px') }, textSplitable));
            /* Add one to the iterator. */
            iter++;
        }

        /* Check that the itterator isnt in the first two cols. */
        if (iter > 2) {
            /* Hide the slideRightLink. */
            $('slideRightLink').style.visibility = 'visible';
        }
    },


    /* 
    function broken.widgetCollection.poiArticle.checkDivHeight()
    Parameter string divId = the id of the div to check.
    Returns the contents of the div that fits in the fitted collumn.
    Function used in the calculation of the columns in the POI-Article texts.
    */
    checkDivHeight: function(divId) {
        /* Declare the return variable. */
        var r = "";
        /* Check if the height exceeds the set height. */
        if ($(divId).getHeight() > this.divHeight) {
            /* Set r to the innerHTML of the div.  */
            r = $(divId).innerHTML;
            /* Set the innerHTML of the div to the r variables last instande of a spacesign. */
            $(divId).innerHTML = r.substring(0, r.lastIndexOf(' '));
            /* Pass everything after the last instande of a spacesign back to r. */
            r = r.substring(r.lastIndexOf(' '), r.length);

            /* Set the temporary string to pass back to the return. */
            this.tempString = r + this.tempString;
            /* Call the function again. */
            this.checkDivHeight(divId);
        }

        /* Repopulate the r with the temporarry string. */
        r = this.tempString; ;

        /* Return r back to the caller.*/
        return r;
    },


    /* 
    function broken.widgetCollection.poiArticle.doSlide()
    Parameter string direction = the direction of the slider - what way to slide.
    Function used to slide the contents of the POI widgets.
    */
    doSlide: function(direction) {

        /* Set the initial style.left of the containing div. */
        var left = 0;
        /* The width of the text columns. */
        var diff = 218;

        /* Set the total width of the containing div. scrollWidth wont work since the div contained is absolute positioned */
        var width = (parseInt($$('.poitext').length) * diff);

        /* Is the current left set? */
        if ($('bottomslider').style.left.length > 0) {
            /* Set the current left of the containing div. */
            left = $('bottomslider').style.left.substring(0, $('bottomslider').style.left.lastIndexOf('px'));
        }

        /* Check the direction - Left. */
        if (direction == 'left') {
            /* Check if we're supposed to slide left. */
            if (parseInt(left) - parseInt(diff) < -diff) {
                /* Update style.left of the containing div */
                new Effect.Morph('bottomslider', {
                    /* Set the duration of the morph. */
                    duration: 0.5,
                    /* Set the style. */
                    style: { left: parseInt(left) + parseInt(diff) + 'px' },
                    /* Execute when finished. */
                    afterFinish: function() {
                        /* Update the left variable with the new current style.left of the container. */
                        left = $('bottomslider').style.left.substring(0, $('bottomslider').style.left.lastIndexOf('px'));

                        /* Handle the links. */
                        /* Is there more to slide in the left direction? */
                        if (parseInt(left) - parseInt(diff) < -diff) {
                            /* Show the left link */
                            $('slideLeftLink').style.display = 'block';
                            /* Set the left-link to the proper cursor, hand/pointer. */
                            broken.visitSite.page.setCursor($('slideLeftLink'));
                        }
                        /* Are we max left? */
                        else {
                            /* Hide the left link */
                            $('slideLeftLink').style.display = 'none';
                            /* Set the left-link to the proper cursor, hand/pointer. */
                            broken.visitSite.page.setCursor($('slideLeftLink'), true);
                        }

                        /* Show the right link */
                        $('slideRightLink').style.visibility = 'visible';
                        /* Set the right-link to the proper cursor, hand/pointer. */
                        broken.visitSite.page.setCursor(document.getElementById('slideRightLink'));
                    }
                });
            }
        }
        /* Check the direction - Right. */
        else {
            /* Check if we're supposed to slide right. */
            if (-parseInt(left) + (parseInt(diff) * 2) < parseInt(width)) {
                /* Update style.left of the containing div */
                new Effect.Morph('bottomslider', {
                    /* Set the duration of the morph. */
                    duration: 0.5,
                    /* Set the style. */
                    style: { left: parseInt(left) - parseInt(diff) + 'px' },
                    /* Execute when finished. */
                    afterFinish: function() {
                        /* Update the left variable with the new current style.left of the container. */
                        left = $('bottomslider').style.left.substring(0, $('bottomslider').style.left.lastIndexOf('px'));

                        //                        if ((parseInt(left) + parseInt(diff) > -(parseInt(left) + parseInt(width) - (parseInt(diff) * 2)))) {
                        if (-parseInt(left) + (parseInt(diff) * 2) < parseInt(width)) {
                            /* Show the right link */
                            $('slideRightLink').style.visibility = 'visible';
                            /* Set the right-link to the proper cursor, hand/pointer. */
                            broken.visitSite.page.setCursor($('slideRightLink'));
                        }
                        else {
                            /* Show the right link */
                            $('slideRightLink').style.visibility = 'hidden';
                            /* Set the right-link to the proper cursor, hand/pointer. */
                            broken.visitSite.page.setCursor($('slideRightLink'), true);
                        }

                        /* Show the left link */
                        $('slideLeftLink').style.display = 'block';
                        /* Set the left-link to the proper cursor, hand/pointer. */
                        broken.visitSite.page.setCursor($('slideLeftLink'));
                    }
                });
            }
        }
    }


};

broken.widget = Class.create();
broken.widget.prototype = {

    /* 
    function broken.prototype.initialize()
    Function used to initialize the class.
    */
    initialize: function() {
        /* Fetch all arguments */
        this.arguments = arguments[0];

        /* Itterate through the arcuments.widgets collection*/
        for (var x in this.arguments.widgets) {
            /* Set the current id to the active widget id. */
            this.id = this.arguments.widgets[x].id;
            /* Set the current target to the active widget target. */
            this.target = this.arguments.widgets[x].target;

            /* Check if the widgetLoader doesnt exist? */
            if (!$('widgetLoader') && this.target == 'widgetLoader') {
                /* Call the createWidgetLoader */
                this.createWidgetLoader();
            }

            /* Check if the current widget.id exist. */
            if (typeof broken.widgetCollection[this.id] == 'undefined') {
                /* Set the current widget to the active widget. */
                this.widget = this.arguments.widgets[x];
                /* Set the styles from the active widget. */
                this.applyStyleSheets(this.arguments.widgets[x].style);
                /* Populate the html from the active widget. */
                this.loadHtml(this.arguments.widgets[x].html);
            }
            /* The active widget exist in the collection. */
            else {
                /* Populate the html from the active widget. */
                $(this.target).innerHTML = broken.widgetCollection[this.id].html;
                /* Does the onSuccess event exist? */
                if (typeof this.arguments.onSuccess == 'function') {
                    /* Call the event */
                    this.arguments.onSuccess();
                }
            }
        }
    },

    /* 
    function broken.prototype.createWidgetLoader()
    Function used to build the HTML of the widgetLoader.
    */
    createWidgetLoader: function() {
        /* Build the div called 'widgetLoader' */
        $$('body')[0].appendChild(Builder.node("div", { id: 'widgetLoader', className: 'widgetWrapper' }));
        /* Set the proper height of the div. */
        $('widgetLoader').style.height = $$('html')[0].scrollHeight + 'px';
    },

    /* 
    function broken.prototype.applyStyleSheets()
    Parameter string url = the href to the widget.
    Function used to add rel=stylesheet to the url-link.
    */
    applyStyleSheets: function(url) {
        /* Declare the add variable. */
        var add = true;

        /* Itterate through all links in the head. */
        $$("head link").each(function(item) {
            /* Check if the current item is the url. */
            if (item.url == url) {
                /* Set the add variable to false. */
                add = false;
            }
        });

        /* Should we add the url? */
        if (add) {
            /* Add HTML to the link. */
            $$('head')[0].appendChild(Builder.node("link", {
                /* Set the href to url. */
                href: url,
                /* Set the rel to 'stylesheet' */
                rel: 'stylesheet'
            }));
        }
    },

    /* 
    function broken.prototype.loadHtml()
    Parameter string src = the fully qualified path to the widget.
    Function used to load HTML into widgets.
    */
    loadHtml: function(src) {
        /* Declare _this and populate it with the current this. */
        var _this = this;
        /* Make the AJAX-call with the param src.*/
        new Ajax.Request(src, { method: 'get', evalScripts: true, onSuccess: _this.onLoaded.bind(this) });
    },

    /* 
    function broken.prototype.onLoaded()
    Parameter object transport = the transport from the AJAX-call
    Function used to handle the onLoaded event in a AJAX-call.
    */
    onLoaded: function(transport) {
        /* Check if the target exists in the current this. */
        if ($(this.target)) {
            /* Set the targets innerHTML to the responseText. */
            $(this.target).innerHTML = transport.responseText;
        }
        /* No target exists, use 'poiWrapper' instead. */
        else if ($('poiWrapper')) {
            /* Set the 'poiWrapper' innerHTML to the responseText. */
            $('poiWrapper').innerHTML = transport.responseText;
        }

        /* Set the current this html to the responsetext. */
        this.html = transport.responseText;

        /* Does the onSuccess function exist in the current this arguments? */
        if (typeof this.arguments.onSuccess == 'function') {
            /* Execute the event */
            this.arguments.onSuccess();
        }

        /* Add the current this to the widgetcollection. */
        broken.widgetCollection[this.id] = this;
        /* Make the current widget active. */
        broken.widgetCollection.activeWidget = this;

        /* GoogleAnalytics Added by Tor */
        /* Does the pageTracker Exist and does any of the poiwrappers exist? */
        if (pageTracker != null && ($('mappoi') || $('mappoilight'))) {
            /* Add the pagename to the tracker. */
            pageTracker._trackPageview($('hidden_pageName').value);
        }
    },

    /* 
    function broken.prototype.closeWidget()
    Function is called to remove any widgets/widgetLoaders from the page. 
    Used with the postcardwidget etc.
    */
    closeWidget: function() {
        /* is the browser IE? */
        if (broken.util.isIE) {
            /* Remove the widgetLoader */
            $('widgetLoader').remove();
        } else {
            /* Start the effect fade. */
            new Effect.Fade(this.id, { duration: 0.5,
                /* When finished: */
                afterFinish: function() {
                    /* Remove the widgetLoader */
                    $('widgetLoader').remove();
                }
            });
        }
    }
};


/* 
namespace broken.util
Genereal functions/methods to handle data. 
*/
broken.util = {
    /* Variable used to determine if the browser is Internet Explorer. */
    isIE: Prototype.Browser.IE,
    /* Variable used to determine if the browser is Internet Explorer version 6.x. */
    isIE6: !!(typeof document.body.style.maxHeight == 'undefined' && Prototype.Browser.IE),
    /* Variable used to determine if the browser is Internet Explorer version 7.x. */
    isIE7: !!(typeof document.body.style.maxHeight != 'undefined' && Prototype.Browser.IE),
    /* Variable used to determine if the page and scripts are fully loaded. */
    isLoaded: false,

    /* 
    function broken.util.isEnter()
    Parameter event event = the keypress event.
    Function is called to determine if a event-keypress is ENTER-key.
    Used from input-fields on the page, ie: the search-fields.
    Returns a boolean, true if the key pressed was ENTER.
    */
    isEnter: function(event) {
        /* Return the tested key. */
        return (event.keyCode == Event.KEY_RETURN);
    },

    /* 
    function broken.util.scrollToTop()
    Parameter int target = the pixel value from the pages top the scroller should stop at.
    Parameter int offset = the pixel-offset value from the pages top.
    Parameter int direction = 0 for up, 1 for down.
    Function to scroll the page to the top.
    */
    scrollToTop: function(target, offset, direction) {
        /* Declare the variable t, n pixles from the top. Populate it with fallback if undefined. */
        var t = typeof target == 'undefined' ? 0 : target;
        /* Declare the variable scrollY with the viewports offset top. */
        var offset = typeof offset == 'undefined' ? 0 : offset;
        var direction = typeof direction == 'undefined' ? 0 : direction;
        var scrollY = document.viewport.getScrollOffsets().top;

        /* Declare the variable ppms, pixles per millisecond. Determines the speed of the scroller. */
        var ppms = 30;

        /* sub-function used to scroll ppms pixtels. */
        function doScrollY() {
            /* Declare the variable used to determine the current viewport top. */
            var scrollY = document.viewport.getScrollOffsets().top - offset;


            if (direction == 0) {
                /* Test if the viewport should be scrolled.  */
                if (scrollY > t) {
                    /* Scroll the viewport up. The speed is based on the ppms variable */
                    scrollBy(0, (scrollY - (scrollY + ppms)));
                }
                else {
                    /* Clear the interval/Stop the scrolling */
                    clearInterval(si);
                }
            }
            else {
                /* Test if the viewport should be scrolled.  */
                if (scrollY < t) {
                    /* Scroll the viewport up. The speed is based on the ppms variable */
                    scrollBy(0, (scrollY + (scrollY + ppms)));
                }
                else {
                    /* Clear the interval/Stop the scrolling */
                    clearInterval(si);
                }
            }
        }

        /* Declare the interval, one call per millisecond. */
        var si = setInterval(doScrollY, 1);
    },

    /* 
    function broken.util.trim()
    Parameter string str = the string thats supposed to be trimmed.
    Returns = trimmed string.
    Used to trim strings (remove leading and tailing whitespaces)
    */
    trim: function(str) {
        /* Return the trimmed string, string if modified with regexp. */
        return str.replace(/^\s+/, "").replace(/\s+$/, '');
    },

    /* 
    function broken.util.encode()
    Parameter string string = the string to be encoded.
    Return = the encoded string.
    Function used as a sluice to the private encoding method.
    */
    encode: function(string) {
        /* Return the encoded string, fetched from the private encoding method. */
        return escape(this._utf8_encode(string));
    },


    /* 
    function broken.util.decode()
    Parameter string string = the string to be decoded.
    Return = the decoded string.
    Function used as a sluice to the private decoding method.
    */
    decode: function(string) {
        /* Return the decoded string, fetched from the private decoding method. */
        return this._utf8_decode(unescape(string));
    },

    /* 
    function broken.util._utf8_encode()
    Parameter string string = the string to be encoded.
    Return = the encoded string.
    Function used to encode strings.
    */
    _utf8_encode: function(string) {
        /* Clean the the string */
        string = string.replace(/\r\n/g, "\n");
        /* Declare a empty variable to be used with the return. */
        var utftext = "";

        /* Itterate through the strings characters. */
        for (var n = 0; n < string.length; n++) {
            /* Declare a variable for the active character. */
            var c = string.charCodeAt(n);

            /* Test if the character is ASCII (one bit per character). */
            if (c < 128) {
                /* Add the unmodified character to the return string */
                utftext += String.fromCharCode(c);
            }
            /* Else - test if the character is ANSI (two bits per character). */
            else if ((c > 127) && (c < 2048)) {
                /* Move the character bits. */
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            /* Else - The character is extended ANSI (three bits per character). */
            else {
                /* Move the character bits. */
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }
        }
        /* Return the encoded string. */
        return utftext;
    },

    /* 
    function broken.util._utf8_decode()
    Parameter string utftext = the string to be decoded.
    Return = the decoded string.
    Function used to decode UTF-8-encoded strings.
    */
    _utf8_decode: function(utftext) {
        /* Declare a empty variable to be used with the return. */
        var string = "";
        /* Declarare the starting position */
        var i = 0;
        /* Declare character variables. */
        var c = c1 = c2 = 0;

        while (i < utftext.length) {
            /* Populate the c-variable with the current character. */
            c = utftext.charCodeAt(i);

            /* Test if the character is ASCII (one bit per character). */
            if (c < 128) {
                /* Add the character to the return string. */
                string += String.fromCharCode(c);
                /* Add one to the itterator. */
                i++;
            }
            /* Else - test if the character is ANSI (two bits per character). */
            else if ((c > 191) && (c < 224)) {
                /* Populate the c2-variable with the next character. */
                c2 = utftext.charCodeAt(i + 1);
                /* Add the characters to the return string. */
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                /* Add two to the itterator. */
                i += 2;
            }
            /* Else - The character is extended ANSI (three bits per character). */
            else {
                /* Populate the c2-variable with the next character. */
                c2 = utftext.charCodeAt(i + 1);
                /* Populate the c3-variable with the second-next character. */
                c3 = utftext.charCodeAt(i + 2);
                /* Add the characters to the return string. */
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                /* Add three to the itterator. */
                i += 3;
            }
        }

        /* Return the decoded string. */
        return string;
    },

    /* Variable to be used with the debugging timer. */
    time: 0,

    /* 
    function broken.util.timeNow()
    Return = the current time.
    Function to get the current time.
    */
    timeNow: function() {
        /* Return the current time. */
        return (new Date()).getTime();
    },

    /* 
    function broken.util.timerStart()
    Function to start the timer.
    */
    timerStart: function() {
        /* Update the time-variable with the current time. */
        this.time = this.timeNow();
    },



    /* 
    function broken.util.timeNow()
    Return = the current tick (difference between the start and the current time).
    Function to tick the debugging timer..
    */
    timerSince: function() {
        /* Return the defferential between the initialization and the current time. */
        return this.timeNow() - this.time;
    }
},

Array.prototype.randomize = function() {
    var i = this.length;
    if (i == 0) return;
    while (--i) {
        var j = Math.floor(Math.random() * (i + 1));
        var tmp1 = this[i];
        var tmp2 = this[j];
        this[i] = tmp2;
        this[j] = tmp1;
    }
    return this;
}


Event.observe(window, 'load', function(event) {
    /* Initialize the broken.visitSite.map. */
    broken.visitSite.map.init();
    /* Initialize the broken.visitSite.page */
    broken.visitSite.page.init();

    /* Set the broken.util.isLoaded - used to determine that the scripts are fully loaded. */
    broken.util.isLoaded = true;
    enableTooltips();
});

/*javascript for Bubble Tooltips by Alessandro Fulciniti
- http://pro.html.it - http://web-graphics.com */

function enableTooltips(id) {
    var links, i, h;
    if (!document.getElementById || !document.getElementsByTagName) return;
    AddCss();
    h = document.createElement("span");
    h.id = "btc";
    h.setAttribute("id", "btc");
    h.style.position = "absolute";
    document.getElementsByTagName("body")[0].appendChild(h);
    if (id == null) links = document.getElementsByClassName("coords");
    else links = document.getElementById(id).getElementsByClassName("coords");
    for (i = 0; i < links.length; i++) {
        Prepare(links[i]);
    }
}


function Prepare(el) {
    var tooltip, t, b, s, l;
    t = el.getAttribute("title");
    if (t == null || t.length == 0) t = "link:";
    el.removeAttribute("title");
    tooltip = CreateEl("span", "tooltip");
    s = CreateEl("span", "top");
    s.appendChild(document.createTextNode(t));
    tooltip.appendChild(s);
    b = CreateEl("b", "bottom");
    l = el.getAttribute("href");
    //b.appendChild(document.createTextNode(l));
    tooltip.appendChild(b);
    //setOpacity(tooltip);
    el.tooltip = tooltip;
    el.onmouseover = showTooltip;
    el.onmouseout = hideTooltip;
    el.onmousemove = Locate;
}

function showTooltip(e) {
    document.getElementById("btc").appendChild(this.tooltip);
    Locate(e);
}

function hideTooltip(e) {
    var d = document.getElementById("btc");
    if (d.childNodes.length > 0) d.removeChild(d.firstChild);
}

function setOpacity(el) {
    el.style.filter = "alpha(opacity:95)";
    el.style.KHTMLOpacity = "0.95";
    el.style.MozOpacity = "0.95";
    el.style.opacity = "0.95";
}

function CreateEl(t, c) {
    var x = document.createElement(t);
    x.className = c;
    x.style.display = "block";
    return (x);
}

function AddCss() {
    var l = CreateEl("link");
    l.setAttribute("type", "text/css");
    l.setAttribute("rel", "stylesheet");
    l.setAttribute("href", "/UI/Styles/bt.css");
    l.setAttribute("media", "screen");
    document.getElementsByTagName("head")[0].appendChild(l);
}

function Locate(e) {
    var posx = 0, posy = 0;
    if (e == null) e = window.event;
    if (e.pageX || e.pageY) {
        posx = e.pageX; posy = e.pageY;
    }
    else if (e.clientX || e.clientY) {
        if (document.documentElement.scrollTop) {
            posx = e.clientX + document.documentElement.scrollLeft;
            posy = e.clientY + document.documentElement.scrollTop;
        }
        else {
            posx = e.clientX + document.body.scrollLeft;
            posy = e.clientY + document.body.scrollTop;
        }
    }
    document.getElementById("btc").style.top = (posy + 10) + "px";
    document.getElementById("btc").style.left = (posx - 20) + "px";
}

var streetview = Class.create();
streetview.core = {
	extStreetviewControl: null,
	streetViewToggled: false,

	toggleStreetView: function(sender, latitude, longitude, maxZoom, minZoom, currZoom, yaw, pitch) {
		if ($('pano').style.display == "none") {
			$(sender).innerHTML = "View info";
		} else {
			$(sender).innerHTML = "Street view";
		}

		if ($('btnZoom') != null && $('btnZoom').visible()) {
			$('btnZoom').toggle();
		}

		$('pano').toggle();
		$('poiarticlewrapper').toggle();

		streetview.core.loadStreetView(latitude, longitude, yaw, pitch);
		return false;
	},

	loadStreetViewFromCategory: function() {


		if (this.extStreetviewControl != null) {
			if (this.streetViewToggled == true) {
				return;
			}
		}

		var m = broken.visitSite.map.map;

		var t_lat = m.getCenter().lat();
		var t_lng = m.getCenter().lng();
		var t_yaw = 0;
		var t_pitch = 0;

		var zoom = 14;

		if (zoom < m.getZoom())
			zoom = m.getZoom();

		var point = this.calculateMarkerOffset(t_lat, t_lng, zoom, 0);

		broken.visitSite.map.gotoPoint(point.y, point.x, zoom);

		myPOV = { yaw: t_yaw, pitch: t_pitch };
		var opts = { latlng: new GLatLng(t_lat, t_lng), pov: myPOV, features: { streetView: true, userPhotos: false} };

		if (this.extStreetviewControl != null) {

			this.extStreetviewControl.update(opts, m);
		}
		else {
			this.extStreetviewControl = new ExtStreetviewControl(opts);

			broken.visitSite.map.map.addControl(this.extStreetviewControl);
			this.extStreetviewControl.markerClick_();
			this.mapIsMoved = true;
		}

	},

	loadStreetView: function(latitude, longitude, yaw, pitch) {

		var m = broken.visitSite.map.map;

		var zoom = 14;

		if (zoom < m.getZoom())
			zoom = m.getZoom();


		var point = this.calculateMarkerOffset(latitude, longitude, zoom, 100);
		broken.visitSite.map.gotoPoint(point.y, point.x, zoom);

		myPOV = { yaw: yaw, pitch: pitch };

		var opts = {
			latlng: new GLatLng(latitude, longitude),
			pov: myPOV,

			features: {
				streetView: true,
				userPhotos: true
			}

		};

		if (this.extStreetviewControl != null) {
			this.extStreetviewControl.update(opts, broken.visitSite.map.map);
		}
		else {
			this.extStreetviewControl = new ExtStreetviewControl(opts);
			broken.visitSite.map.map.addControl(this.extStreetviewControl);
			$('ctl00_FullRegion_MapRegion_MapControl_aStreetView').addClassName('active8');
			this.toggleShowMarker();
		}
	},

	//We want to place the marker so the widget is displayed 100 pixels to the left
	calculateMarkerOffset: function(lat, lng, z, pixels_off) {
		var m = broken.visitSite.map.map;
		var pixels = m.getCurrentMapType().getProjection().fromLatLngToPixel(new GLatLng(lat, lng), z);

		var _y = pixels.y;
		var _x = parseInt(pixels.x - pixels_off);
		var point = m.getCurrentMapType().getProjection().fromPixelToLatLng(new GPoint(_x, _y), z);

		return point;
	},



	toggleShowMarker: function() {
		var off = this.streetViewToggled;
		try {
			streetview.core.extStreetviewControl.toggleShowMarker(off);
		} catch (e) {
			alert(e);
		}

		if (!off) {
			this.streetViewToggled = true;
		}
		else {

			this.streetViewToggled = false;
			if ($('mappoi') != null) {
				$('mappoi').remove();
			}
		}
	},

	isSteetViewToggled: function() {
		return this.streetViewToggled;
	},


	getStreetViewControl: function() {
		return this.extStreetviewControl;

	}



};

