// $Id: map.inc.js,v 1.4 2006/11/10 22:04:55 gaby Exp $

function MapClass()
{
 var map;
 var baseIcon;
 var lasttrace;
 
// var debug = true;
// var debugid = "info";

 var trackbackurl = "";
 
 this.geturlproperties = geturlproperties;
 this.itemclic = itemclic;
 this.processXMLnode = processXMLnode;
 this.processrequest = processrequest;
 this.modified = modified;
 this.moved = moved;
 this.zoomed = zoomed;
 this.initmap = initmap;
 this.addMarker = addMarker;
 this.processxmlDoc = processxmlDoc;
 this.loadPoint = loadPoint;

 //HTML Control.js kode
function HtmlControl(_1,_2){this.html=_1;this.isVisible=true;this.isPrintable=false;this.isSelectable=false;if(_2){this.isVisible=(_2.visible===false)?false:true;this.isPrintable=(_2.printable===true)?true:false;this.isSelectable=(_2.selectable===true)?true:false;}}HtmlControl.prototype=new GControl();HtmlControl.prototype.initialize=function(_3){this.div=document.createElement("div");this.div.innerHTML=this.html;this.setVisible(this.isVisible);_3.getContainer().appendChild(this.div);return this.div;};HtmlControl.prototype.getDefaultPosition=function(){return new GControlPosition(G_ANCHOR_TOP_LEFT,new GSize(7,7));};HtmlControl.prototype.selectable=function(){return this.isSelectable;};HtmlControl.prototype.printable=function(){return this.isPrintable;};HtmlControl.prototype.setVisible=function(_4){this.div.style.display=_4?"":"none";this.isVisible=_4;};HtmlControl.prototype.visible=function(){return this.isVisible;};

//extmaptypecontrol.js kode
//eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('8 z(a){q.E=a||{}}z.l=o 2l();z.l.18=8(d){6 e=q;6 f=n.s("x");6 g;p(e.E.2m){6 h=d.19();6 j=e.1o(d);t.1a(d,"2n",8(){6 a=d.19();6 b=a.2o();6 c=e.W(b.1b());c.K(\'P\',b.1H());h.X(b);j.X(c);e.1c(d,j);f.9(c)});t.1a(d,"2p",8(){u(6 i=0;i<j.r;i++){t.2q(j[i],"F");f.2r(j[i])}j=e.1o(d);e.1c(d,j);u(6 i=0;i<j.r;i++){f.9(j[i])}});u(6 i=0;i<j.r;i++){e.y(j[i].v,A);f.9(j[i]);p(d.1I().1b()==j[i].M){e.y(j[i].v,B)}}d.1d().9(f);g=2s;2t(h.r){1p 2:g+=2u;1q;1p 3:g+=2v;1q;1p 4:g+=2w;1q}}Q{g=e.E.2x||2y}p(e.E.2z){d.1r(o 1e(),o 1f(1g,o 1h(7,31)))}p(e.E.1J){6 k=[{M:"2A",N:o 1i("1s.2B.1t")},{M:"2C",N:o 1i("1s.2D.1t")},{M:"2E",N:o 1i("2F.2G.2H")},{M:"2I",N:o 1i("1s.2J.2K")}];d.1r(o C(k),o 1f(1g,o 1h(g,7)))}p(e.E.2L){p(e.E.1J)g+=2M;d.1r(o 1j(e.E),o 1f(1g,o 1h(g,7)))}D f};z.l.1o=8(a){6 b=q;6 c=a.19();6 d=[];u(6 i=0;i<c.r;i++){d[i]=b.W(c[i].1b());d[i].M=c[i].1b();d[i].K(\'P\',c[i].1H())}b.1c(a,d);D d};z.l.1c=8(c,d){6 e=q;6 f=c.19();u(6 i=0;i<d.r;i++){6 g=[];u(6 j=0;j<f.r;j++){p(j!=i){g.X(d[j])}}e.1K(d[i],c,f[i],g)}t.1a(c,"2N",8(){6 a=0;6 b=c.1I();u(6 i=0;i<f.r;i++){p(f[i]==b){a=i}}t.2O(d[a],"F")})};z.l.W=8(a){6 b=n.s("x");q.1k(b);b.5.1L="R";b.5.1M="R";6 c=n.s("x");c.9(n.Y(a));c.5.G="1N";b.9(c);D b};z.l.1K=8(a,b,c,d){6 e=q;t.H(a,"F",8(){u(6 i=0;i<d.r;i++){e.y(d[i].v,A)}e.y(a.v,B);b.2P(c)})};z.l.y=8(a,b){a.5.2Q=b?"2R":"2S";a.5.Z=b?"I 1l #2T":"I 1l #1O";6 c=b?"#2U":"#1P";6 d=["2V","2W"];u(6 j=0;j<d.r;j++){a.5["Z"+d[j]]=c}};z.l.2X=8(){D o 1f(1g,o 1h(7,7))};z.l.1k=8(a){a.5.w="#2Y";a.5.1u="2Z";a.5.1Q="1R 1S";a.5.Z="I 1l 30";a.5.10="11";a.5.32="11";a.5.1T="1U";a.5.1V="1W";a.5.12="1X"};8 1j(a){q.E=a}8 13(){};13.l=z.l;1j.l=o 13();1j.l.18=8(b){6 c=q;6 d=c.W("1Y");d.K("P","1Z 1Y");d.5.1v="O";d.5.G="1N";d.v.5.1L="R";d.v.5.1M="R";c.y(d.v,A);6 e=o 33({20:B});e.O=B;t.1a(e,"34",8(a){p(a){d.5.1v="35"}Q{d.5.1v="O"}});b.21(e);t.H(d.v,"F",8(){p(e.O){e.O=A;e.36()}Q{e.O=B;e.20()}c.y(d.v,!e.O)});p(c.E.37){d.5.G="7.38";6 f=n.s("x");f.5.G="1.39";f.5.1m="22";f.5.23="11";f.5.3a="11";f.24="?";6 g=n.s("x");g.5.3b="3c";g.5.10="1w";6 h=[{"w":"#3d","S":"&3e; 26 1x"},{"w":"#3f","S":"25-26 1x"},{"w":"#3g","S":"&3h; 25 1x"},{"w":"#1P","S":"3i 3j"}];u(6 i=0;i<h.r;i++){g.24+="<x 5=\'S-3k: R\'><14 5=\'3l-w: "+h[i].w+"\'>&27;&27;</14>"+"<14 5=\'w: "+h[i].w+"\'> "+h[i].S+" </14>"+"</x>"}g.5.T="U";t.H(f,"F",8(){p(c.15){c.15=A;g.5.T="U"}Q{c.15=B;g.5.T="28"}c.y(f,c.15)});c.y(f,c.15);d.9(f);d.9(g)}b.1d().9(d);D d};8 C(a){C.l.V=a;q.16=[];q.L=[]}C.l=o 13();C.l.18=8(c){6 d=q;d.1y=c;6 e=n.s("x");d.J=d.W("3m...");d.J.K("P","1Z/29 3n");d.J.v.5.G="1z";d.y(d.J.v,A);e.9(d.J);e.9(d.2a());t.H(e,"3o",8(){p(2b.1A)3p(1A);d.m.5.T="28";d.J.v.5.1B="3q"});t.H(e,"3r",8(){1A=2b.3s(8(){d.m.5.T="U";d.J.v.5.1B=""},3t)});t.H(d.J,"F",8(){p(d.16.r>0){6 a=d.16.3u();u(6 i=0;i<a.r;i++){6 b=3v(a[i]);d.1n(B,d.V[b].N);d.L[b].17=B}}Q{d.1C()}});c.1d().9(e);D e};C.l.2a=8(){6 a=q;a.m=n.s("x");a.m.5.1m="22";a.m.5.23="3w";a.m.5.R="11";a.m.5.3x="-I";a.m.5.1Q="1R 1S";a.m.5.1V="1W";a.m.5.10="2c";a.m.5.G="2d";a.m.5.w="#3y";a.m.5.1u="#1O";a.m.5.Z="I 1l 3z";a.m.5.3A="#1D";a.m.5.12="1E";6 b=[];u(6 i=0;i<a.V.r;i++){b[i]=a.2e(i,a.V[i].M);a.m.9(b[i])}6 c=n.s("3B");c.5.G="3C%";c.5.1B="I";c.5.1T="1U";c.5.Z="I";c.5.w="#1D";c.5.1u="#1D";6 d=n.s("a");d.K("3D","3E:3F(0)");d.5.w="#2f";d.5.1F="U";d.5.12="1E";d.5.2g="3G";d.9(n.Y("29 1t"));a.m.9(c);a.m.9(d);t.H(d,"F",8(){a.1C()});a.m.5.T="U";D a.m};C.l.2e=8(a,b){6 c=q;6 d=n.s("x");6 e=n.s("3H");e.K("3I","3J");6 f=n.s("14");f.5.2g="1w";f.9(n.Y(b));d.9(e);d.9(f);d.9(n.s("3K"));c.L.X(e);t.H(e,"F",8(){c.1n(q.17,c.V[a].N)});D d};C.l.1G=8(a,b){a.5.3L=b?"1w":"I";a.5.G=b?"3M":"2d"};C.l.1n=8(a,b){6 c=q;6 d=c.m.3N;6 e=c.J.v;p(a){c.1y.21(b);c.16.r=0;d.5.w="#3O";d.5.1F="3P";d.5.12="1X";c.y(e,B);c.1G(c.m,B)}Q{c.1y.3Q(b);p(!c.2h()){d.5.w="#2f";d.5.1F="U";d.5.12="1E";c.y(e,A);c.1G(c.m,A)}}};C.l.1C=8(){6 a=q;u(6 i=0;i<a.L.r;i++){p(a.L[i].17){a.L[i].17=A;a.1n(A,a.V[i].N);a.16.X(i)}}};C.l.2h=8(){6 a=q;u(6 i=0;i<a.L.r;i++){p(a.L[i].17)D B}D A};8 1e(){};1e.l=o 13();1e.l.18=8(c){6 d=q;6 e=[];6 f=n.s("x");6 g=n.s("x");g.K("P","2i 3R 1m 3S 3T");d.1k(g);g.5.G="1z";g.5.10="I";g.5.3U="2c";g.5.3V="3W";g.9(n.Y("2i 2j"));f.9(g);6 h=n.s("x");h.K("P","3X 3Y 3Z 1m");d.1k(h);h.5.G="1z";h.5.10="I";h.9(n.Y("40 2k"));f.9(h);t.H(g,"F",8(){6 a=c.41();6 b=c.42();e.43(0,2,a,b);44("2k 2j: "+a.45()+"\\46: "+b)});t.H(h,"F",8(){p(e.r>0){c.47(e[1]);c.48(e[0])}});c.1d().9(f);D f};',62,257,'|||||style|var||function|appendChild||||||||||||prototype|layerboxDiv|document|new|if|this|length|createElement|GEvent|for|firstChild|color|div|toggleButton_|ExtMapTypeControl|false|true|MoreControl|return|options|click|width|addDomListener|1px|moreDiv|setAttribute|boxes_|name|obj|hidden|title|else|left|text|display|none|layers|createButton_|push|createTextNode|border|padding|0px|cursor|Inherit|span|keyExpanded|chosen_|checked|initialize|getMapTypes|addListener|getName|resetButtonEvents_|getContainer|SavePosControl|GControlPosition|G_ANCHOR_TOP_RIGHT|GSize|GLayer|TrafficControl|setButtonStyle_|solid|position|switchLayer_|addMapTypeButtons_|case|break|addControl|com|all|backgroundColor|visibility|2px|MPH|map_|7em|timer|height|hideAll_|e2e2e2|default|textDecoration|toggleBox_|getAlt|getCurrentMapType|showMore|assignButtonEvent_|cssFloat|styleFloat|6em|fff|c0c0c0|font|small|Arial|textAlign|center|fontSize|12px|pointer|Traffic|Show|hide|addOverlay|absolute|top|innerHTML||50|nbsp|block|Skjul|createLayerBox_|window|4px|120px|createCheckbox_|a5a5a5|marginLeft|checkChecked|Save|Position|Saved|GControl|useMapTypes|addmaptype|pop|removemaptype|clearListeners|removeChild|98|switch|72|144|216|posRight|220|showSave|Bilder|panoramio|Filmer|youtube|Wikipedia|org|wikipedia|en|Webkamera|google|webcams|showTraffic|94|maptypechanged|trigger|setMapType|fontWeight|bold|normal|483d8b|6495ed|RightColor|BottomColor|getDefaultPosition|000000|white|black||margin|GTrafficOverlay|changed|visible|show|showTrafficKey|8em|5em|right|clear|both|30ac3e|gt|ffcf00|ff0000|lt|No|data|align|background|Mer|Layers|mouseover|clearTimeout|23px|mouseout|setTimeout|300|slice|parseInt|20px|marginTop|000|gray|borderTopColor|hr|92|href|javascript|void|33px|input|type|checkbox|br|borderWidth|119px|lastChild|0000cd|underline|removeOverlay|actual|and|zoomlevel|marginBottom|whiteSpace|nowrap|Back|to|saved|To|getCenter|getZoom|splice|alert|toUrlValue|nZoomlevel|setZoom|panTo'.split('|'),0,{}))
/**
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * @name ExtMapTypeControl
 * @version 1.5
 * @copyright 2007 Google
 * @author Pamela Fox, others 
 * Added More button and buttons to save and restore position functionality.
 * This version of ExtMapTypeControl can also be used together with
 * GMapTypeControl, GHierarchicalMapTypeControl, GMenuMapTypeControl,
 * setUIToDefault and all self created map type buttons.
 * @copyright 2009 Wolfgang Pichler
 * @author Wolfgang Pichler (Pil), www.wolfpil.de
 * @fileoverview
 * <p>This class lets you add a control to the map which mimics GMapTypeControl
 * and allows for the addition of a traffic button/traffic key
 * plus a more button to display additional layers
 * and buttons to save the map position and return to it.
 * </p>
 */

/**
 * @name ExtMapTypeControlOptions
 * @class This class represents optional arguments to {@link ExtMapTypeControl}.
 * @desc Either option 'useMapTypes' or 'posRight' should be used.
 * @property {Boolean} [useMapTypes] Controls whether map type buttons are shown.
 * @property {Integer} [posRight] Defines the spacing in pixels of the button from the right map border.
 * @property {Boolean} [showTraffic] Controls whether traffic button is shown.
 * @property {Boolean} [showTrafficKey] Controls whether traffic key is shown.
 * @property {Boolean} [showMore] Controls whether more button is shown.
 * @property {Boolean} [showSave] Controls whether save/return buttons are shown.
 */

/**
 * @desc Creates a control with options specified in {@link ExtMapTypeControlOptions}.
 * @param {ExtMapTypeControlOptions} [opt_opts] Named optional arguments.
 * @constructor
 */
function ExtMapTypeControl(opt_opts) {
  this.options = opt_opts || {};
}

/**
 * Extends GOverlay class from the Google Maps API
 */
ExtMapTypeControl.prototype = new GControl();

/**
 * @desc Initialize the control on the map.
 * Creates the buttons for the map types and appends them to the map.
 * @param {GMap2} map The map that has had this ExtMapTypeControl added to it.
 * @return {DOM Object} Div that holds the map types buttons
 * @private
 */
ExtMapTypeControl.prototype.initialize = function(map) {
 var me = this;
 var extDiv = document.createElement("div");
 var posX;

 if (me.options.useMapTypes) {
  var mapTypes = map.getMapTypes();
  var mapTypeDivs = me.addMapTypeButtons_(map);

  GEvent.addListener(map, "addmaptype", function() {
    var newMapTypes = map.getMapTypes();
    var newMapType = newMapTypes.pop();
    var newMapTypeDiv = me.createButton_(newMapType.getName());
    newMapTypeDiv.setAttribute('title', newMapType.getAlt());
    mapTypes.push(newMapType);
    mapTypeDivs.push(newMapTypeDiv);
    me.resetButtonEvents_(map, mapTypeDivs);
    extDiv.appendChild(newMapTypeDiv);
  });
  GEvent.addListener(map, "removemaptype", function() {
    for (var i = 0; i < mapTypeDivs.length; i++) {
      GEvent.clearListeners(mapTypeDivs[i], "click");
      extDiv.removeChild(mapTypeDivs[i]);
    }
    mapTypeDivs = me.addMapTypeButtons_(map);
    me.resetButtonEvents_(map, mapTypeDivs);
    for (var i = 0; i < mapTypeDivs.length; i++) {
      extDiv.appendChild(mapTypeDivs[i]);
    }
  });

   for (var i = 0; i < mapTypeDivs.length; i++) {
    me.toggleButton_(mapTypeDivs[i].firstChild, false);
    extDiv.appendChild(mapTypeDivs[i]);
    if(map.getCurrentMapType().getName() == mapTypeDivs[i].name) {
     me.toggleButton_(mapTypeDivs[i].firstChild, true);
    }
   }
   map.getContainer().appendChild(extDiv);
   // Sets the proper spaces between the buttons
   posX = 98;
   switch (mapTypes.length) {
    case 2: posX += 72; break;
    case 3: posX += 144; break;
    case 4: posX += 216; break;
   }
 }
  else {
   // If no options were defined, 'posRight: 220' is assumed.
   posX = me.options.posRight || 220;
  }

  /*
  *  Loads SavePosControl when specified as option
  */
  if (me.options.showSave) {
   map.addControl(new SavePosControl(),
    new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(7, 31)));
  }

  /*
  *  Loads MoreControl when specified as option
  */
  if (me.options.showMore) {
   var layers = [
    { name: "Bilder", obj: new GLayer("com.panoramio.all") },
    { name: "Film", obj: new GLayer("com.youtube.all") },
    { name: "Wikipedia", obj: new GLayer("org.wikipedia.no") },
    { name: "Webkamera", obj: new GLayer("com.google.webcams") }
   ];

   map.addControl(new MoreControl(layers),
    new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(posX, 7)));
  }

  /*
  *  Loads TrafficControl when specified as option
  */
  if (me.options.showTraffic) {
    // Moves traffic button to the left if more button should also be displayed
    if(me.options.showMore)
     posX += 94;
    map.addControl(new TrafficControl(me.options),
     new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(posX, 7)));
  }
  return extDiv;
};

