

var baseIcon = new GIcon(G_DEFAULT_ICON);
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);

var map = null;
var centerD = false;
var shiftM = Array(0.002,0.0025);

var markerData = null;


var markerGroupsName 
	= Array("typ1","typ2","typ3","typ4","typ5","typ6","typ51","typ50",
		"typ100","typ101","typ102","typ103","typ104","typ105","typ106","typ107","typ108","typ109");
var markerGroups = { 
	"typ1": [],
	"typ2": [],
	"typ3": [],
	"typ4": [],
	"typ5": [],
	"typ6": [],
	"typ51": [],
	"typ50": [],
	"typ100": [],
	"typ101": [],
	"typ102": [],
	"typ103": [],
	"typ104": [],
	"typ105": [],
	"typ106": [],
	"typ107": [],
	"typ108": [],
	"typ109": []
}

function toggleGroup(type) {

    for (var i = 0; i < markerGroups[type].length; i++) {
        var marker = markerGroups[type][i];
        if (marker.isHidden()) {
          marker.show();
        } else {
          marker.hide();
        }
    } 
}

function showGroupAll() {

	for (var j = 0; j < markerGroupsName.length; j++) {
	    for (var i = 0; i < markerGroups[markerGroupsName[j]].length; i++) {
	        var marker = markerGroups[markerGroupsName[j]][i];
	        marker.show();
	    } 
	}
}


function hideGroupAll() {

	for (var j = 0; j < markerGroupsName.length; j++) {
	    for (var i = 0; i < markerGroups[markerGroupsName[j]].length; i++) {
	        var marker = markerGroups[markerGroupsName[j]][i];
	        marker.hide();
	    } 
	}

}

function loadGM(mdata,gmapParam) {

	if (gmapParam==undefined) { gmapParam = ""; }

    if (gmapZoom==0) { gmapZ = 14; } else { gmapZ = 14+gmapZoom; }
    if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("gMapD"));
        map.setCenter(new GLatLng(50.63049055890759, 15.777783393859863), gmapZ);
    }
	if (gmapZoom!=0) {
    	map.addControl(new GLargeMapControl());
	} else {
    	map.addControl(new GSmallMapControl());
	}
    map.addControl(new GMapTypeControl());

	// -- lanovky
    
    ew = new EWindow(map, E_STYLE_7);      
    map.addOverlay(ew);  

	if (mdata!=undefined && mdata!=-1) {
		shiftM = Array(0.004,0.005);

		m = mdata.split('|');
		typ = m[5]*1;
		i = 0;

		map.addOverlay(createMarker(new GLatLng(m[0], m[1]),i, m[2], m[3], m[4],1,typ));
		map.setCenter(new GLatLng(m[0]*1+shiftM[0], m[1]*1+shiftM[1]), 14);
		centerD = true;
	} else {
    
	    $.get("/gmap/?param="+gmapParam+"&ln="+gmapLang+"&gps=1", function(data){   
			markerData = data.split("\n");
	        addMarker(0);
	    });  
	}

}  

function drawLines() {

	var polyline = new GPolyline([  
			new GLatLng(50.772668305302396, 15.42568176984787),  
			new GLatLng(50.76168734550083, 15.429493188858032)], "#000000", 10, 0.5);
	map.addOverlay(polyline);
	var polyline = new GPolyline([  
			new GLatLng(50.772668305302396, 15.42568176984787),  
			new GLatLng(50.76168734550083, 15.429493188858032)], "#67d9e2", 8, 1);
	map.addOverlay(polyline);

	var polyline = new GPolyline([  
			new GLatLng(50.764591876001916, 15.442711114883422),  
			new GLatLng(50.76144981750833, 15.431756973266601)], "#000000", 10, 0.5);
	map.addOverlay(polyline);
	var polyline = new GPolyline([  
			new GLatLng(50.764591876001916, 15.442711114883422),  
			new GLatLng(50.76144981750833, 15.431756973266601)], "#67d9e2", 8, 1);
	map.addOverlay(polyline);
} 

function addMarker(i) {
		mapsI = markerData;
		if (i<mapsI.length) {
        //for (var i=0; i<mapsI.length; i++) {
            m = mapsI[i];
            m = m.split('|');
			typ = m[5]*1;
	
			var aM = createMarker(new GLatLng(m[0], m[1]),i, m[2], m[3], m[4],0, typ);
			markerGroups["typ"+typ].push(aM);
            map.addOverlay(aM);            

			setTimeout('addMarker('+(i+1)+')', 5);	
        } 		
} 

