var map;
function ShowMap(Flat_c1, Flat_c2, Map_c1, Map_c2, Map_Zoom, BContent, BTitle) {
	document.getElementById('metka').scrollIntoView();
	YMaps.load(function () {
		var mapContainer = YMaps.jQuery("#YMapsID"),
		map = new YMaps.Map(mapContainer[0]);
		mapContainer.css("display", "");
		var Placemark;
		try {
			if (HTitles) {
				for (var i = 0; i < HTitles.length; i++) {
					Placemark = new YMaps.Placemark(new YMaps.GeoPoint(H_Coords2[i], H_Coords1[i]));
					Placemark.setBalloonContent(HTitles[i]);
					Placemark.setIconContent(HTitles[i]);
					map.addOverlay(Placemark);
				}
			}
		} catch (e) {}
		Placemark = new YMaps.Placemark(new YMaps.GeoPoint(Flat_c2, Flat_c1));
		Placemark.setBalloonContent(BContent);
		Placemark.setIconContent(BTitle);
		map.addOverlay(Placemark);
		map.setCenter(new YMaps.GeoPoint(Map_c2, Map_c1), Map_Zoom);
		map.addControl(new YMaps.TypeControl());
		map.addControl(new YMaps.ToolBar());
		map.addControl(new YMaps.Zoom());
	});
}

var hspitemsHTML;
var blockhotels = new Array();
blockhotels[0] = 3;
blockhotels[1] = 3;
blockhotels[2] = 3;
var hotels_uploaded = 6;
var selAreaClicked = false;
if (document.readyState && (jQuery.browser.msie || jQuery.browser.opera))
	document.onreadystatechange = fnStartInit;
else
	document.addEventListener("DOMContentLoaded", fnStartInit, false);
function fnStartInit() {
	if (document.readyState && (jQuery.browser.msie || jQuery.browser.opera))
		if (document.readyState != "complete" && document.readyState != "loaded")
			return;
	
	if ($(".hspitems ul").length > 0)
		hspitemsHTML = $(".hspitems ul")[0].innerHTML;
}