/**
 * Creates buttons for map types.
 * @param {GMap2} Map object for which to create buttons.
 * @return {Array} Divs containing the buttons.
 * @private
 */
ExtMapTypeControl.prototype.addMapTypeButtons_ = function(map) {
  var me = this;
  var mapTypes = map.getMapTypes();
  var mapTypeDivs = [];
  for (var i = 0; i < mapTypes.length; i++) {
    mapTypeDivs[i] = me.createButton_(mapTypes[i].getName());
    mapTypeDivs[i].name = mapTypes[i].getName();
    mapTypeDivs[i].setAttribute('title', mapTypes[i].getAlt());
  }
  me.resetButtonEvents_(map, mapTypeDivs);
  return mapTypeDivs;
};

/**
 * Ensures that map type button events are assigned correctly.
 * @param {GMap2} Map object for which to reset events.
 * @param {Array} mapTypeDivs Divs containing map type buttons.
 * @private
 */
ExtMapTypeControl.prototype.resetButtonEvents_ = function(map, mapTypeDivs) {
  var me = this;
  var mapTypes = map.getMapTypes();
  for (var i = 0; i < mapTypeDivs.length; i++) {
    var otherDivs = [];
    for (var j = 0; j < mapTypes.length; j++) {
      if (j != i) {
        otherDivs.push(mapTypeDivs[j]);
      }
    }
    me.assignButtonEvent_(mapTypeDivs[i], map, mapTypes[i], otherDivs);
  }
  GEvent.addListener(map, "maptypechanged", function() {
    var divIndex = 0;
    var mapType = map.getCurrentMapType();
    for (var i = 0; i < mapTypes.length; i++) {
      if (mapTypes[i] == mapType) {
        divIndex = i;
      }
    }
    GEvent.trigger(mapTypeDivs[divIndex], "click");
  });
};