function animUImg(im,go) {
    if (go==0) {

        if (im.css("width")=="95px") {
            im.animate({ 
                width: "150px",
                height: "113px",
                left: "-27px",
                top: "-21px"
              }, 400 );    
        }
    } else {
        if (im.css("width")!="95px") {
            im.animate({ 
                width: "95px",
                height: "70px",
                left: "0px",
                top: "0px"/*,
                left: "-27px",
                top: "-21px"*/
              }, 100);    
        }
    }          
    return 0;
}
        
function createMarker(point, index, id, letter, tip, open, typ) {
    // Create a lettered icon for this point using our icon class
    //var letter = String.fromCharCode("A".charCodeAt(0) + index);

    var letteredIcon = new GIcon(baseIcon);

	switch (typ) {
	case 101:
    	letteredIcon.image = "http://www.janskelazne.cz/img/gicons/g-info.png";
		break;
	case 104:
    	letteredIcon.image = "http://www.janskelazne.cz/img/gicons/g-blue.png";
		break;
	case 102:
    	letteredIcon.image = "http://www.janskelazne.cz/img/gicons/g-green.png";
		break;
	case 107:
    	letteredIcon.image = "http://www.janskelazne.cz/img/gicons/g-muzeum.png";
		break;
	case 100:
	case 109:
    	letteredIcon.image = "http://www.janskelazne.cz/img/gicons/g-orange.png";
		break;
	case 106:
    	letteredIcon.image = "http://www.janskelazne.cz/img/gicons/g-sport.png";
		break;
	case 103:
    	letteredIcon.image = "http://www.janskelazne.cz/img/gicons/g-lanovka.png";
		break;
	case 105:
    	letteredIcon.image = "http://www.janskelazne.cz/img/gicons/g-turista.png";
		break;
	case 108:
    	letteredIcon.image = "http://www.janskelazne.cz/img/gicons/g-exchange.png";
		break;
	default:
    	letteredIcon.image = "http://www.google.com/mapfiles/marker" + letter + ".png";
	}

    // Set up our GMarkerOptions object
    markerOptions = { icon:letteredIcon, title:tip };
    var marker = new GMarker(point, markerOptions);

    $("a#marker"+id).click(function() {
		map.panTo(new GLatLng(marker.getPoint().lat()*1+shiftM[0], marker.getPoint().lng()*1+shiftM[1]));
        $.get("/gmap/?id="+id, function(data){
            ew.openOnMarker(marker,data);           
        });
	});

    GEvent.addListener(marker, "click", function() {    
		             
        map.panTo(new GLatLng(marker.getPoint().lat()*1+shiftM[0], marker.getPoint().lng()*1+shiftM[1]));
        $.get("/gmap/?ln="+gmapLang+"&id="+id, function(data){
            ew.openOnMarker(marker,data);           
        });
        
    });

	if (open) {
		
        $.get("/gmap/?ln="+gmapLang+"&id="+id, function(data){
			ew.openOnMarker(marker,data);
		});
	}

    return marker;
} 

// Version 0.0  Initial version 
// Version 0.1  10/10/2006 Added E_STYLE_7 
// Version 0.2  17/05/2007 Added .isHidden() and .supportsHide()
// Version 0.3  14/09/2007 added .zindex()