function AttachCoolButtons(selector) {
	$(selector).parent().focus(function () {
		$(this).blur();
	});
	$(selector).mouseover(function () {
		if (this.src.toString().indexOf("dsbl") != -1)
			return;
		if (this.src.toString().indexOf("-hover.") == -1) {
			this.src = this.src.toString().substring(0, this.src.toString().length - 4) + "-hover"
				 + this.src.toString().substring(this.src.toString().length - 4, this.src.toString().length);
		}
	});
	$(selector).mouseout(function () {
		if (this.src.toString().indexOf("dsbl") != -1)
			return;
		if (this.src.toString().indexOf("-hover.") != -1)
			this.src = this.src.toString().replace("-hover", "");
		else if (this.src.toString().indexOf("-pres.") != -1)
			this.src = this.src.toString().replace("-pres", "");
	});
	$(selector).mousedown(function () {
		if (this.src.toString().indexOf("dsbl") != -1)
			return;
		if (this.src.toString().indexOf("-hover") != -1)
			this.src = this.src.toString().replace("-hover", "-pres");
	});
	$(selector).mouseup(function () {
		if (this.src.toString().indexOf("dsbl") != -1)
			return;
		if (this.src.toString().indexOf("-pres") != -1)
			this.src = this.src.toString().replace("-pres", "-hover");
	});
}
$(document).click(function () {
	if ($("#selAreaItems").css("display") != "none" && selAreaClicked == false)
		$("#selAreaItems").slideUp(200);
	selAreaClicked = false;
});
$(document).ready(function () {
	AttachCoolButtons("img.coolbtn");
	$("#srchType input").click(function () {
		$("#srchType label").each(function () {
			this.className = "";
		});
		$(this).next()[0].className = "sel";
	});
	$(".expandhotels").click(function () {
		$("#divZoom").css("visibility", "hidden");
		var oTopItem = jQuery(this).parent().parent();
		if (jQuery(this).find("img")[0].src.toString().indexOf("minimize") != -1) {
			oTopItem.next('.sahgroup').hide(500);
			jQuery(this).find("img")[0].src = jQuery(this).find("img")[0].src.toString().replace("minimize", "maximize");
			jQuery(this).find("u")[0].innerHTML = "Развернуть номера";
		} else {
			var _w = oTopItem.next('.sahgroup');
			if (_w.find('.sahitem').length == 0) {
				var _id = _w.attr('id');
				jQuery.post('http://'+window.location.hostname+'/wp-content/themes/default/numer-ajax.php', 'hotel_id=' + _id, function (response) {
					_w.html(response);
				});
			}
			_w.show(500);
			jQuery(this).find("img")[0].src = jQuery(this).find("img")[0].src.toString().replace("maximize", "minimize");
			jQuery(this).find("u")[0].innerHTML = "Свернуть номера";
		}
	});
	$("#hmenu a").mouseover(function () {
		this.style.textDecoration = 'underline';
	});
	$("#hmenu a").mouseout(function () {
		this.style.textDecoration = 'none';
	});
	$("#selAreaItems div").mouseover(function () {
		this.className = "sel";
	});
	$("#selAreaItems div").mouseout(function () {
		this.className = "";
	});
	$("#selAreaItems div").click(function () {
		selAreaClicked = true;
		$("#selArea")[0].innerHTML = this.innerHTML;
		$("#selAreaItems").slideUp(200);
		try {
			var tlels = document.getElementById('selAreaItems').getElementsByTagName('div');
			for (var i = 0; i < tlels.length; i++) {
				var tlel = tlels[i];
				if (tlel.id != "saif" && tlel.id != "sait")
					tlel.style.display = "";
			}
			this.style.display = 'none';
		} catch (err) {}
	});
	$("#selArea").click(function () {
		selAreaClicked = true;
		if ($("#selAreaItems").css("display") == "none") {
			var pos = getAbsolutePos(this);
			$("#selAreaItems").css("top", pos.y + this.clientHeight - 12);
			$("#selAreaItems").css("left", pos.x);
			$("#selAreaItems").slideDown(200);
		} else
			$("#selAreaItems").slideUp(200);
	});
	$(".optPlaceCountItem").click(function () {
		var sdasdsadtbcl = false;
		if (this.className == "optPlaceCountItem sel")
			sdasdsadtbcl = true;
		$(".optPlaceCountItem").each(function () {
			this.className = "optPlaceCountItem";
		});
		if (!sdasdsadtbcl)
			this.className = "optPlaceCountItem sel";
		//else
		//	this.className = "optPlaceCountItem";
	});
	$("#zfrmhotelclass").mouseup(function () {
		starsonchange();
	});
	$("#zfrmhotelclass").mouseover(function () {
		starsonchange();
	});
	$("#zfrmhotelclass").mouseout(function () {
		starsonchange();
	});
	$("#zfrmhotelclass").mousemove(function () {
		starsonchange();
	});
	function starsonchange() {
		var vFrom = ZForms.aForms.zfrmhotelclass.aWidgets.zfrmhcnumberfrom.oValue.mValue;
		var vTo = ZForms.aForms.zfrmhotelclass.aWidgets.zfrmhcnumberto.oValue.mValue;
		switch (vFrom) {
		case 1:
			if ($("#srchstarsfrom")[0].className != "srchstars one")
				$("#srchstarsfrom")[0].className = "srchstars one";
			break;
		case 2:
			if ($("#srchstarsfrom")[0].className != "srchstars two")
				$("#srchstarsfrom")[0].className = "srchstars two";
			break;
		case 3:
			if ($("#srchstarsfrom")[0].className != "srchstars three")
				$("#srchstarsfrom")[0].className = "srchstars three";
			break;
		case 4:
			if ($("#srchstarsfrom")[0].className != "srchstars four")
				$("#srchstarsfrom")[0].className = "srchstars four";
			break;
		case 5:
			if ($("#srchstarsfrom")[0].className != "srchstars five")
				$("#srchstarsfrom")[0].className = "srchstars five";
			break;
		default:
			if ($("#srchstarsfrom")[0].className != "srchstars one")
				$("#srchstarsfrom")[0].className = "srchstars one";
			break;
		}
		switch (vTo) {
		case 1:
			if ($("#srchstarsto")[0].className != "srchstars one")
				$("#srchstarsto")[0].className = "srchstars one";
			break;
		case 2:
			if ($("#srchstarsto")[0].className != "srchstars two")
				$("#srchstarsto")[0].className = "srchstars two";
			break;
		case 3:
			if ($("#srchstarsto")[0].className != "srchstars three")
				$("#srchstarsto")[0].className = "srchstars three";
			break;
		case 4:
			if ($("#srchstarsto")[0].className != "srchstars four")
				$("#srchstarsto")[0].className = "srchstars four";
			break;
		case 5:
			if ($("#srchstarsto")[0].className != "srchstars five")
				$("#srchstarsto")[0].className = "srchstars five";
			break;
		default:
			if ($("#srchstarsto")[0].className != "srchstars one")
				$("#srchstarsto")[0].className = "srchstars one";
			break;
		}
	}
	var i = 100;
	$(".tab").each(function () {
		if (this.className.toString().indexOf("sel") > -1)
			$(this).css("z-index", 101);
		else
			$(this).css("z-index", i);
		i = i - 1;
	});
});
function getAbsolutePos(el) {
	var r = {
		x : el.offsetLeft,
		y : el.offsetTop
	};
	if (el.offsetParent) {
		var tmp = getAbsolutePos(el.offsetParent);
		r.x += tmp.x;
		r.y += tmp.y;
	}
	if (navigator.appName == "Netscape")
		r.y -= 0;
	return r;
}

function MM_preloadImages() {
	var d = document;
	if (d.images) {
		if (!d.MM_p)
			d.MM_p = new Array();
		var i,
		j = d.MM_p.length,
		a = MM_preloadImages.arguments;
		for (i = 0; i < a.length; i++)
			if (a[i].indexOf("#") != 0) {
				d.MM_p[j] = new Image;
				d.MM_p[j++].src = a[i];
			}
	}
}
MM_preloadImages("images/btnfeedback2-hover.gif", "images/btnfeedback2-pres.gif", "images/btnfeedback-hover.gif", "images/btnfeedback-pres.gif",
	"images/btnfind2-hover.gif", "images/btnfind2-pres.gif", "images/btnfind-hover.gif", "images/btnfind-pres.gif", "images/btnminimize-hover.gif",
	"images/btnminimize-pres.gif", "images/btnmore-hover.gif", "images/btnmorelight-hover.gif", "images/btnmorelight-pres.gif", "images/btnmore-pres.gif",
	"images/btnorder-hover.gif", "images/btnorder-pres.gif", "images/btnreadfeedbacks-hover.gif", "images/btnreadfeedbacks-pres.gif",
	"images/btntakenumber-hover.gif", "images/btntakenumber-pres.gif", "images/btnvote-hover.gif", "images/btnvote-pres.gif",
	"images/lookonmap-hover.gif", "images/lookonmap-pres.gif", "images/navl.gif", "images/navl-hover.gif", "images/navl-pres.gif",
	"images/navr-hover.gif", "images/navr-pres.gif", "images/btnmaximize-hover.gif", "images/btnmaximize-pres.gif", "images/sait.gif", "images/saib.gif",
	"images/saif.gif");