/**
 * Creates buttons with text nodes. 
 * @param {String} text Text to display in button
 * @return {DOM Object} The div for the button.
 * @private
 */
ExtMapTypeControl.prototype.createButton_ = function(text) {
  var buttonDiv = document.createElement("div");
  this.setButtonStyle_(buttonDiv);
  buttonDiv.style.cssFloat = "left";
  buttonDiv.style.styleFloat = "left";
  var textDiv = document.createElement("div");
  textDiv.appendChild(document.createTextNode(text));
  textDiv.style.width = "6em";
  buttonDiv.appendChild(textDiv);
  return buttonDiv;
};

/**
 * Assigns events to MapType buttons to change maptype
 * and toggle button styles correctly for all buttons
 * when button is clicked.
 * @param {DOM Object} div Button's div to assign click to
 * @param {GMap2} Map object to change maptype of.
 * @param {Object} mapType GMapType to change map to when clicked
 * @param {Array} otherDivs Array of other button divs to toggle off
 * @private
 */  
ExtMapTypeControl.prototype.assignButtonEvent_ = function(div, map, mapType, otherDivs) {
  var me = this;
  GEvent.addDomListener(div, "click", function() {
    for (var i = 0; i < otherDivs.length; i++) {
      me.toggleButton_(otherDivs[i].firstChild, false);
    }
    me.toggleButton_(div.firstChild, true);
    map.setMapType(mapType);
  });
};

/**
 * Changes style of button to appear on/off depending on boolean passed in.
 * @param {DOM Object} div inner button div to change style of
 * @param {Boolean} boolCheck Used to decide to use on style or off style
 * @private
 */
ExtMapTypeControl.prototype.toggleButton_ = function(div, boolCheck) {
  div.style.fontWeight = boolCheck ? "bold" : "normal";
  div.style.border = boolCheck ? "1px solid #483d8b" : "1px solid #fff";
  var shadow = boolCheck ? "#6495ed" : "#c0c0c0";
  var edges = ["RightColor", "BottomColor"];
   for (var j = 0; j < edges.length; j++) {
    div.style["border" + edges[j]] = shadow;
   }
};

/**
 * Required by GMaps API for controls. 
 * @return {GControlPosition} Default location for map types buttons
 * @private
 */
ExtMapTypeControl.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(7, 7));
};

/**
 * Sets the proper CSS for the given button element.
 * @param {DOM Object} button Button div to set style for
 * @private
 */
ExtMapTypeControl.prototype.setButtonStyle_ = function(button) {
  button.style.color = "#000000";
  button.style.backgroundColor = "white";
  button.style.font = "small Arial";
  button.style.border = "1px solid black";
  button.style.padding = "0px";
  button.style.margin= "0px";
  button.style.textAlign = "center";
  button.style.fontSize = "12px"; 
  button.style.cursor = "pointer";
};

/**
 * @desc Constructor for TrafficControl.
 * Option hash to decide whether traffic key is shown.
 */
function TrafficControl(opt_opts) {
  this.options = opt_opts;
}

/*
 * It's more efficient to inherit ExtMapTypeControl's prototypes only
 */
function Inherit() {};
Inherit.prototype = ExtMapTypeControl.prototype;
TrafficControl.prototype = new Inherit();

/**
 * Creates the div that holds the traffic button
 * and - if specified - appends the div that holds the traffic key.
 * @param {GMap2} map The map that has had this Control added to it.
 * @return {DOM Object} Div that holds the button.
 * @private 
 */
