// remap jQuery to $
(function($){
	/* Spinner */
	$.spinner = {
		start: function() {
			$("#spinner").show();
		},
		stop: function () {
			$("#spinner").hide();
		}
	};

	$.cafeShow = function(x, y) {
		$("#headtitle").hide();
		$.spinner.start();
		$.post('/info/ajax.php?act=show', { lng: x, lat: y }, function(data) {
			if (data != "")
			{
				$.spinner.stop();
				$(data).appendTo('#content');
				$("#cafebox").slideDown().fadeIn();
			}
			else
			{
				$.spinner.stop();
				$("#headtitle").show();
			}
		});
		return false;
	}

	$.cafeHide = function() {
		$("#cafebox").slideUp().fadeOut(1000, function () {
			$(this).remove();
			$("#headtitle").fadeIn();
		});
		return false;
	}

	$.cafeRecommend = function(rec) {
		if ($("#text_response").val() != "")
		{
			$.post('/info/ajax.php?act=recommend', { cafe_id: $("#cafe_id").val(), response: $("#text_response").val(), type: rec }, function(data) {
				if (data != "")
				{
					$("#list_responses").hide().html(data).fadeIn();
					$("#response").fadeOut();
				}
				else
				{
					// Ошибка
					//$("#headtitle").show();
				}
			});
		}
		return false;
	}
})(window.jQuery);

function GetSizes() {
	var w=document.documentElement; var d=document.body;
	var tww = document.compatMode=='CSS1Compat' && !window.opera?w.clientWidth:d.clientWidth;
	var twh = document.compatMode=='CSS1Compat' && !window.opera?w.clientHeight:d.clientHeight;
	var sl = (window.scrollX)?window.scrollX:(w.scrollLeft)?w.scrollLeft:d.scrollLeft;
	var st = (window.scrollY)?window.scrollY:(w.scrollTop)?w.scrollTop:d.scrollTop;
	var wW1 = (window.innerHeight && window.scrollMaxY)?d.scrollWidth:(d.scrollHeight > d.offsetHeight)?d.scrollWidth:(w && w.scrollHeight > w.offsetHeight)?w.scrollWidth:d.offsetWidth;
	var wH1 = (window.innerHeight && window.scrollMaxY)?d.scrollHeight:(d.scrollHeight > d.offsetHeight)?d.scrollHeight:(w && w.scrollHeight > w.offsetHeight)?w.scrollHeight:d.offsetHeight;
	var wW2 = (self.innerHeight)?self.innerWidth:(w && w.clientHeight)?w.clientWidth:d.clientWidth; var pW = (wW1 < wW2)?wW2:wW1;
	var wH2 = (self.innerHeight)?self.innerHeight:(w && w.clientHeight)?w.clientHeight:d.clientHeight; var pH = (wH1 < wH2)?wH2:wH1;
	pW = ($.browser.msie)?pW:Math.max(w.scrollWidth, w.clientWidth, d.scrollWidth, d.offsetWidth);
	pH = ($.browser.msie)?pH:Math.max(w.scrollHeight, w.clientHeight, d.scrollHeight, d.offsetHeight);
	if (window.opera){ tww = (d.scrollWidth==d.clientWidth)?w.clientWidth:tww; twh = (d.scrollHeight==d.clientHeight)?w.clientHeight:twh;}
	return { 
		winWidth:tww, 
		winHeight: twh, 
		winScrollLeft: sl, 
		winScrollTop: st, 
		pageWidth: pW, 
		pageHeight: pH
	} 
}

/* trigger when page is ready */
$(document).ready(function (){
	var sizes = GetSizes();
	$("#YMapsID").css({ "width": sizes['winWidth'], "height": sizes['winHeight'] });
	if (sizes['pageHeight'] > sizes['winHeight'])
	{
		$("body").css({ "overflow-y": "scroll" });
	}
});

$(window).resize(function() {
	var sizes = GetSizes();
	$("#YMapsID").css({ "width": sizes['winWidth'], "height": sizes['winHeight'] });	

	if (sizes['pageHeight'] > sizes['winHeight'])
	{
		$("body").css({ "overflow-y": "scroll" });
	}
});

