var ESC_CODE_KEY = 27;
var ENTER_CODE_KEY = 13;

var INIT_MAP_SCALE=14;

// здесь я вставляю свой код
 var hotel=hotelObj[0].hotels[0];
 var hotelInfo=hotelObj[1].hotel;
// вставил

// теперь я комменчу чужую функцию
/*
$(document).ready(function() {
	var hotel=hotelObj[0].hotels[0];
	var hotelInfo=hotelObj[1].hotel;

	AddMapMenuItem(hotel,hotelInfo);
});
*/
// здесь добавляю свою функцию
function show_map(page_name)
{
 var hotel=hotelObj[0].hotels[0];
 var hotelInfo=hotelObj[1].hotel;

 UpdateMenu(page_name);
 ShowMap(hotel);
 ShowMarker(hotel,hotelInfo);
}

function GetMenuItemHtml(menuType,menuText,menuLink){
	switch(menuType){
		case "white":
			return "\
<li class='hot hot1'>\
<a href='"+menuLink+"' class='hot'>\
"+menuText+" \
<img src='/images/emp.gif' width='0' height='1' alt='' border='0'>\
</a>\
</li>\
			";
		case "blue":
			return "\
<li class='hot hot1'>\
<a href='"+menuLink+"' class='hotel_menu'>\
<span id='top_nav' >\
"+menuText+" \
<img src='/images/arr_hotel_menu_white.png' width='4' height='7' alt='' border='0'>\
</a>\
</span>\
</li>\
			";
		case "active":
			return "\
<li class='hot hot1'>\
<span id='current'>\
"+menuText+"\
</span>\
</li>\
			";
		default:
			return "";
	}
}

function AddMapMenuItem(hotel,hotelInfo){
	var jMenuItem=$(" "+GetMenuItemHtml("white","Map","#"));

	jMenuItem.find("a").click(function(){
		UpdateMenu();
		ShowMap(hotel);
		ShowMarker(hotel,hotelInfo);
		return false;
	});
	
	$("ul.hot li:eq(3)").after(jMenuItem);
}

function UpdateMenu(page_name){
	var menuItems=[
		["white","О гостинице","/rus/"+page_name+"-price.htm"],
		["white","Номера","/rus/"+page_name+"-rooms.htm"],
		["white","Услуги","/rus/"+page_name+"-services.htm"],
		["white","Рестораны","/rus/"+page_name+"-restaurants.htm"],
		["active","Карта",""],
        ["white","Фото","/rus/"+page_name+"-images.htm"],
		["blue","Бронирование","/rus/"+page_name+"-reservations.htm"]
	];
	
	var menuItemsHtml=[];
	
	for(var i=0;i<menuItems.length;i++){
		var menuItem=menuItems[i];
		menuItemsHtml.push(GetMenuItemHtml(menuItem[0],menuItem[1],menuItem[2]));
	}
	
	$("ul.hot").html(menuItemsHtml.join(""));
}

function ShowMap(hotel){	
	$("div.map_anchor").find("div").remove();
	$("div.map_anchor").append($("<div id='map'></div>"));
	
	var hotelScale=INIT_MAP_SCALE;
	var hotelLat=parseFloat(hotel.lat);
	var hotelLng=parseFloat(hotel.lng);

	var showIndicator=false;
	
	SetMapModule(hotelLat,hotelLng,hotelScale,showIndicator);
}

function ShowMarker(hotel,hotelInfo){
	var numResult=0;
	var hotelIcon;
	switch (hotel.star) {
		case "0":
			hotelIcon = GetCustomIcon(mapIcons.noStars,numResult);
			break;
		case "1":
			hotelIcon = GetCustomIcon(mapIcons.oneStar,numResult);
			break;
		case "2":
			hotelIcon = GetCustomIcon(mapIcons.twoStars,numResult);
			break;
		case "3":
			hotelIcon = GetCustomIcon(mapIcons.threeStars,numResult);
			break;
		case "4":
			hotelIcon = GetCustomIcon(mapIcons.fourStars,numResult);
			break;
		case "5":
			hotelIcon = GetCustomIcon(mapIcons.fiveStars,numResult);
			break;
	}

	//создаем маркер
	var marker = new GMarker(
		new GLatLng(parseFloat(hotel.lat), parseFloat(hotel.lng)),
		{
			draggable: false,
			bouncy: false,
			title: hotel.hotelname,
			icon: hotelIcon
		}
	);

	//добавляем обработчик клика на маркере
	GEvent.addListener(marker, 'click', function(){
		ShowBalloon(marker,hotelInfo);
	});

	map.addOverlay(marker);
	
	ShowBalloon(marker,hotelInfo);
}

function GetCustomIcon(icon,numResult){
	return new GIcon(icon,icon.image.replace("image.png","/images/"+numResult+".png"));
}

function GetStarsHtml(hotelStars,imageFileName){
	var starsImage="<img width='12' height='14' border='0' src='/images/"+imageFileName+"' alt=''>";
	var starsImages=[];
	
	if(hotelStars>0){
		for(var i=0;i<hotelStars;i++){
			starsImages.push(starsImage);
		}
	}
	
	return starsImages.join("");
}


function ShowBalloon(marker,hotelInfo) {
	var baloonTemplate="\
<div id='balloon_"+hotelInfo.shortname+"' class='map_info_window'>\
<table cellspacing='0' cellpadding='0' width='100%' height='100%'>\
<tr>\
<td>\
<table width='100%'>\
<tbody>\
<tr>\
<td valign='top' width='23'>\
<img class='map_info_icon' width='23' height='23' src='"+marker.getIcon().image+"' alt=''>\
</td>\
<td valign='top' align='left'>\
<a href='/rus/"+hotelInfo.pagename+"-price.htm'  class='map_info_hotelname font14 colored'>\
"+hotelInfo.hotelname+"\
</a>\
</td>\
<td class='map_info_stars' valign='top' align='right' width='60' >\
"+GetStarsHtml(hotelInfo.star,"star_cut_white.gif")+"\
</td>\
<td width='6'>\
</td>\
</tr>\
</tbody>\
</table>\
</td>\
</tr>\
<tr>\
<td>\
<table width='100%'>\
<tbody>\
<tr>\
<td valign='top'>\
<table width='100%' height='115'>\
<tbody>\
<tr>\
<td valign='top'>\
<span class='map_info_description font11'>"+hotelInfo.description+"</span>\
</td>\
</tr>\
<tr>\
<td valign='top'>\
<a href='/rus/"+hotelInfo.pagename+"-price.htm'  class='map_info_pricepage font11 colored'>Дополнительно</a>\
</td>\
</tr>\
<tr>\
<td>\
<a href='/rus/"+hotelInfo.pagename+"-reservations.htm'  class='map_info_reservationspage font13 bolded colored'>Бронировать!</a>\
</td>\
</tr>\
</tbody>\
</table>\
</td>\
<td valign='top' width='115'>\
<img class='map_info_image' width='115' height='115' src='http://64.106.243.48"+hotelInfo.image+"' alt=''>\
</td>\
</tr>\
</tbody>\
</table>\
</td>\
</tr>\
<tr>\
<td>\
<span class='font11 bolded'>Адрес: </span>\
<span class='map_info_address font11'>"+hotelInfo.address+"</span>\
</td>\
</tr>\
<tr>\
<td valign='bottom' align='right'>\
<span class='font11 bolded'>Звоните +7-812-309-57-60</span>\
</td>\
</tr>\
</table>\
</div>\
";
	
	marker.openInfoWindowHtml(baloonTemplate, {});
}