TrafficControl.prototype.initialize = function(map) {
  var me = this;
  var trafficDiv = me.createButton_("Traffic");
  trafficDiv.setAttribute("title", "Show Traffic");
  trafficDiv.style.visibility = "hidden";
  trafficDiv.style.width = "6em";
  trafficDiv.firstChild.style.cssFloat = "left";
  trafficDiv.firstChild.style.styleFloat = "left";
  me.toggleButton_(trafficDiv.firstChild, false);

  // Sending true makes traffic overlay hidden by default
  var trafficInfo = new GTrafficOverlay({hide: true});
  trafficInfo.hidden = true;

  // Checks whether traffic data is available in viewport,
  // shows and hides the traffic button accordingly.
  GEvent.addListener(trafficInfo, "changed", function(hasTrafficInView) {
   if (hasTrafficInView) {
      trafficDiv.style.visibility = "visible";
   } else {
      trafficDiv.style.visibility = "hidden";
     }
  });
  map.addOverlay(trafficInfo);

  GEvent.addDomListener(trafficDiv.firstChild, "click", function() {
    if (trafficInfo.hidden) {
     trafficInfo.hidden = false;
     trafficInfo.show();
    } else {
     trafficInfo.hidden = true;
     trafficInfo.hide();
    }
    me.toggleButton_(trafficDiv.firstChild, !trafficInfo.hidden);
  });

  /*
  *  Appends traffic key when defined as option
  */
  if(me.options.showTrafficKey) {
   trafficDiv.style.width = "7.8em";
   var keyDiv = document.createElement("div");
   keyDiv.style.width = "1.5em";
   keyDiv.style.position = "absolute";
   keyDiv.style.top = "0px";
   keyDiv.style.right = "0px";
   keyDiv.innerHTML = "?";

   var keyExpandedDiv = document.createElement("div");
   keyExpandedDiv.style.clear = "both";
   keyExpandedDiv.style.padding = "2px";
   var keyInfo = [{"color": "#30ac3e", "text": "&gt; 50 MPH"},
                  {"color": "#ffcf00", "text": "25-50 MPH"},
                  {"color": "#ff0000", "text": "&lt; 25 MPH"},
                  {"color": "#c0c0c0", "text": "No data"}];
    for (var i = 0; i < keyInfo.length; i++) {
      keyExpandedDiv.innerHTML += "<div style='text-align: left'><span style='background-color: " + keyInfo[i].color + "'>&nbsp;&nbsp;</span>"
    +  "<span style='color: " + keyInfo[i].color + "'> " + keyInfo[i].text + " </span>" + "</div>";
    }
    keyExpandedDiv.style.display = "none";

    GEvent.addDomListener(keyDiv, "click", function() {
      if (me.keyExpanded) {
        me.keyExpanded = false;
        keyExpandedDiv.style.display = "none";
      }
       else {
        me.keyExpanded = true;
        keyExpandedDiv.style.display = "block";
       }
       me.toggleButton_(keyDiv, me.keyExpanded);
    });
    me.toggleButton_(keyDiv, me.keyExpanded);
    trafficDiv.appendChild(keyDiv);
    trafficDiv.appendChild(keyExpandedDiv);
  }
  map.getContainer().appendChild(trafficDiv);
  return trafficDiv;
};


/**
 * @desc Constructor for MoreControl.
 * Immutable shared property moved to prototype.
 */
function MoreControl(layers) {
  MoreControl.prototype.layers = layers;
  this.chosen_ = [];
  this.boxes_ = [];
}

/**
* Inherits ExtMapTypeControl's prototypes only
*/
MoreControl.prototype = new Inherit();

/*
 * Primarily creates an outer div that holds 
 * all necessary elements needed for the more button.
 * @param {GMap2} map The map that has had this Control added to it.
 * @return {DOM Object} Div that holds all button elements.
 * @private
 */
MoreControl.prototype.initialize = function(map) {
  var me = this;
  me.map_ = map;
  var outer = document.createElement("div");
  me.moreDiv = me.createButton_("Mere...");
  me.moreDiv.setAttribute("title", "Show/Hide Layers");
  me.moreDiv.firstChild.style.width = "7em";
  me.toggleButton_(me.moreDiv.firstChild, false);
  outer.appendChild(me.moreDiv);
  outer.appendChild(me.createLayerBox_());

  GEvent.addDomListener(outer, "mouseover", function() {
  if(window.timer) clearTimeout(timer);
   me.layerboxDiv.style.display = "block";
   me.moreDiv.firstChild.style.height = "23px";
  });
  GEvent.addDomListener(outer, "mouseout", function() {
   timer = window.setTimeout(function() {
    me.layerboxDiv.style.display = "none";
    me.moreDiv.firstChild.style.height = "";
   }, 300);
  });
  GEvent.addDomListener(me.moreDiv, "click", function() {
   if(me.chosen_.length > 0 ) {
    /* Makes an independent copy of chosen array since it will be
    *  reset by switchLayer, which might not be useful here
    */
    var copy = me.chosen_.slice();
    for(var i = 0; i < copy.length; i++) {
     var index = parseInt(copy[i]);
     me.switchLayer_(true, me.layers[index].obj);
     me.boxes_[index].checked = true;
    }
   }
   else {
    me.hideAll_();
   }
  });
 map.getContainer().appendChild(outer);
 return outer;
};

/**
 * Primarily creates the outer div that holds the checkboxes.
 * @return {DOM Object} Div that holds all elements underneath the More...Button.
 * @private
 */
MoreControl.prototype.createLayerBox_ = function() {
  var me = this;
  me.layerboxDiv = document.createElement("div");
  // For nested elements position:absolute means relative to its parent
  me.layerboxDiv.style.position = "absolute";
  me.layerboxDiv.style.top = "20px";
  me.layerboxDiv.style.left = "0px";
  me.layerboxDiv.style.marginTop = "-1px";
  me.layerboxDiv.style.font = "small Arial";
  me.layerboxDiv.style.fontSize = "12px";
  me.layerboxDiv.style.padding = "4px";
  me.layerboxDiv.style.width = "120px";
  me.layerboxDiv.style.color = "#000";
  me.layerboxDiv.style.backgroundColor = "#fff";
  me.layerboxDiv.style.border = "1px solid gray";
  me.layerboxDiv.style.borderTopColor = "#e2e2e2";
  me.layerboxDiv.style.cursor = "default";

  var input = [];
  for (var i = 0; i < me.layers.length; i++) {
   input[i] = me.createCheckbox_(i, me.layers[i].name);
   me.layerboxDiv.appendChild(input[i] );
  }

  var ruler = document.createElement("hr");
  ruler.style.width = "92%";
  ruler.style.height = "1px";
  ruler.style.textAlign = "center";
  ruler.style.border = "1px";
  ruler.style.color = "#e2e2e2";
  ruler.style.backgroundColor = "#e2e2e2";
  var boxlink = document.createElement("a");
  boxlink.setAttribute("href", "javascript:void(0)");
  boxlink.style.color = "#a5a5a5";
  boxlink.style.textDecoration = "none";
  boxlink.style.cursor = "default";
  boxlink.style.marginLeft = "33px";
  boxlink.appendChild(document.createTextNode("Skjul alle"));

  me.layerboxDiv.appendChild(ruler);
  me.layerboxDiv.appendChild(boxlink);

  GEvent.addDomListener(boxlink, "click", function() {
   me.hideAll_();
  });
  me.layerboxDiv.style.display = "none";
  return me.layerboxDiv;
};

/**
 * Creates checkboxes with a click event inside of a div element.
 * @param {Number} nr The array index of the layers array
 * @param {String} name The name of the layer the checkbox belongs to
 * @return {DOM Object} Div that holds the checkbox and its related text node
 * @private
 */
MoreControl.prototype.createCheckbox_ = function(nr, name) {
  var me = this;
  var innerDiv = document.createElement("div");
  var checkbox = document.createElement("input");
  checkbox.setAttribute("type", "checkbox");
  var textSpan = document.createElement("span");
  textSpan.style.marginLeft = "2px";
  textSpan.appendChild(document.createTextNode(name));
  innerDiv.appendChild(checkbox);
  innerDiv.appendChild(textSpan);
  innerDiv.appendChild(document.createElement("br"));
  me.boxes_.push(checkbox);

  GEvent.addDomListener(checkbox, "click", function() {
   me.switchLayer_(this.checked, me.layers[nr].obj);
  });
  return innerDiv;
};

/**
 * Changes style of layerbox to appear on/off depending on passed boolean.
 * @param {DOM Object} elem element to change style of
 * @param {Boolean} boolCheck Used to decide between on or off style
 * @private
 */
MoreControl.prototype.toggleBox_ = function(elem, boolCheck) {
  elem.style.borderWidth = boolCheck ? "2px": "1px";
  elem.style.width = boolCheck ? "119px" : "120px";
};

/**
 * Adds and removes the chosen layers to/from the map.
 * Styles the link inside the layer box and the more button accordingly.
 * @param {Boolean} checked Value of checked or unchecked checkbox
 * @param {Object} layer The GLayer object to add or to remove
 * @private
 */