function EStyle(stemImage, stemSize, boxClass, boxOffset) {
    this.stemImage = stemImage;
    this.stemSize = stemSize;
    this.boxClass = boxClass;
    this.boxOffset = boxOffset;
    //this.border = border;

    // Known fudge factors are:
    // Firefox (1.0.6 and 1.5)    5, -1
    // IE 6.0                     0, -1
    // Opera 8.54                 3, -1
    // Opera 9 prev               4, -1
    // Netscape (7.2, 8.0)        5, -1
    // Safari                     5, -1        

    var agent = navigator.userAgent.toLowerCase();

    var fudge = 5;  // assume Netscape if no match found

    if (agent.indexOf("opera") > -1) {
      fudge = 3;
    }   
    if (agent.indexOf("firefox") > -1) {
      fudge = 5;
    }   
    if (agent.indexOf("safari") > -1) {
      fudge = 5;
    }   
    if ((agent.indexOf("msie") > -1) && (agent.indexOf("opera") < 1)){
      fudge = 0;
    }
    this.fudge = fudge;
    }

    var E_STYLE_7 = new EStyle("img/gmap-arr.png", new GSize(0,0),  "gmapStyle", new GPoint(-73,-36));

    function EWindow(map,estyle) {
    // parameters
    this.map=map;
    this.estyle=estyle;
    // internal variables
    this.visible = false;
    // browser - specific variables
    this.ie = false;
    var agent = navigator.userAgent.toLowerCase();
    if ((agent.indexOf("msie") > -1) && (agent.indexOf("opera") < 1)){ this.ie = true} else {this.ie = false}
} 

EWindow.prototype = new GOverlay();

EWindow.prototype.initialize = function(map) {
    var div1 = document.createElement("div");
    div1.style.position = "absolute";
    map.getPane(G_MAP_FLOAT_SHADOW_PANE).appendChild(div1);
    var div2 = document.createElement("div");
    div2.style.position = "absolute";
    div2.style.width = this.estyle.stemSize.width+"px";
    map.getPane(G_MAP_FLOAT_SHADOW_PANE).appendChild(div2);
    this.div1 = div1;
    this.div2 = div2;
}

EWindow.prototype.openOnMap = function(point, html, offset) {
    this.offset = offset||new GPoint(0,0);
    this.point = point;
    this.div1.innerHTML = '<div class="' + this.estyle.boxClass + '"><div class="inGW">' + html + '</div><a href="javascript:ew.hide()" class="gwClose"></a></div>';
    if (this.ie && this.estyle.stemImage.toLowerCase().indexOf(".png")>-1) {
      var loader = "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+this.estyle.stemImage+"', sizingMethod='scale');";
      this.div2.innerHTML = '<div style="height:' +this.estyle.stemSize.height+ 'px; width:'+this.estyle.stemSize.width+'px; ' +loader+ '" ></div>';
    } else {
      this.div2.innerHTML = '<img src="' + this.estyle.stemImage + '" width="' + this.estyle.stemSize.width +'" height="' + this.estyle.stemSize.height +'">';
    }
    var z = GOverlay.getZIndex(this.point.lat());
    this.div1.style.zIndex = z;
    this.div2.style.zIndex = z+1;
    this.visible = true;
    this.show();
    this.redraw(true);
}

EWindow.prototype.openOnMarker = function(marker,html) {
    var vx = marker.getIcon().iconAnchor.x - marker.getIcon().infoWindowAnchor.x;
    var vy = marker.getIcon().iconAnchor.y - marker.getIcon().infoWindowAnchor.y;
    this.openOnMap(marker.getPoint(), html, new GPoint(vx,vy));
}


EWindow.prototype.redraw = function(force) {
    if (!this.visible) {return;}
    var p = this.map.fromLatLngToDivPixel(this.point);
    this.div2.style.left   = (p.x + this.offset.x) + "px";
    this.div2.style.bottom = (-p.y + this.offset.y -this.estyle.fudge) + "px";
    this.div1.style.left   = (p.x + this.offset.x + this.estyle.boxOffset.x) + "px";
    this.div1.style.bottom = (-p.y + this.offset.y + this.estyle.boxOffset.y) + "px";
}

EWindow.prototype.remove = function() {
    this.div1.parentNode.removeChild(this.div1);
    this.div2.parentNode.removeChild(this.div2);
    this.visible = false;
}

EWindow.prototype.copy = function() {
    return new EWindow(this.map, this.estyle);
}

EWindow.prototype.show = function() {
    this.div1.style.display="";
    this.div2.style.display="";
    this.visible = true;
}

EWindow.prototype.hide = function() {
    this.div1.style.display="none";
    this.div2.style.display="none";
    this.visible = false;
}

EWindow.prototype.isHidden = function() {
    return !this.visible;
}

EWindow.prototype.supportsHide = function() {
    return true;
}

EWindow.prototype.zindex = function(zin) {
    var z = GOverlay.getZIndex(this.point.lat());
    this.div1.style.zIndex = z+zin;
    this.div2.style.zIndex = z+1+zin;
}

