var bChangeMapZoom = true;

$(document).ready(function() {
	
	resizeTools();

	$(".ui-slider").slider({
		axis: "vertical",
		max: "18",		
		change: function(e, ui) {
			var wartosc = ui.value;
			if (bChangeMapZoom === true){
  			map.setZoom(wartosc);      
      }else {
        //przywroc domyslne ustawienie
        bChangeMapZoom = true;
      }
		}
	});
	

	
	$("#zoom_out").click(function() {
		$(".ui-slider").slider("moveTo", "-=1");
	//	map.zoomOut();
	});
	
	$("#zoom_in").click(function() {
		$(".ui-slider").slider("moveTo", "+=1");
		// map.zoomIn();
	});

	$("#map_navi img").click(function() {
		var src = $(this).attr("src");
		if(src.search(/_a.png/i) == -1) {
			replaceImages();
			$(this).attr("src", src.replace(/_n.png/i, "_a.png"));
			$(this).attr("src", src.replace(/_o.png/i, "_a.png"));
			switch($(this).attr("alt")) {
				case "Mapa":
				  map.setMapType(G_NORMAL_MAP);
					break;
				case "Satelita":
				 map.setMapType(G_SATELLITE_MAP);
					break;
				case "Hybryda":
				 map.setMapType(G_HYBRID_MAP);
					break;
			}
		}
	});

	$("#map_navi img").mouseover(function() {
		var src = $(this).attr("src");
		if(src.search(/_a.png/i) == -1) {			
			$(this).attr("src", src.replace(/_n.png/i, "_o.png"));
		} else {
			$(this).attr("src", src.replace(/_a.png/i, "_b.png"));      
    }				
	});
	
	$("#map_navi img").mouseout(function() {
  	$("#map_navi img").each(function() {
  		var src = $(this).attr("src");
  		
  		if(src.search(/_b.png/i) == -1) {			
  			$(this).attr("src", src.replace(/_o.png/i, "_n.png"));
  		} else {
  			$(this).attr("src", src.replace(/_b.png/i, "_a.png"));      
      }			

  	//	$(this).attr("src", src.replace(/_o.png/i, "_n.png"));
  	});
	});	
	
	
	$("#moveLeft").click(function(){
		map.panDirection(1,0); //x, y   -1: left/up +1: right/down
	});

	$("#moveRight").click(function(){
		map.panDirection(-1,0);
	});

	$("#moveTop").click(function(){
		map.panDirection(0,1);
	});

	$("#moveDown").click(function(){
		map.panDirection(0,-1);
	});
	
	$("#mapReset").click(function(){
		resetMap();
	});
	
	$("span.polska").click(function() {
		resetMap();
	});

	$("#refresh_map").click(function() {
		refreshMap();
	});
	
	$("#legend_link img").mouseover(function() {
        $("#map_legend").fadeIn("fast");
    }).mouseout(function() {
        $("#map_legend").fadeOut("fast");
    });
	
});

function replaceImages() {
	$("#map_navi img").each(function() {
		var src = $(this).attr("src");
		$(this).attr("src", src.replace(/_a.png/i, "_n.png"));
	});
}

function resizeTools() {
	var pos = $("#mapka").position();
	var w = $("#mapka").width();
	$("#map_tools").css("left", pos.left);
	$("#map_tools").css("top", pos.top);
	$("#map_tools").css("width", w);
 	if($.browser.msie) {
        $("#map_tools").css("z-index", "10");
    }
	$("#map_navi").css("position", "absolute");



    var pos2 = $("#search_bar_right").position();
    var h2 = $("#search_bar_right").height();

    $("#map_navi").css("top", (pos2.top + h2) + "px");
    $("#map_navi").css("left", (pos2.left + 300) + "px");

    $("#tloprzesuwaka").css("left", pos2.left + "px");
	$("#tloprzesuwaka").css("top", pos2.top + h2 + "px");

	
//	console.debug($("#map_navi").css("top"));




    $("#map_legend").css("left", pos.left - 25);
	$("#map_legend").css("top", pos.top + 414);
	$("#map_legend").css("z-index", "100");

}

function moveSliderTo(zoomLevel){
	$(".ui-slider").slider("moveTo", zoomLevel);
}

function changeIcon(txt){  
    //$("#maptypeh").attr("src","/_items/mm/images/maptools/but/"+txt+"_o.png");
   	var src = $(this).attr("src");
    $(this).attr("src", src.replace(/_o.png/i, "_n.png"));
}

function restoreIcons(){
	$("#map_navi img").each(function() {
		var src = $(this).attr("src");
		$(this).attr("src", src.replace(/_o.png/i, "_n.png"));
	});
}




$(document).ready(function() {
    $("#chmurka").css("z-index", "11");

//    var pos = $("#chmurka_close").position();
//    alert(pos);
});