MoreControl.prototype.switchLayer_ = function(checked, layer) {
  var me = this;
  var link = me.layerboxDiv.lastChild;
  var button = me.moreDiv.firstChild;
  if(checked) {
   me.map_.addOverlay(layer);
   // Resets chosen array
   me.chosen_.length = 0;
   /* 
   *  Toggles the elements
   */
   link.style.color = "#0000cd";
   link.style.textDecoration = "underline";
   link.style.cursor = "pointer";
   me.toggleButton_(button, true);
   me.toggleBox_(me.layerboxDiv, true);
  }
  else {
   me.map_.removeOverlay(layer);
   /*  Resets the elements
    * if all checkboxes were unchecked
   */
   if(!me.checkChecked()) {
    link.style.color = "#a5a5a5";
    link.style.textDecoration = "none";
    link.style.cursor = "default";
    me.toggleButton_(button, false);
    me.toggleBox_(me.layerboxDiv, false);
   }
  }
};

/**
 * Calls switchLayer to remove all displayed layers.
 * Stores index of removed layers in chosen array.
 * @private
 */
MoreControl.prototype.hideAll_ = function() {
  var me = this;
  for(var i = 0; i < me.boxes_.length; i++) {
   if(me.boxes_[i].checked) {
    me.boxes_[i].checked = false;
    me.switchLayer_(false, me.layers[i].obj);
    me.chosen_.push(i);
   }
  }
};

/**
 * Returns true if a checkbox is still checked, otherwise false.
 * @return {Boolean}
 */
MoreControl.prototype.checkChecked = function() {
  var me = this;
  for(var i = 0; i < me.boxes_.length; i++) {
   if(me.boxes_[i].checked) return true;
  }
  return false;
};


/**
 * @desc Constructor for SavePosControl.
 */
function SavePosControl() {};

/**
* Inherits ExtMapTypeControl's prototypes only
*/
SavePosControl.prototype = new Inherit();

/**
 * Creates the buttons for saving position and the back button.
 * @param {GMap2} map The map that has had this Control added to it.
 * @return {DOM Object} Div that holds both buttons.
 * @private
 */
SavePosControl.prototype.initialize = function(map) {
  var me = this;
  var saved = [];
  var saveDiv = document.createElement("div");
  var saveButtonDiv = document.createElement("div");
 
  saveButtonDiv.setAttribute("title", "Save actual position and zoomlevel");
  me.setButtonStyle_(saveButtonDiv);
  // Overwrites a few 'normal' styles of these buttons
  saveButtonDiv.style.width = "7em";
  saveButtonDiv.style.padding = "1px";
  saveButtonDiv.style.marginBottom = "4px";
  saveButtonDiv.style.whiteSpace = "nowrap";
  saveButtonDiv.appendChild(document.createTextNode("Save Position"));
  saveDiv.appendChild(saveButtonDiv);
  var backButtonDiv = document.createElement("div");
  backButtonDiv.setAttribute("title", "Back to saved position");
  me.setButtonStyle_(backButtonDiv);
  backButtonDiv.style.width = "7em";
  backButtonDiv.style.padding = "1px";
  backButtonDiv.appendChild(document.createTextNode("To Saved"));
  saveDiv.appendChild(backButtonDiv);

  GEvent.addDomListener(saveButtonDiv, "click", function() {
   var center = map.getCenter();
   var zoom = map.getZoom();
   saved.splice(0, 2, center, zoom);
   alert("Saved Position: "+ center.toUrlValue()+ "\nZoomlevel: "+ zoom);
  });
  GEvent.addDomListener(backButtonDiv, "click", function() {
   if (saved.length > 0) {
    map.setZoom(saved[1]);
    map.panTo(saved[0]);
   }
  });
 map.getContainer().appendChild(saveDiv);
 return saveDiv;
};

//extmaptypecontrol.js kode slutt

 function addMarker(xmlnode) {
  	var point = loadPoint(xmlnode); 
   	var markee;
  	var icon = xmlnode.getAttribute("icon");
     	if (icon != "") {
         var anicon = new GIcon(baseIcon);
         anicon.image = icon;
     	 markee = new GMarker(point, anicon);
     	}
     	else
     	{      	
     	 markee = new GMarker(point);
     	}
        GEvent.addListener(markee, "click", function() {
           markee.openInfoWindowHtml(xmlnode.getAttribute("info"));
           itemclic(xmlnode.getAttribute("id"), parseFloat(xmlnode.getAttribute("x")),parseFloat(xmlnode.getAttribute("y")));
         });
        map.addOverlay(markee);
   
 }

 function geturlproperties() {
	 var bounds = map.getBounds();
         var southWest = bounds.getSouthWest();
         var northEast = bounds.getNorthEast();
	 var zl = 17 - map.getZoom();
	 var res = 'maxX='+northEast.lng()+'&maxY='+northEast.lat()+'&minY='+southWest.lat()+'&minX='+southWest.lng();
	 res = res + '&zoomlevel='+zl;
	 return res;
 }

 function itemclic(id, x, y) {
     var xmlfile = trackbackurl+'?action=clicked'+
      '&id='+id+
      '&xclicked=' + x +
      '&yclicked=' + y +
      '&'+geturlproperties();
     processrequest(xmlfile, true);
 }

 function loadPoint(xmlnode) {
     return new GLatLng(
      parseFloat(xmlnode.getAttribute("y")),
      parseFloat(xmlnode.getAttribute("x"))); 
 }

 function processXMLnode(marker) {

     if (marker.getAttribute("type") == "alert") {
        alert(marker.getAttribute("alert"));
     }
     if (marker.getAttribute("type") == "point") {
     	addMarker(marker);
     };
     if (marker.getAttribute("type") == "trace") {
         var pointspolyline = [];
         var markers = marker.getElementsByTagName("point");
         for (var i = 0; i < markers.length; i++) {
           pointspolyline.push(loadPoint(markers[i]));
         }
         var trace = new GPolyline(pointspolyline,
          marker.getAttribute("color"),
          parseFloat(marker.getAttribute("weight")),
          parseFloat(marker.getAttribute("opacity"))
         );
         map.addOverlay(trace);
         lasttrace = trace;
     }
     if (marker.getAttribute("type") == "clear") {
         map.clearOverlays();
          }
     if (marker.getAttribute("type") == "clearlasttrace" && lasttrace) {
         map.removeOverlay(lasttrace);
     }
     if (marker.getAttribute("type") == "move") {
         map.setCenter(new GLatLng(parseFloat(marker.getAttribute("y")), parseFloat(marker.getAttribute("x"))), 17 - parseFloat(marker.getAttribute("zl")));
     }
     if (marker.getAttribute("type") == "info") {
         document.getElementById(marker.getAttribute("id")).innerHTML = marker.getAttribute("text");
     }
 }

 function processxmlDoc(xmlDoc) {
      var markers = xmlDoc.documentElement.getElementsByTagName("data");
      markerstoadd = [];

      for (var i = 0; i < markers.length; i++) { // er"<"erg<>
        processXMLnode(markers[i]);
      }
 }

 function processrequest(url, async) {
     var request = GXmlHttp.create();

     request.open("GET", url, async);

     if (async) {
      request.onreadystatechange = function() {
        if (request.readyState == 4) {
//          alert(request.responseText);
          processxmlDoc(request.responseXML);
        }
      }
      request.send(null);
     }
     else
     {
      request.send(null);
//      alert(request.responseText);
      processxmlDoc(request.responseXML);
     }       
 }

 function modified(actionmade, async) {
    var xmlfile = trackbackurl+'?action='+actionmade+'&'+geturlproperties();
    processrequest(xmlfile, async);
 }

 function moved() {
	modified('moved', true);
 }

 function zoomed(oldZoomLevel, newZoomLevel) {
	modified('zoomed', true);
 }

 function initmap(trackback, divid) {

  trackbackurl = trackback;

//  alert("DBG: TrackBack: "+trackback+" DivId: "+divid);
//  alert(document.getElementById(divid));
  

//LAYERS SOM SKAL BRUKES I CUSTOM KNAPPER
//flickr = new GGeoXml("http://api.flickr.com/services/feeds/geo/&tags=sykkelspor&num=500&format=rss200");
//DNT = new GGeoXml("http://sykkelspor.no/dnt.kmz");
//marka = new GGeoXml("http://sykkelspor.no/marka.kmz");

    

	  
// We define the function first
function TextualZoomControl() {
}

// To "subclass" the GControl, we set the prototype object to
// an instance of the GControl object
TextualZoomControl.prototype = new GControl();

// Creates a one DIV for each of the buttons and places them in a container
// DIV which is returned as our control element. We add the control to
// to the map container and return the element for the map class to
// position properly.
TextualZoomControl.prototype.initialize = function(map) {
  var container = document.createElement("div");

  var stor = document.createElement("div");
  this.setButtonfullStyle_(stor);
  container.appendChild(stor);
  stor.appendChild(document.createTextNode("MAX"));
  GEvent.addDomListener(stor, "click", function() {
  var myElement = document.getElementById("map");
  myElement.style.position="fixed";
  myElement.style.height="100%";
  myElement.style.width="100%";
  myElement.style.top="0px";
  myElement.style.bottom="0px";
  myElement.style.overflow="hidden";
  map.checkResize();
  });

  var liten = document.createElement("div");
  this.setButtonfullStyle_(liten);
  container.appendChild(liten);
  liten.appendChild(document.createTextNode("MIN"));
  GEvent.addDomListener(liten, "click", function() {
  var myElement = document.getElementById("map");
  myElement.style.position="relative";
  myElement.style.height="650px";
  myElement.style.top="0px";
  map.checkResize();
  });
 
/*  
  var Flick = document.createElement("div");
  this.setButtonStyle_(Flick);
  container.appendChild(Flick);
  Flick.appendChild(document.createTextNode("Flickr"));
  GEvent.addDomListener(Flick, "click", function() {
  map.addOverlay(flickr);
    });
  GEvent.addDomListener(Flick, "dblclick", function() {
  map.removeOverlay(flickr);
   });
   
  var dntu = document.createElement("div");
  this.setButtonStyle_(dntu);
  container.appendChild(dntu);
  dntu.appendChild(document.createTextNode("DNT"));
  GEvent.addDomListener(dntu, "click", function() {
    map.addOverlay(DNT);
  });
  GEvent.addDomListener(dntu, "dblclick", function() {
  map.removeOverlay(DNT);
  });
  
  var oslo = document.createElement("div");
  this.setButtonStyle_(oslo);
  container.appendChild(oslo);
  oslo.appendChild(document.createTextNode("Oslomarka"));
  GEvent.addDomListener(oslo, "click", function() {
    map.addOverlay(marka);
  });
  GEvent.addDomListener(oslo, "dblclick", function() {
  map.removeOverlay(marka);
  });
*/
  map.getContainer().appendChild(container);
  return container;
}

// By default, the control will appear in the top left corner of the
// map with 7 pixels of padding.
TextualZoomControl.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(5, 6));
}

//css for fullskjerm knapp
TextualZoomControl.prototype.setButtonfullStyle_ = function(button) {
//  button.style.textDecoration = "underline";
  button.style.color = "black";
  button.style.backgroundColor = "white";
  button.style.fontSize = "10px";
  button.style.fontFamily = "Arial, sans-serif";
  button.style.border = "1px solid black";
  button.style.padding = "1px";
  button.style.marginBottom = "2px";
  button.style.textAlign = "center";
  button.style.width = "40px";
  button.style.cursor = "pointer";
}

map = new GMap2(document.getElementById(divid));

map.addControl(new TextualZoomControl());


/*
//tøff meny
	var html='<div class="htmlControl" style="width:100px; background-color:white; cursor:pointer;"><div id="menuButton" style="margin:1px"><span style="font-weight:bold">Vis</span>&nbsp;hjelp</div><div id="menuPanel" style="display:none"><div class="htmlControl htmlButton" id="selectableButton"><span style="font-weight:bold">Vis</span> layers hjelp</div><div class="htmlControl htmlButton" id="nonSelectableButton"><span style="font-weight:bold">Vis</span> kart tips</div></div></div>';
	//fjernet fra linjen over <div class="htmlControl htmlButton" id="imageButton"><span style="font-weight:bold">Vis</span> legend</div>
	map.addControl(new HtmlControl(html), new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(440, 5)));
	//	now add a click event listener to the menuButton to show/hide the menuPanel that contains the other buttons
	GEvent.addDomListener(document.getElementById('menuButton'), 'click', function() {
		var menuPanel=document.getElementById('menuPanel');
		menuPanel.style.display=(menuPanel.style.display=='block')?'none':'block';
		var button=document.getElementById('menuButton');
		var html=(menuPanel.style.display=='block')?'Skjul':'Vis';
		html='<span style="font-weight:bold">'+html+'</span> hjelp';
		button.innerHTML=html;
	});
	
	
	//	now we create a HTML control which contains text that is selectable but not printable
	//	we want this HtmlControl to be created hidden
	html='<div class="htmlControl" style="width:184px"><p><u><b>Layers</b></u></p><p>Klikk for &#229; vise innhold <i>(fra andre nettsider)</i> som layers i kartet. -> <p><i>Dobbelklikk for &#229; fjerne layer.</i><p><b>Flickr:</b><br>viser bilder fra flickr.com som er tagget med sykkelspor.<p><b>DNT:</b><br>viser de <b>U</b>betjente, <b>B</b>etjente og <b>S</b>elvbetjente hyttene til Den Norske Turistforening.<p><b>Oslomarka:</b><br>viser diverse markapunkter hentet fra Skirforeningen.no i marka rundt Oslo.<p><b>Wikipedia, Panoramio, Youtube:</b><br>viser innhold fra disse nettsidene. <i>(Anbefales!)</i><b><p>Fjern layers:</b><br>fjerner alle layers fra kartet.</p></div>';
		//	pass the html and override the defaults for visible and selectable but accept default for printable(false)
	var selectableTextPanel=new HtmlControl(html, { visible:false, selectable:false });
	map.addControl(selectableTextPanel, new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(95, 50)));
	// another click listener - we want to show/hide selectableTextPanel when selectableButton is clicked
	GEvent.addDomListener(document.getElementById('selectableButton'), 'click', function() {
		selectableTextPanel.setVisible(!selectableTextPanel.isVisible);
		var button=document.getElementById('selectableButton');
		var html=(selectableTextPanel.isVisible)?'Skjul':'Vis';
		html='<span style="font-weight:bold">'+html+'</span> layers hjelp';
		button.innerHTML=html;
	});
	
	
	//	another HtmlControl, this time the text it contans is not selectable or printable and we want it to be hidden when first created
	html='<div class="htmlControl" id="nonSelectableTextPanel" style="width:256px"><p><b><u>Kart Tips</u></b><p><b>Kart:</b><br>Viser Google map gatekart. Et par undervalg kommer opp. V&#230;rdata og Verneomr&#229;der. Dette er test av nye karttyper s&#229; det fungerer ikke 100% enda.<p><b>Satellitt:</b><br>Viser Google satellitt bilder. Gatenavn bytter til blanding av gatekart og satellitt visning.<p><b>Terreng:</b><br>Viser gatekart med terreng.<p><b>OSM:</b><br>Viser Openstreetmap slippymap som standard. Du kan ogs&#229; velge OSM Cloudmade som er en variant av standard OSM Slippy map, CycleMap som er optimalisert for sykkelbruk, eller Tiles & Home.<p><b>Navigering:</b><br>dobbelklikk venstreknapp for &#229; zoome inn.<br>dobbleklikk h&#248;yreknapp for &#229; zoome ut.<br>klikkogdra for &#229; bevege deg i kartet.<br>musehjul zoomer ut/inn.<br><p><b>Fullskjerm</b><br>Viser fullskjerms modus av kartet. Dobbelklikk viser liten versjon. Enkelt klikk viser fullskjerm.';
	//	pass the html, override default visible setting and accept defaults settings for selectable(false) and printable(false)
	var nonSelectableTextPanel=new HtmlControl(html, { visible:false });
	map.addControl(nonSelectableTextPanel, new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(285, 90)));
	//	another click event listener - we want to show/hide nonSelectableTextPanel when nonSelectableButton is clicked
	GEvent.addDomListener(document.getElementById('nonSelectableButton'), 'click', function() {
		nonSelectableTextPanel.setVisible(!nonSelectableTextPanel.isVisible);
		var button=document.getElementById('nonSelectableButton');
		var html=(nonSelectableTextPanel.isVisible)?'Skjul':'Vis';
		html='<span style="font-weight:bold">'+html+'</span> kart tips';
		button.innerHTML=html;
	});
	
	/*
	//	lastly we create a HtmlControl to contain an image
	html='<img src="http://sykkelspor.no/beta/ski/ski.jpg" width="150" height="150" border="1">';
	//	we want the image to be created as hidden, not be selectable(default) but be printable
	var imagePanel=new HtmlControl(html, { visible:false, printable:true });
	map.addControl(imagePanel, new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(7, 21)));
	//	 finally one last event listener - to show/hide imagePanel when imageButton is clicked
	GEvent.addDomListener(document.getElementById('imageButton'), 'click', function() {
		imagePanel.setVisible(!imagePanel.isVisible);
		var button=document.getElementById('imageButton');
		var html=(imagePanel.isVisible)?'Skjul':'Vis';
		html='<span style="font-weight:bold">'+html+'</span> legend';
		button.innerHTML=html;
	});
*/
//tøff meny slutt. Husk htmlcontrol CSS i styles.css
 
 //Hente dato funksjoner
   		function getDateStr() {
			var now = new Date();
			return now.getFullYear()+"-"+(now.getMonth()+1)+"-"+now.getDate();
		}
		
		
/*
//WMS tolker
function WMSCreateMap(name,copyright,baseUrl,layer,format,transparent,opacity,minResolution,maxResolution,extraTileLayers,urlArg)
{var tileLayer=new GTileLayer(new GCopyrightCollection(copyright),minResolution,maxResolution);tileLayer.baseUrl=baseUrl;tileLayer.layer=layer;tileLayer.format=format;tileLayer.transparent=transparent;tileLayer.getTileUrl=WMSGetTileUrl;tileLayer.getOpacity=function(){return opacity;};tileLayer.getCopyright=function(){return{prefix:'',copyrightTexts:[copyright]};};var tileLayers=[];for(var i in extraTileLayers)
tileLayers.push(extraTileLayers[i]);tileLayers.push(tileLayer);return new GMapType(tileLayers,G_SATELLITE_MAP.getProjection(),name,{urlArg:urlArg});}
function WMSGetTileUrl(tile,zoom)
{var southWestPixel=new GPoint(tile.x*256,(tile.y+1)*256);var northEastPixel=new GPoint((tile.x+1)*256,tile.y*256);var southWestCoords=G_NORMAL_MAP.getProjection().fromPixelToLatLng(southWestPixel,zoom);var northEastCoords=G_NORMAL_MAP.getProjection().fromPixelToLatLng(northEastPixel,zoom);var bbox=southWestCoords.lng()+','+southWestCoords.lat()+','+northEastCoords.lng()+','+northEastCoords.lat();var transparency=this.transparent?'&TRANSPARENT=TRUE':'';return this.baseUrl+'?VERSION=1.1.1&REQUEST=GetMap&LAYERS='+this.layer+'&STYLES=&SRS=EPSG:4326&BBOX='+bbox+'&WIDTH=256&HEIGHT=256&FORMAT='+this.format+'&BGCOLOR=0xCCCCCC&EXCEPTIONS=INIMAGE'+transparency;}
*/
function OSMCreateMap(name,copyright,baseUrl,opacity,minResolution,maxResolution,extraTileLayers,urlArg)
{var tileLayer=new GTileLayer(new GCopyrightCollection(copyright),minResolution,maxResolution);tileLayer.baseUrl=baseUrl;tileLayer.getTileUrl=OSMGetTileUrl;tileLayer.getOpacity=function(){return opacity;};tileLayer.getCopyright=function(){return{prefix:'',copyrightTexts:[copyright]};};var tileLayers=[];for(var i in extraTileLayers)
tileLayers.push(extraTileLayers[i]);tileLayers.push(tileLayer);return new GMapType(tileLayers,G_NORMAL_MAP.getProjection(),name,{urlArg:urlArg});}
function OSMGetTileUrl(tile,zoom)
{return this.baseUrl+zoom+'/'+tile.x+'/'+tile.y+'.png';}
//var WMS_TOPO_MAP=WMSCreateMap('Topo','StatKart','http://openwms.statkart.no/skwms1/wms.topo2?','topo2_WMS','image/jpeg',false,1.0,4,14,[],'t');
//var WMS_DOQ_MAP=WMSCreateMap('DOQ','Imagery by USGS / Service by TerraServer','http://www.terraserver-usa.com/ogcmap6.ashx','DOQ','image/jpeg',false,1.0,4,18,[],'o');
//var WMS_NEXRAD_MAP=WMSCreateMap('NEXRAD','Data by NWS / Service by Iowa U. Ag. Dept.','http://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi','nexrad-n0r','image/png',true,0.666,4,10,G_HYBRID_MAP.getTileLayers(),'n');
var OSMServers=['a.tile.openstreetmap.org','b.tile.openstreetmap.org','c.tile.openstreetmap.org'];var OSMServer=OSMServers[Math.floor(Math.random()*OSMServers.length)];var OSM_MAPNIK_MAP=OSMCreateMap('OSM','OpenStreetMap / Mapnik','http://'+OSMServer+'/',1.0,0,17,[],'k');
var OCMServers=['a.tile.cloudmade.com/f4211dafc9815eb38aab7c6a5d49d12c/997/256/','b.tile.cloudmade.com/f4211dafc9815eb38aab7c6a5d49d12c/997/256/','c.tile.cloudmade.com/f4211dafc9815eb38aab7c6a5d49d12c/997/256/'];var OCMServer=OCMServers[Math.floor(Math.random()*OCMServers.length)];
var OSM_OCMNIK_MAP=OSMCreateMap('CloudMade','OpenStreetMap / CloudMade','http://'+OCMServer+'/',1.0,0,18,[],'k');
var OKMServers=['a.andy.sandbox.cloudmade.com/tiles/cycle','b.andy.sandbox.cloudmade.com/tiles/cycle','c.andy.sandbox.cloudmade.com/tiles/cycle'];var OKMServer=OKMServers[Math.floor(Math.random()*OKMServers.length)];var OSM_OKMNIK_MAP=OSMCreateMap('OSM','OpenStreetMap / CycleMap','http://'+OKMServer+'/',1.0,0,16,[],'k');
var OTMServers=['tah.openstreetmap.org/Tiles/tile','tah.openstreetmap.org/Tiles/tile','tah.openstreetmap.org/Tiles/tile'];var OTMServer=OTMServers[Math.floor(Math.random()*OTMServers.length)];var OTM_MAPNIK_MAP=OSMCreateMap('TM','OpenStreetMap / T&H','http://'+OTMServer+'/',1.0,0,17,[],'');

//Henter Verneområder fra DN
var copyCollection = new GCopyrightCollection('Data fra &#169;');
var copyright = new GCopyright(1, new GLatLngBounds(new GLatLng(-85, -180), new GLatLng(85, 180)), 0, "Naturbase, Direktoratet for naturforvaltning - 2009");
copyCollection.addCopyright(copyright);

	
    var tile3= new GTileLayer(copyCollection, 3, 13);
   	tile3.getTileUrl=function(a,b) {
	var nwPoint = new GPoint(a.x*256,(a.y+1)*256);
	var sePoint = new GPoint((a.x+1)*256,a.y*256);
	var nw = G_NORMAL_MAP.getProjection().fromPixelToLatLng(nwPoint,b,1);
	var se = G_NORMAL_MAP.getProjection().fromPixelToLatLng(sePoint,b,1);
	var tileurl = "http://dnweb12.dirnat.no/wmsconnector/com.esri.wms.Esrimap?WMTVER=1.1.1&REQUEST=GetMap&service=WMS&FORMAT=image/png&WIDTH=512&HEIGHT=256&SRS=epsg:4326&BGCOLOR=0x23f3f5&TRANSPARENT=TRUE&ServiceName=WMS_NB_Vern_tema&LAYERS=VernNatPkt,VernNatOmrKlasser,AnnenFredning,Artsfredning,Naturreservater,Landskapsvernomrader,Nasjonalparker&STYLES=default,default,default&bbox=" + nw.x + "," + nw.y + "," + se.x + "," + se.y;
	return tileurl;
    };
        tile3.getOpacity = function() {return 0.6;}
   var layer3=[G_NORMAL_MAP.getTileLayers()[0],tile3];
   var dnmap = new GMapType(layer3, G_NORMAL_MAP.getProjection(), "DN", {errorMessage:"No chart data available"});

   //Henter Vær fra met  
var copyCollection = new GCopyrightCollection('Data fra &#169;');
var copyright = new GCopyright(1, new GLatLngBounds(new GLatLng(-85, -180), new GLatLng(85, 180)), 0, "met.no");
copyCollection.addCopyright(copyright);
  
    var tile4= new GTileLayer(copyCollection, 3, 13);
   	tile4.getTileUrl=function(a,b) {
	var nwPoint = new GPoint(a.x*256,(a.y+1)*256);
	var sePoint = new GPoint((a.x+1)*256,a.y*256);
	var nw = G_NORMAL_MAP.getProjection().fromPixelToLatLng(nwPoint,b,1);
	var se = G_NORMAL_MAP.getProjection().fromPixelToLatLng(sePoint,b,1);
	var tileurl = "http://openmetoc.met.no:8080/metoc/metocwms?VERSION=1.1.1&REQUEST=GetMap&SERVICE=WMS&format=image/png&WIDTH=256&HEIGHT=256&SRS=epsg:4326&style=default&layers=ECMWF-IFS_2:TMP,ECMWF-IFS_2:GRD,ECMWF-IFS_1:APCP6hr&bbox=" + nw.x + "," + nw.y + "," + se.x + "," + se.y;
	return tileurl;
    };
        tile4.getOpacity = function() {return 0.8;}
   var layer4=[G_NORMAL_MAP.getTileLayers()[0],tile4];
   var yrmap = new GMapType(layer4, G_NORMAL_MAP.getProjection(), "", {errorMessage:"No chart data available"});

//StatKart topo2 
var copyCollection = new GCopyrightCollection('Kartgrunnlag:');
var copyright = new GCopyright(1, new GLatLngBounds(new GLatLng(-85, -180), new GLatLng(85, 180)), 0, '<a href="http://www.statkart.no">Statens kartverk</a>, <a href="http://www.statkart.no/nor/Land/Fagomrader/Geovekst/">Geovekst</a> og <a href="http://www.statkart.no/?module=Articles;action=Article.publicShow;ID=14194">kommuner</a>');
copyCollection.addCopyright(copyright);
  
    var tile5= new GTileLayer(copyCollection, 1, 14,
              {tileUrlTemplate: 'http://opencache.statkart.no/gatekeeper/gk/gk.open_gmaps?layers=topo2&zoom={Z}&x={X}&y={Y}',
               isPng:true,
               opacity:1.0 }
           );
   var layer5=[G_NORMAL_MAP.getTileLayers()[0],tile5];
   var statmap = new GMapType(layer5, G_NORMAL_MAP.getProjection(), "StatKart", {errorMessage:"No chart data available"});

//StatKart toporaster2
var copyCollection = new GCopyrightCollection('Kartgrunnlag:');
var copyright = new GCopyright(1, new GLatLngBounds(new GLatLng(-85, -180), new GLatLng(85, 180)), 0, '<a href="http://www.statkart.no">Statens kartverk</a>, <a href="http://www.statkart.no/nor/Land/Fagomrader/Geovekst/">Geovekst</a> og <a href="http://www.statkart.no/?module=Articles;action=Article.publicShow;ID=14194">kommuner</a>');
copyCollection.addCopyright(copyright);
  
    var tile6= new GTileLayer(copyCollection, 1, 14,
              {tileUrlTemplate: 'http://opencache.statkart.no/gatekeeper/gk/gk.open_gmaps?layers=toporaster2&zoom={Z}&x={X}&y={Y}',
               isPng:true,
               opacity:1.0 }
           );
   var layer6=[G_NORMAL_MAP.getTileLayers()[0],tile6];
   var statmap2 = new GMapType(layer6, G_NORMAL_MAP.getProjection(), "StatKart", {errorMessage:"No chart data available"});

   //StatKart sjo_hovedkart2
var copyCollection = new GCopyrightCollection('Kartgrunnlag:');
var copyright = new GCopyright(1, new GLatLngBounds(new GLatLng(-85, -180), new GLatLng(85, 180)), 0, '<a href="http://www.statkart.no">Statens kartverk</a>, <a href="http://www.statkart.no/nor/Land/Fagomrader/Geovekst/">Geovekst</a> og <a href="http://www.statkart.no/?module=Articles;action=Article.publicShow;ID=14194">kommuner</a>');
copyCollection.addCopyright(copyright);
  
    var tile7= new GTileLayer(copyCollection, 1, 14,
              {tileUrlTemplate: 'http://opencache.statkart.no/gatekeeper/gk/gk.open_gmaps?layers=sjo_hovedkart2&zoom={Z}&x={X}&y={Y}',
               isPng:true,
               opacity:1.0 }
           );
   var layer7=[G_NORMAL_MAP.getTileLayers()[0],tile7];
   var statmap3 = new GMapType(layer7, G_NORMAL_MAP.getProjection(), "StatKart", {errorMessage:"No chart data available"});

   
   
  
  baseIcon = new GIcon();
  baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
  baseIcon.iconSize = new GSize(20, 34);
  baseIcon.shadowSize = new GSize(37, 34);
  baseIcon.iconAnchor = new GPoint(9, 34);
  baseIcon.infoWindowAnchor = new GPoint(9, 2);
  baseIcon.infoShadowAnchor = new GPoint(18, 25);
        
	   
map.addMapType(statmap);
map.addMapType(statmap2);
map.addMapType(statmap3);
map.addMapType(G_PHYSICAL_MAP);
map.addMapType(dnmap);
map.addMapType(yrmap);
map.addMapType(OSM_MAPNIK_MAP);
map.addMapType(OSM_OCMNIK_MAP);
map.addMapType(OSM_OKMNIK_MAP);
map.addMapType(OTM_MAPNIK_MAP);

var mapControl = new GHierarchicalMapTypeControl();

// Set up map type menu relationships
mapControl.clearRelationships();
mapControl.addRelationship(statmap, statmap2, "TopoRaster", false);
mapControl.addRelationship(statmap, statmap3, "Sjokart", false);
mapControl.addRelationship(G_NORMAL_MAP, G_HYBRID_MAP, "Hybrid", false);
mapControl.addRelationship(G_NORMAL_MAP, G_SATELLITE_MAP, "Satelitt", false);
mapControl.addRelationship(G_NORMAL_MAP, G_PHYSICAL_MAP, "Terreng", false);
//mapControl.addRelationship(WMS_SE_MAP, , "testings");
mapControl.addRelationship(G_NORMAL_MAP, dnmap, "Verneomraader (test)", false);
mapControl.addRelationship(G_NORMAL_MAP, yrmap, "Vaerdata (test)", false);
mapControl.addRelationship(OSM_MAPNIK_MAP, OSM_OCMNIK_MAP, "OSM CloudMade");
mapControl.addRelationship(OSM_MAPNIK_MAP, OSM_OKMNIK_MAP, "OSM CycleMap");
mapControl.addRelationship(OSM_MAPNIK_MAP, OTM_MAPNIK_MAP, "OSM T&H");


// Add control after you've specified the relationships
var topRight = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(55,6));
map.addControl(mapControl, topRight);
map.addControl(new ExtMapTypeControl( { posRight: 263, showMore: true } ));

 
map.addControl(new GSmallMapControl());
map.addControl(new GScaleControl());
//map.addControl(new GOverviewMapControl());

 GEvent.addListener(map, 'moveend', moved);
 GEvent.addListener(map, 'zoom', zoomed);

map.setCenter(new GLatLng(0, 0), 0);
map.setMapType(statmap);
map.enableScrollWheelZoom();
map.enableContinuousZoom();



 modified('initsync', false);
 modified('initasync', true);
//  alert("initmap complete!");

 }

}