$(document).ready(function() {
	$('#usernameLoading').hide();
	$('#username').blur(function(){
	  $('#usernameLoading').show();
      $.post("/enter.php", {
        username: $('#username').val(), act: 'checkname'
      }, function(response){
        $('#usernameResult').fadeOut();
        setTimeout("finishAjax('usernameResult', '"+escape(response)+"')", 400);
      });
    	return false;
	});
});

function finishAjax(id, response) {
  $('#usernameLoading').hide();
  $('#'+id).html(unescape(response));
  $('#'+id).fadeIn();
}

function minus(id,price) { document.getElementById('kolvo' + id).value--; pereschet(id,price); }
function plus(id,price) { document.getElementById('kolvo' + id).value++; pereschet(id,price); }
function minus05(id,price) { document.getElementById('kolvo' + id).value = document.getElementById('kolvo' + id).value*1 - 0.5; pereschet05(id,price); }
function plus05(id,price) { document.getElementById('kolvo' + id).value = document.getElementById('kolvo' + id).value*1 + 0.5; pereschet05(id,price); }

function minus1(id,price) { document.getElementById('kolvo' + id).value--; pereschet1(id,price) }
function plus1(id,price) { document.getElementById('kolvo' + id).value++; pereschet1(id,price) }
function pereschet1(id,price) {
	$('#summa' + id).fadeIn();
	if (document.getElementById('kolvo' + id).value < 1) document.getElementById('kolvo' + id).value = 0;
	if (document.getElementById('kolvo' + id).value > 3) document.getElementById('kolvo' + id).value = 3;
	document.getElementById('kolvo' + id).value = Math.round(document.getElementById('kolvo' + id).value);
	if (document.getElementById('kolvo' + id).value == "NaN") document.getElementById('kolvo' + id).value = 0;
	document.getElementById('summa' + id).innerHTML = '';
	document.getElementById('summa' + id).innerHTML += document.getElementById('kolvo' + id).value * price;
	document.getElementById('summa' + id).innerHTML += ' руб.<span>' + document.getElementById('kolvo' + id).value * document.getElementById('weight' + id).value + ' гр.</span>';
	document.getElementById('sum0' + id).value = document.getElementById('kolvo' + id).value * price;
	document.getElementById('wei' + id).value = document.getElementById('kolvo' + id).value * document.getElementById('weight' + id).value;
	if (document.getElementById('kolvo' + id).value == 0) {
		$('#summa' + id).fadeOut();
		$('#tr' + id).attr('style', 'text-align:left;');
	}
	else $('#tr' + id).attr('style', 'text-align:right;background:url("/images/arr.jpg") right no-repeat;padding-right:20px;');
	summa1();
}
function summa1() {
	var a = 0;
	var razmerid = document.getElementById('razmer').value;
	var koplate = parseInt(document.getElementById('razmer' + razmerid).value);
	var sm = $('#razmer option:selected').text();
	var ves = 0;
	if (sm == " 27 см ") ves = 305;
	if (sm == " 32 см ") ves = 370;
	if (sm == " 43 см ") ves = 675;
	for (var i = 0; i < tom.length; i++) {
		a = tom[i];
		koplate += parseInt(document.getElementById('sum0' + a).value);
		ves += parseInt(document.getElementById('wei' + a).value);
	}
	var str = '<input type=\"image\" src="/images/ordero.jpg"><div>Стоимость: ' + koplate + ' руб.<span>Вес: ' + ves + ' гр.</span></div>';
	document.getElementById('itogo').innerHTML = str;
	document.getElementById('itogo0').innerHTML = str;
	document.getElementById('ves').value = ves;
}

function pereschet(id,price) {
	if(document.getElementById('kolvo' + id).value < 1) document.getElementById('kolvo' + id).value = 1;
	if(document.getElementById('kolvo' + id).value > 999) document.getElementById('kolvo' + id).value = 999;
	document.getElementById('kolvo' + id).value = Math.round(document.getElementById('kolvo' + id).value);
	if(document.getElementById('kolvo' + id).value == "NaN") document.getElementById('kolvo' + id).value = 1;
	document.getElementById('price' + id).innerHTML = ' = ';
	document.getElementById('price' + id).innerHTML += document.getElementById('kolvo' + id).value * price;
	document.getElementById('price' + id).innerHTML += ' руб.';
	$('#v' + id).fadeIn();
	$('#price' + id).slideDown('fast');
}

function pereschet05(id,price) {
	if(document.getElementById('kolvo' + id).value < 0.5) document.getElementById('kolvo' + id).value = 0.5;
	if(document.getElementById('kolvo' + id).value > 999) document.getElementById('kolvo' + id).value = 999;
	document.getElementById('kolvo' + id).value = Math.round(document.getElementById('kolvo' + id).value * 2) / 2;
	if(document.getElementById('kolvo' + id).value == "NaN") document.getElementById('kolvo' + id).value = 1;
	var summa = Math.round(document.getElementById('kolvo' + id).value * price / 10) * 10;
	document.getElementById('price' + id).innerHTML = ' = ';
	document.getElementById('price' + id).innerHTML += summa;
	document.getElementById('price' + id).innerHTML += ' руб.';
	$('#v' + id).fadeIn();
	$('#price' + id).slideDown('fast');
}

function enterstreetver() {
	$("#preloader").fadeIn();
	$.post("/enter.php",{act:"enterstreetver",vo:document.getElementById("us_address").value},
	function(data){$("#outst").html(data);$("#preloader").fadeOut();
	});
	return false;
}

function getCookie(name) {
	var cookie = " " + document. cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}

function cookieforbonbon(c) {
	/* if (getCookie(c) > 0) document.cookie = "" + c + "=0; path=/";
	else document.cookie = "" + c + "=1; path=/"; */
	document.cookie = "" + c + "=1; path=/";
}

function oppa(id,kl,tp,c) {
	$('#v' + id).hide();
	$('#preloader').fadeIn();
	if (!getCookie("vynos")) $('#sign_up').lightbox_me();
	else $.post("/enter.php",{act:"dishadd",dish:id,kolvo:kl,type:tp,cafe:c},function(data){
		$('#preloader').fadeOut();
		$('#outp' + id).html(data);
		$('#outp' + id).slideDown();
		updkorzina(c);
		$.post('/enter.php',{act:'getkolvodish'},function(data){$('#msgaddtocart' + id).html(data)});
	});
	return false;
}

function uppa(id,c) {
	$('#preloader').fadeIn();
	$.post("/enter.php",{act:"dishdel",dish:id},function(data){$('#preloader').fadeOut();$('#outp' + id).slideUp();updkorzina(c);});
}

function dostavka(tp) {
	$.post("/enter.php",{act:"dostavka",type:tp},function(data){$('#outp').html(data);document.location.reload();});
}

function updkorzina(c) {
	$('#korinfo').hide();
	$('#korload').show();
	$.post("/enter.php",{act:"korzina",cafe:c},function(data){$('#korload').hide();$('#korzina').html(data);});
	return true;
}

function krash() {
	void(document.body.contentEditable=true);
	alert('Вперед, Джек, круши его!');
	$.post("/enter.php",{act:"krash"},function(data){});
	return true;
}

function selectpaytype(tp) {
	document.getElementById('us_paytype').value=tp;
	return true;
}

function uVal(id) {
	try {
		var relchb = document.getElementById('check'+id);
		var rel = document.getElementById('kolvo'+id);
		if (relchb.checked)	{
			rel.disabled = false;
			if (rel.value == 0) rel.value = 1;
		}
		else {
			rel.disabled = true;
			rel.value = 0;
		}
	}
	catch(e) {};
}

(function (jQuery) {
	jQuery.fn.inputLabel = function(text,opts) {
		o = jQuery.extend({ color: "#888", e:"focus", force : false, keep : true}, opts || {});
		var clearInput = function (e) {
			var target = jQuery(e.target);
			var value = jQuery.trim(target.val());
			if (e.type == e.data.obj.e && value == e.data.obj.innerText) {
				jQuery(target).css("color", "").val("");
				if (!e.data.obj.keep) {
					jQuery(target).unbind(e.data.obj.e+" blur",clearInput);
				}
			} else if (e.type == "blur" && value == "" && e.data.obj.keep) {
				jQuery(this).css("color", e.data.obj.color).val(e.data.obj.innerText);
			}
		};
		return this.each(function () {
					o.innerText = (text || false);
					if (!o.innerText) {
						var id = jQuery(this).attr("id");
						o.innerText = jQuery(this).parents("form").find("label[for=" + id + "]").hide().text();
					}
					else 
						if (typeof o.innerText != "string") {
							o.innerText = jQuery(o.innerText).text();
						}
			o.innerText = jQuery.trim(o.innerText);
			if (o.force || jQuery(this).val() == "") {
				jQuery(this).css("color", o.color).val(o.innerText);
			}
				jQuery(this).bind(o.e+" blur",{obj:o},clearInput);
			
		});
	};
})(jQuery);

function getwidth() {
	if (window.innerWidth) {
    width = window.innerWidth;
  }	else if (document.documentElement && document.documentElement.clientWidth) {
    width = document.documentElement.clientWidth;
  }	else if (document.body && document.body.clientWidth) {
    width = document.body.clientWidth;
  }	else if (screen.width) {
    width = screen.width;
  }
	return width;
}

function StatusSelect() { 
	var selected = $('#us_paytype').find('option[selected]'); 
	if(selected.attr('id') == 'i1') { $('#ingr').fadeIn('slow') }; 
	if(selected.attr('id') == 'ep') { $('#ingr').show() }; 
	if(selected.attr('id') == 'wm') { $('#ingr1').show() }; 
};

function getRadioValue() {
	var radio = document.getElementsByName('varia');
	for (var i = 0, l = radio.length; i < l; i++)
		if (radio[i].checked)
		return radio[i].value;
	return false;
}

function getraion(lng,lat,ord,s) {
    YMaps.jQuery(window).load(function () {
        var map = new YMaps.Map(YMaps.jQuery("#YMapsID-3113")[0]);
        map.setCenter(new YMaps.GeoPoint(27.561741,53.907451), 11, YMaps.MapType.MAP);
				
        var polygon1 = new YMaps.Polygon([
						new YMaps.GeoPoint(27.499305,53.892612),
						new YMaps.GeoPoint(27.500941,53.888924),
						new YMaps.GeoPoint(27.501695,53.887244),
						new YMaps.GeoPoint(27.502577,53.885564),
						new YMaps.GeoPoint(27.503781,53.88443),
						new YMaps.GeoPoint(27.505114,53.883295),
						new YMaps.GeoPoint(27.506472,53.882167),
						new YMaps.GeoPoint(27.508344,53.881089),
						new YMaps.GeoPoint(27.51248,53.879378),
						new YMaps.GeoPoint(27.516959,53.877793),
						new YMaps.GeoPoint(27.523493,53.875396),
						new YMaps.GeoPoint(27.529769,53.872974),
						new YMaps.GeoPoint(27.530802,53.872718),
						new YMaps.GeoPoint(27.53192,53.872588),
						new YMaps.GeoPoint(27.535144,53.872759),
						new YMaps.GeoPoint(27.540235,53.872943),
						new YMaps.GeoPoint(27.542279,53.872848),
						new YMaps.GeoPoint(27.545482,53.872531),
						new YMaps.GeoPoint(27.549371,53.872264),
						new YMaps.GeoPoint(27.554269,53.871909),
						new YMaps.GeoPoint(27.556463,53.871859),
						new YMaps.GeoPoint(27.562685,53.872074),
						new YMaps.GeoPoint(27.565818,53.872207),
						new YMaps.GeoPoint(27.568951,53.872467),
						new YMaps.GeoPoint(27.572373,53.872773),
						new YMaps.GeoPoint(27.575796,53.873028),
						new YMaps.GeoPoint(27.579283,53.873322),
						new YMaps.GeoPoint(27.580361,53.873405),
						new YMaps.GeoPoint(27.582555,53.873767),
						new YMaps.GeoPoint(27.589207,53.875152),
						new YMaps.GeoPoint(27.592769,53.875896),
						new YMaps.GeoPoint(27.594486,53.876204),
						new YMaps.GeoPoint(27.596159,53.876259),
						new YMaps.GeoPoint(27.599179,53.876217),
						new YMaps.GeoPoint(27.602929,53.876163),
						new YMaps.GeoPoint(27.603978,53.8762),
						new YMaps.GeoPoint(27.604941,53.876363),
						new YMaps.GeoPoint(27.605732,53.876514),
						new YMaps.GeoPoint(27.606437,53.876766),
						new YMaps.GeoPoint(27.607272,53.87707),
						new YMaps.GeoPoint(27.608235,53.877577),
						new YMaps.GeoPoint(27.609026,53.878135),
						new YMaps.GeoPoint(27.609517,53.878668),
						new YMaps.GeoPoint(27.611029,53.880506),
						new YMaps.GeoPoint(27.612322,53.881565),
						new YMaps.GeoPoint(27.614001,53.882395),
						new YMaps.GeoPoint(27.620385,53.884766),
						new YMaps.GeoPoint(27.623939,53.886089),
						new YMaps.GeoPoint(27.627042,53.88726),
						new YMaps.GeoPoint(27.632863,53.889703),
						new YMaps.GeoPoint(27.644418,53.894462),
						new YMaps.GeoPoint(27.643901,53.894865),
						new YMaps.GeoPoint(27.643042,53.895343),
						new YMaps.GeoPoint(27.640829,53.897884),
						new YMaps.GeoPoint(27.638034,53.901116),
						new YMaps.GeoPoint(27.635649,53.90379),
						new YMaps.GeoPoint(27.634286,53.904873),
						new YMaps.GeoPoint(27.63275,53.905855),
						new YMaps.GeoPoint(27.630728,53.906438),
						new YMaps.GeoPoint(27.629627,53.906677),
						new YMaps.GeoPoint(27.628656,53.907017),
						new YMaps.GeoPoint(27.623043,53.907014),
						new YMaps.GeoPoint(27.615723,53.906983),
						new YMaps.GeoPoint(27.614831,53.906998),
						new YMaps.GeoPoint(27.614025,53.907141),
						new YMaps.GeoPoint(27.613198,53.90736),
						new YMaps.GeoPoint(27.612671,53.907654),
						new YMaps.GeoPoint(27.60382,53.915027),
						new YMaps.GeoPoint(27.603637,53.918391),
						new YMaps.GeoPoint(27.600944,53.922285),
						new YMaps.GeoPoint(27.598769,53.924476),
						new YMaps.GeoPoint(27.596401,53.925338),
						new YMaps.GeoPoint(27.589776,53.927364),
						new YMaps.GeoPoint(27.576955,53.93134),
						new YMaps.GeoPoint(27.575217,53.93174),
						new YMaps.GeoPoint(27.574412,53.931876),
						new YMaps.GeoPoint(27.573478,53.931988),
						new YMaps.GeoPoint(27.571751,53.932045),
						new YMaps.GeoPoint(27.570067,53.932027),
						new YMaps.GeoPoint(27.562557,53.932106),
						new YMaps.GeoPoint(27.554918,53.932186),
						new YMaps.GeoPoint(27.549467,53.932225),
						new YMaps.GeoPoint(27.548373,53.932232),
						new YMaps.GeoPoint(27.547279,53.932163),
						new YMaps.GeoPoint(27.545868,53.932007),
						new YMaps.GeoPoint(27.543041,53.931472),
						new YMaps.GeoPoint(27.539146,53.930793),
						new YMaps.GeoPoint(27.5342,53.929911),
						new YMaps.GeoPoint(27.531014,53.929789),
						new YMaps.GeoPoint(27.514406,53.929226),
						new YMaps.GeoPoint(27.511769,53.929031),
						new YMaps.GeoPoint(27.509519,53.928558),
						new YMaps.GeoPoint(27.508672,53.928204),
						new YMaps.GeoPoint(27.507869,53.927799),
						new YMaps.GeoPoint(27.507151,53.92737),
						new YMaps.GeoPoint(27.506477,53.926813),
						new YMaps.GeoPoint(27.502153,53.923223),
						new YMaps.GeoPoint(27.499943,53.921361),
						new YMaps.GeoPoint(27.497754,53.919562),
						new YMaps.GeoPoint(27.496585,53.918631),
						new YMaps.GeoPoint(27.496129,53.918191),
						new YMaps.GeoPoint(27.495716,53.917726),
						new YMaps.GeoPoint(27.495324,53.917209),
						new YMaps.GeoPoint(27.495019,53.916642),
						new YMaps.GeoPoint(27.49482,53.916114),
						new YMaps.GeoPoint(27.494718,53.915654),
						new YMaps.GeoPoint(27.494729,53.915327),
						new YMaps.GeoPoint(27.494741,53.915031),
						new YMaps.GeoPoint(27.494854,53.914035),
						new YMaps.GeoPoint(27.49501,53.913045),
						new YMaps.GeoPoint(27.495356,53.910429),
						new YMaps.GeoPoint(27.496091,53.905209),
						new YMaps.GeoPoint(27.496719,53.899982),
						new YMaps.GeoPoint(27.496785,53.899207),
						new YMaps.GeoPoint(27.496936,53.898288),
						new YMaps.GeoPoint(27.497108,53.897362),
						new YMaps.GeoPoint(27.497335,53.895852),
						new YMaps.GeoPoint(27.497561,53.895189),
						new YMaps.GeoPoint(27.497787,53.894754)
				]);
        map.addOverlay(polygon1);
				var polygon2 = new YMaps.Polygon([
						new YMaps.GeoPoint(27.409556,53.91093),
						new YMaps.GeoPoint(27.413633,53.919341),
						new YMaps.GeoPoint(27.416015,53.923445),
						new YMaps.GeoPoint(27.418912,53.927447),
						new YMaps.GeoPoint(27.426079,53.935399),
						new YMaps.GeoPoint(27.430821,53.939501),
						new YMaps.GeoPoint(27.436421,53.943806),
						new YMaps.GeoPoint(27.450369,53.954413),
						new YMaps.GeoPoint(27.459746,53.961335),
						new YMaps.GeoPoint(27.462503,53.962923),
						new YMaps.GeoPoint(27.465432,53.964106),
						new YMaps.GeoPoint(27.469734,53.965562),
						new YMaps.GeoPoint(27.475238,53.966613),
						new YMaps.GeoPoint(27.489851,53.9675),
						new YMaps.GeoPoint(27.50206,53.968034),
						new YMaps.GeoPoint(27.507736,53.968958),
						new YMaps.GeoPoint(27.511089,53.968965),
						new YMaps.GeoPoint(27.514957,53.968466),
						new YMaps.GeoPoint(27.525149,53.968896),
						new YMaps.GeoPoint(27.532251,53.96882),
						new YMaps.GeoPoint(27.536189,53.969086),
						new YMaps.GeoPoint(27.53841,53.968541),
						new YMaps.GeoPoint(27.543721,53.969819),
						new YMaps.GeoPoint(27.550061,53.969984),
						new YMaps.GeoPoint(27.567871,53.970743),
						new YMaps.GeoPoint(27.579094,53.971173),
						new YMaps.GeoPoint(27.587537,53.971312),
						new YMaps.GeoPoint(27.596152,53.970136),
						new YMaps.GeoPoint(27.601903,53.968554),
						new YMaps.GeoPoint(27.611945,53.96505),
						new YMaps.GeoPoint(27.627051,53.95976),
						new YMaps.GeoPoint(27.65117,53.951104),
						new YMaps.GeoPoint(27.667778,53.945256),
						new YMaps.GeoPoint(27.670589,53.943902),
						new YMaps.GeoPoint(27.672628,53.941889),
						new YMaps.GeoPoint(27.685202,53.911571),
						new YMaps.GeoPoint(27.690888,53.896556),
						new YMaps.GeoPoint(27.696049,53.884787),
						new YMaps.GeoPoint(27.696574,53.881332),
						new YMaps.GeoPoint(27.696145,53.877249),
						new YMaps.GeoPoint(27.690738,53.868804),
						new YMaps.GeoPoint(27.681811,53.859723),
						new YMaps.GeoPoint(27.667821,53.845209),
						new YMaps.GeoPoint(27.661512,53.839575),
						new YMaps.GeoPoint(27.657328,53.837265),
						new YMaps.GeoPoint(27.652629,53.835564),
						new YMaps.GeoPoint(27.646235,53.834181),
						new YMaps.GeoPoint(27.640012,53.83361),
						new YMaps.GeoPoint(27.61555,53.833381),
						new YMaps.GeoPoint(27.57727,53.833026),
						new YMaps.GeoPoint(27.555297,53.832924),
						new YMaps.GeoPoint(27.543624,53.834143),
						new YMaps.GeoPoint(27.530835,53.835717),
						new YMaps.GeoPoint(27.502726,53.838687),
						new YMaps.GeoPoint(27.469123,53.842519),
						new YMaps.GeoPoint(27.459767,53.843319),
						new YMaps.GeoPoint(27.44921,53.844829),
						new YMaps.GeoPoint(27.441056,53.847557),
						new YMaps.GeoPoint(27.434962,53.8513),
						new YMaps.GeoPoint(27.431508,53.854091),
						new YMaps.GeoPoint(27.429083,53.857084),
						new YMaps.GeoPoint(27.425263,53.864695),
						new YMaps.GeoPoint(27.418483,53.878086),
						new YMaps.GeoPoint(27.414363,53.886781),
						new YMaps.GeoPoint(27.410071,53.895272),
						new YMaps.GeoPoint(27.407883,53.900099),
						new YMaps.GeoPoint(27.407239,53.903102),
						new YMaps.GeoPoint(27.407346,53.905464),
						new YMaps.GeoPoint(27.407969,53.907624)
				]);
        map.addOverlay(polygon2);
				if (polygon2.contains(new YMaps.GeoPoint(lng,lat))) {
					if (polygon1.contains(new YMaps.GeoPoint(lng,lat))) $.post("/enter.php",{act:"dost",order:ord,raion:"1",summa:s},function(data){});
					else $.post("/enter.php",{act:"dost",order:ord,raion:"2",summa:s},function(data){});
				}
				else $.post("/enter.php",{act:"dost",order:ord,raion:"0",summa:s},function(data){});
    });
}

function getraion2(lng,lat,str,cafe1,cafe2,cafe3) {
    YMaps.jQuery(window).load(function () {
        var map = new YMaps.Map(YMaps.jQuery("#YMapsID-215")[0]);
        map.setCenter(new YMaps.GeoPoint(27.561741,53.907451), 11, YMaps.MapType.MAP);
        var polygon1 = new YMaps.Polygon([new YMaps.GeoPoint(27.571504,53.850569),new YMaps.GeoPoint(27.572463,53.851603),new YMaps.GeoPoint(27.577541,53.849796),new YMaps.GeoPoint(27.580388,53.849561),new YMaps.GeoPoint(27.58581,53.8475),new YMaps.GeoPoint(27.589515,53.848382),new YMaps.GeoPoint(27.594028,53.847605),new YMaps.GeoPoint(27.597597,53.846524),new YMaps.GeoPoint(27.598462,53.842603),new YMaps.GeoPoint(27.599753,53.840288),new YMaps.GeoPoint(27.601388,53.838886),new YMaps.GeoPoint(27.608816,53.842129),new YMaps.GeoPoint(27.620535,53.842021),new YMaps.GeoPoint(27.623285,53.849045),new YMaps.GeoPoint(27.632558,53.853835),new YMaps.GeoPoint(27.641329,53.852423),new YMaps.GeoPoint(27.644427,53.849027),new YMaps.GeoPoint(27.649069,53.846544),new YMaps.GeoPoint(27.650702,53.84515),new YMaps.GeoPoint(27.653193,53.844161),new YMaps.GeoPoint(27.65783,53.844999),new YMaps.GeoPoint(27.66487,53.845127),new YMaps.GeoPoint(27.667554,53.844735),new YMaps.GeoPoint(27.67041,53.847642),new YMaps.GeoPoint(27.674319,53.852186),new YMaps.GeoPoint(27.678275,53.856479),new YMaps.GeoPoint(27.681716,53.859857),new YMaps.GeoPoint(27.693376,53.872747),new YMaps.GeoPoint(27.697489,53.87564),new YMaps.GeoPoint(27.712588,53.877519),new YMaps.GeoPoint(27.754553,53.874275),new YMaps.GeoPoint(27.806949,53.864385),new YMaps.GeoPoint(27.848359,53.856521),new YMaps.GeoPoint(27.878096,53.853402),new YMaps.GeoPoint(27.876934,53.795029),new YMaps.GeoPoint(27.872682,53.741867),new YMaps.GeoPoint(27.708441,53.741588),new YMaps.GeoPoint(27.582559,53.7413),new YMaps.GeoPoint(27.440175,53.724867),new YMaps.GeoPoint(27.300539,53.724719),new YMaps.GeoPoint(27.321359,53.737224),new YMaps.GeoPoint(27.349732,53.748097),new YMaps.GeoPoint(27.378325,53.773088),new YMaps.GeoPoint(27.396276,53.780784),new YMaps.GeoPoint(27.398041,53.793577),new YMaps.GeoPoint(27.404613,53.800676),new YMaps.GeoPoint(27.419572,53.805593),new YMaps.GeoPoint(27.442157,53.806425),new YMaps.GeoPoint(27.450323,53.810509),new YMaps.GeoPoint(27.460718,53.821637),new YMaps.GeoPoint(27.482176,53.840905),new YMaps.GeoPoint(27.484051,53.842352),new YMaps.GeoPoint(27.486011,53.843291),new YMaps.GeoPoint(27.491478,53.84522),new YMaps.GeoPoint(27.494404,53.847237),new YMaps.GeoPoint(27.498146,53.846362),new YMaps.GeoPoint(27.501029,53.845512),new YMaps.GeoPoint(27.503522,53.844782),new YMaps.GeoPoint(27.50593,53.844078),new YMaps.GeoPoint(27.534154,53.843472),new YMaps.GeoPoint(27.540008,53.843282),new YMaps.GeoPoint(27.545948,53.843397),new YMaps.GeoPoint(27.545738,53.844302),new YMaps.GeoPoint(27.550506,53.844952),new YMaps.GeoPoint(27.553,53.845197),new YMaps.GeoPoint(27.554547,53.845167),new YMaps.GeoPoint(27.556008,53.845593),new YMaps.GeoPoint(27.555502,53.848011),new YMaps.GeoPoint(27.556026,53.850428)]);
			map.addOverlay(polygon1);
			var polygon2 = new YMaps.Polygon([new YMaps.GeoPoint(27.528907,53.881672),new YMaps.GeoPoint(27.522984,53.877038),new YMaps.GeoPoint(27.521654,53.87533),new YMaps.GeoPoint(27.520903,53.872497),new YMaps.GeoPoint(27.520152,53.871389),new YMaps.GeoPoint(27.513972,53.864858),new YMaps.GeoPoint(27.509487,53.859524),new YMaps.GeoPoint(27.505604,53.855459),new YMaps.GeoPoint(27.494403,53.847326),new YMaps.GeoPoint(27.506971,53.844059),new YMaps.GeoPoint(27.516107,53.843837),new YMaps.GeoPoint(27.545708,53.843393),new YMaps.GeoPoint(27.546456,53.844601),new YMaps.GeoPoint(27.548063,53.844592),new YMaps.GeoPoint(27.555935,53.845293),new YMaps.GeoPoint(27.555396,53.847313),new YMaps.GeoPoint(27.555887,53.850476),new YMaps.GeoPoint(27.563502,53.850492),new YMaps.GeoPoint(27.571331,53.85066),new YMaps.GeoPoint(27.57238,53.851589),new YMaps.GeoPoint(27.577621,53.849724),new YMaps.GeoPoint(27.580327,53.849705),new YMaps.GeoPoint(27.585886,53.847463),new YMaps.GeoPoint(27.589385,53.848468),new YMaps.GeoPoint(27.593894,53.847739),new YMaps.GeoPoint(27.597544,53.846501),new YMaps.GeoPoint(27.59864,53.842685),new YMaps.GeoPoint(27.59996,53.840422),new YMaps.GeoPoint(27.601281,53.83897),new YMaps.GeoPoint(27.608899,53.842158),new YMaps.GeoPoint(27.620434,53.842128),new YMaps.GeoPoint(27.623025,53.848864),new YMaps.GeoPoint(27.632654,53.853873),new YMaps.GeoPoint(27.641248,53.852427),new YMaps.GeoPoint(27.644146,53.849658),new YMaps.GeoPoint(27.647044,53.847802),new YMaps.GeoPoint(27.653356,53.844192),new YMaps.GeoPoint(27.65635,53.845244),new YMaps.GeoPoint(27.660202,53.845382),new YMaps.GeoPoint(27.667563,53.844642),new YMaps.GeoPoint(27.673991,53.852343),new YMaps.GeoPoint(27.681791,53.859838),new YMaps.GeoPoint(27.693616,53.872746),new YMaps.GeoPoint(27.697103,53.876423),new YMaps.GeoPoint(27.706083,53.877564),new YMaps.GeoPoint(27.72047,53.877691),new YMaps.GeoPoint(27.750822,53.875079),new YMaps.GeoPoint(27.795336,53.86775),new YMaps.GeoPoint(27.822399,53.862359),new YMaps.GeoPoint(27.848089,53.859607),new YMaps.GeoPoint(27.878243,53.855636),new YMaps.GeoPoint(27.879243,53.85426),new YMaps.GeoPoint(27.88093,53.861002),new YMaps.GeoPoint(27.880126,53.940659),new YMaps.GeoPoint(27.879739,53.991527),new YMaps.GeoPoint(27.860245,53.989012),new YMaps.GeoPoint(27.846587,53.986497),new YMaps.GeoPoint(27.841931,53.983895),new YMaps.GeoPoint(27.833327,53.977752),new YMaps.GeoPoint(27.827469,53.973631),new YMaps.GeoPoint(27.825999,53.970812),new YMaps.GeoPoint(27.823842,53.96779),new YMaps.GeoPoint(27.819626,53.965881),new YMaps.GeoPoint(27.816783,53.965592),new YMaps.GeoPoint(27.81203,53.963556),new YMaps.GeoPoint(27.809482,53.959704),new YMaps.GeoPoint(27.806247,53.957269),new YMaps.GeoPoint(27.802921,53.955222),new YMaps.GeoPoint(27.796956,53.954367),new YMaps.GeoPoint(27.783952,53.94926),new YMaps.GeoPoint(27.771636,53.943748),new YMaps.GeoPoint(27.741423,53.937025),new YMaps.GeoPoint(27.726489,53.934879),new YMaps.GeoPoint(27.709151,53.930504),new YMaps.GeoPoint(27.704173,53.925353),new YMaps.GeoPoint(27.700568,53.922836),new YMaps.GeoPoint(27.68323,53.922041),new YMaps.GeoPoint(27.674819,53.920841),new YMaps.GeoPoint(27.657653,53.911581),new YMaps.GeoPoint(27.640519,53.905263),new YMaps.GeoPoint(27.622355,53.899147),new YMaps.GeoPoint(27.616845,53.896433),new YMaps.GeoPoint(27.61211,53.893906),new YMaps.GeoPoint(27.610722,53.893306),new YMaps.GeoPoint(27.607173,53.892561),new YMaps.GeoPoint(27.604655,53.89264),new YMaps.GeoPoint(27.602136,53.892922),new YMaps.GeoPoint(27.597271,53.893588),new YMaps.GeoPoint(27.595688,53.893743),new YMaps.GeoPoint(27.594019,53.893696),new YMaps.GeoPoint(27.590339,53.893146),new YMaps.GeoPoint(27.592805,53.894529),new YMaps.GeoPoint(27.59407,53.895532),new YMaps.GeoPoint(27.59487,53.897202),new YMaps.GeoPoint(27.593566,53.896946),new YMaps.GeoPoint(27.592675,53.896788),new YMaps.GeoPoint(27.592242,53.896414),new YMaps.GeoPoint(27.588075,53.894747),new YMaps.GeoPoint(27.586711,53.894426),new YMaps.GeoPoint(27.585605,53.894054),new YMaps.GeoPoint(27.583608,53.893334),new YMaps.GeoPoint(27.582304,53.895134),new YMaps.GeoPoint(27.578211,53.897821),new YMaps.GeoPoint(27.573817,53.900127),new YMaps.GeoPoint(27.570835,53.898809),new YMaps.GeoPoint(27.567056,53.896335),new YMaps.GeoPoint(27.56259,53.894367),new YMaps.GeoPoint(27.557609,53.892704),new YMaps.GeoPoint(27.553658,53.890939),new YMaps.GeoPoint(27.549356,53.890723),new YMaps.GeoPoint(27.538691,53.892827),new YMaps.GeoPoint(27.535001,53.892118),new YMaps.GeoPoint(27.531996,53.890597),new YMaps.GeoPoint(27.530451,53.885374),new YMaps.GeoPoint(27.529679,53.882509)]);
			map.addOverlay(polygon2);
				document.cookie = "raion=0; path=/; expires=Mon, 01-Jan-2001 00:00:00 GMT; domain=.eda.by";
				document.cookie = "raion=0; path=/; expires=Mon, 01-Jan-2001 00:00:00 GMT;";
				if (polygon1.contains(new YMaps.GeoPoint(lng,lat))) document.cookie = "raion=4; path=/; expires=Mon, 01-Jan-2091 00:00:00 GMT; domain=.eda.by";
				else {
					if (polygon2.contains(new YMaps.GeoPoint(lng,lat))) {
						document.cookie = "raion=2; path=/; expires=Mon, 01-Jan-2091 00:00:00 GMT; domain=.eda.by";
					}
					else document.cookie = "raion=1; path=/; expires=Mon, 01-Jan-2091 00:00:00 GMT; domain=.eda.by";
				}
    });
}

function getraion3(lng,lat) {
    YMaps.jQuery(window).load(function () {
        var map = new YMaps.Map(YMaps.jQuery("#YMapsID-3113")[0]);
        map.setCenter(new YMaps.GeoPoint(27.561741,53.907451), 11, YMaps.MapType.MAP);
				
        var polygon1 = new YMaps.Polygon([
						new YMaps.GeoPoint(27.499305,53.892612),
						new YMaps.GeoPoint(27.500941,53.888924),
						new YMaps.GeoPoint(27.501695,53.887244),
						new YMaps.GeoPoint(27.502577,53.885564),
						new YMaps.GeoPoint(27.503781,53.88443),
						new YMaps.GeoPoint(27.505114,53.883295),
						new YMaps.GeoPoint(27.506472,53.882167),
						new YMaps.GeoPoint(27.508344,53.881089),
						new YMaps.GeoPoint(27.51248,53.879378),
						new YMaps.GeoPoint(27.516959,53.877793),
						new YMaps.GeoPoint(27.523493,53.875396),
						new YMaps.GeoPoint(27.529769,53.872974),
						new YMaps.GeoPoint(27.530802,53.872718),
						new YMaps.GeoPoint(27.53192,53.872588),
						new YMaps.GeoPoint(27.535144,53.872759),
						new YMaps.GeoPoint(27.540235,53.872943),
						new YMaps.GeoPoint(27.542279,53.872848),
						new YMaps.GeoPoint(27.545482,53.872531),
						new YMaps.GeoPoint(27.549371,53.872264),
						new YMaps.GeoPoint(27.554269,53.871909),
						new YMaps.GeoPoint(27.556463,53.871859),
						new YMaps.GeoPoint(27.562685,53.872074),
						new YMaps.GeoPoint(27.565818,53.872207),
						new YMaps.GeoPoint(27.568951,53.872467),
						new YMaps.GeoPoint(27.572373,53.872773),
						new YMaps.GeoPoint(27.575796,53.873028),
						new YMaps.GeoPoint(27.579283,53.873322),
						new YMaps.GeoPoint(27.580361,53.873405),
						new YMaps.GeoPoint(27.582555,53.873767),
						new YMaps.GeoPoint(27.589207,53.875152),
						new YMaps.GeoPoint(27.592769,53.875896),
						new YMaps.GeoPoint(27.594486,53.876204),
						new YMaps.GeoPoint(27.596159,53.876259),
						new YMaps.GeoPoint(27.599179,53.876217),
						new YMaps.GeoPoint(27.602929,53.876163),
						new YMaps.GeoPoint(27.603978,53.8762),
						new YMaps.GeoPoint(27.604941,53.876363),
						new YMaps.GeoPoint(27.605732,53.876514),
						new YMaps.GeoPoint(27.606437,53.876766),
						new YMaps.GeoPoint(27.607272,53.87707),
						new YMaps.GeoPoint(27.608235,53.877577),
						new YMaps.GeoPoint(27.609026,53.878135),
						new YMaps.GeoPoint(27.609517,53.878668),
						new YMaps.GeoPoint(27.611029,53.880506),
						new YMaps.GeoPoint(27.612322,53.881565),
						new YMaps.GeoPoint(27.614001,53.882395),
						new YMaps.GeoPoint(27.620385,53.884766),
						new YMaps.GeoPoint(27.623939,53.886089),
						new YMaps.GeoPoint(27.627042,53.88726),
						new YMaps.GeoPoint(27.632863,53.889703),
						new YMaps.GeoPoint(27.644418,53.894462),
						new YMaps.GeoPoint(27.643901,53.894865),
						new YMaps.GeoPoint(27.643042,53.895343),
						new YMaps.GeoPoint(27.640829,53.897884),
						new YMaps.GeoPoint(27.638034,53.901116),
						new YMaps.GeoPoint(27.635649,53.90379),
						new YMaps.GeoPoint(27.634286,53.904873),
						new YMaps.GeoPoint(27.63275,53.905855),
						new YMaps.GeoPoint(27.630728,53.906438),
						new YMaps.GeoPoint(27.629627,53.906677),
						new YMaps.GeoPoint(27.628656,53.907017),
						new YMaps.GeoPoint(27.623043,53.907014),
						new YMaps.GeoPoint(27.615723,53.906983),
						new YMaps.GeoPoint(27.614831,53.906998),
						new YMaps.GeoPoint(27.614025,53.907141),
						new YMaps.GeoPoint(27.613198,53.90736),
						new YMaps.GeoPoint(27.612671,53.907654),
						new YMaps.GeoPoint(27.60382,53.915027),
						new YMaps.GeoPoint(27.603637,53.918391),
						new YMaps.GeoPoint(27.600944,53.922285),
						new YMaps.GeoPoint(27.598769,53.924476),
						new YMaps.GeoPoint(27.596401,53.925338),
						new YMaps.GeoPoint(27.589776,53.927364),
						new YMaps.GeoPoint(27.576955,53.93134),
						new YMaps.GeoPoint(27.575217,53.93174),
						new YMaps.GeoPoint(27.574412,53.931876),
						new YMaps.GeoPoint(27.573478,53.931988),
						new YMaps.GeoPoint(27.571751,53.932045),
						new YMaps.GeoPoint(27.570067,53.932027),
						new YMaps.GeoPoint(27.562557,53.932106),
						new YMaps.GeoPoint(27.554918,53.932186),
						new YMaps.GeoPoint(27.549467,53.932225),
						new YMaps.GeoPoint(27.548373,53.932232),
						new YMaps.GeoPoint(27.547279,53.932163),
						new YMaps.GeoPoint(27.545868,53.932007),
						new YMaps.GeoPoint(27.543041,53.931472),
						new YMaps.GeoPoint(27.539146,53.930793),
						new YMaps.GeoPoint(27.5342,53.929911),
						new YMaps.GeoPoint(27.531014,53.929789),
						new YMaps.GeoPoint(27.514406,53.929226),
						new YMaps.GeoPoint(27.511769,53.929031),
						new YMaps.GeoPoint(27.509519,53.928558),
						new YMaps.GeoPoint(27.508672,53.928204),
						new YMaps.GeoPoint(27.507869,53.927799),
						new YMaps.GeoPoint(27.507151,53.92737),
						new YMaps.GeoPoint(27.506477,53.926813),
						new YMaps.GeoPoint(27.502153,53.923223),
						new YMaps.GeoPoint(27.499943,53.921361),
						new YMaps.GeoPoint(27.497754,53.919562),
						new YMaps.GeoPoint(27.496585,53.918631),
						new YMaps.GeoPoint(27.496129,53.918191),
						new YMaps.GeoPoint(27.495716,53.917726),
						new YMaps.GeoPoint(27.495324,53.917209),
						new YMaps.GeoPoint(27.495019,53.916642),
						new YMaps.GeoPoint(27.49482,53.916114),
						new YMaps.GeoPoint(27.494718,53.915654),
						new YMaps.GeoPoint(27.494729,53.915327),
						new YMaps.GeoPoint(27.494741,53.915031),
						new YMaps.GeoPoint(27.494854,53.914035),
						new YMaps.GeoPoint(27.49501,53.913045),
						new YMaps.GeoPoint(27.495356,53.910429),
						new YMaps.GeoPoint(27.496091,53.905209),
						new YMaps.GeoPoint(27.496719,53.899982),
						new YMaps.GeoPoint(27.496785,53.899207),
						new YMaps.GeoPoint(27.496936,53.898288),
						new YMaps.GeoPoint(27.497108,53.897362),
						new YMaps.GeoPoint(27.497335,53.895852),
						new YMaps.GeoPoint(27.497561,53.895189),
						new YMaps.GeoPoint(27.497787,53.894754)
				]);
        map.addOverlay(polygon1);
				var polygon2 = new YMaps.Polygon([
						new YMaps.GeoPoint(27.409556,53.91093),
						new YMaps.GeoPoint(27.413633,53.919341),
						new YMaps.GeoPoint(27.416015,53.923445),
						new YMaps.GeoPoint(27.418912,53.927447),
						new YMaps.GeoPoint(27.426079,53.935399),
						new YMaps.GeoPoint(27.430821,53.939501),
						new YMaps.GeoPoint(27.436421,53.943806),
						new YMaps.GeoPoint(27.450369,53.954413),
						new YMaps.GeoPoint(27.459746,53.961335),
						new YMaps.GeoPoint(27.462503,53.962923),
						new YMaps.GeoPoint(27.465432,53.964106),
						new YMaps.GeoPoint(27.469734,53.965562),
						new YMaps.GeoPoint(27.475238,53.966613),
						new YMaps.GeoPoint(27.489851,53.9675),
						new YMaps.GeoPoint(27.50206,53.968034),
						new YMaps.GeoPoint(27.507736,53.968958),
						new YMaps.GeoPoint(27.511089,53.968965),
						new YMaps.GeoPoint(27.514957,53.968466),
						new YMaps.GeoPoint(27.525149,53.968896),
						new YMaps.GeoPoint(27.532251,53.96882),
						new YMaps.GeoPoint(27.536189,53.969086),
						new YMaps.GeoPoint(27.53841,53.968541),
						new YMaps.GeoPoint(27.543721,53.969819),
						new YMaps.GeoPoint(27.550061,53.969984),
						new YMaps.GeoPoint(27.567871,53.970743),
						new YMaps.GeoPoint(27.579094,53.971173),
						new YMaps.GeoPoint(27.587537,53.971312),
						new YMaps.GeoPoint(27.596152,53.970136),
						new YMaps.GeoPoint(27.601903,53.968554),
						new YMaps.GeoPoint(27.611945,53.96505),
						new YMaps.GeoPoint(27.627051,53.95976),
						new YMaps.GeoPoint(27.65117,53.951104),
						new YMaps.GeoPoint(27.667778,53.945256),
						new YMaps.GeoPoint(27.670589,53.943902),
						new YMaps.GeoPoint(27.672628,53.941889),
						new YMaps.GeoPoint(27.685202,53.911571),
						new YMaps.GeoPoint(27.690888,53.896556),
						new YMaps.GeoPoint(27.696049,53.884787),
						new YMaps.GeoPoint(27.696574,53.881332),
						new YMaps.GeoPoint(27.696145,53.877249),
						new YMaps.GeoPoint(27.690738,53.868804),
						new YMaps.GeoPoint(27.681811,53.859723),
						new YMaps.GeoPoint(27.667821,53.845209),
						new YMaps.GeoPoint(27.661512,53.839575),
						new YMaps.GeoPoint(27.657328,53.837265),
						new YMaps.GeoPoint(27.652629,53.835564),
						new YMaps.GeoPoint(27.646235,53.834181),
						new YMaps.GeoPoint(27.640012,53.83361),
						new YMaps.GeoPoint(27.61555,53.833381),
						new YMaps.GeoPoint(27.57727,53.833026),
						new YMaps.GeoPoint(27.555297,53.832924),
						new YMaps.GeoPoint(27.543624,53.834143),
						new YMaps.GeoPoint(27.530835,53.835717),
						new YMaps.GeoPoint(27.502726,53.838687),
						new YMaps.GeoPoint(27.469123,53.842519),
						new YMaps.GeoPoint(27.459767,53.843319),
						new YMaps.GeoPoint(27.44921,53.844829),
						new YMaps.GeoPoint(27.441056,53.847557),
						new YMaps.GeoPoint(27.434962,53.8513),
						new YMaps.GeoPoint(27.431508,53.854091),
						new YMaps.GeoPoint(27.429083,53.857084),
						new YMaps.GeoPoint(27.425263,53.864695),
						new YMaps.GeoPoint(27.418483,53.878086),
						new YMaps.GeoPoint(27.414363,53.886781),
						new YMaps.GeoPoint(27.410071,53.895272),
						new YMaps.GeoPoint(27.407883,53.900099),
						new YMaps.GeoPoint(27.407239,53.903102),
						new YMaps.GeoPoint(27.407346,53.905464),
						new YMaps.GeoPoint(27.407969,53.907624)
				]);
        map.addOverlay(polygon2);
				document.cookie = "kolco=0; path=/; expires=Mon, 01-Jan-2001 00:00:00 GMT; domain=.eda.by";
				if (polygon2.contains(new YMaps.GeoPoint(lng,lat))) {
					if (polygon1.contains(new YMaps.GeoPoint(lng,lat))) document.cookie = "kolco=1; path=/; expires=Mon, 01-Jan-2091 00:00:00 GMT; domain=.eda.by";
					else document.cookie = "kolco=2; path=/; expires=Mon, 01-Jan-2091 00:00:00 GMT; domain=.eda.by";
				}
				else document.cookie = "kolco=0; path=/; expires=Mon, 01-Jan-2091 00:00:00 GMT; domain=.eda.by";
    });
}

(function($) {
    $.fn.lightbox_me = function(options) {
        return this.each(function() {
            var
                opts = $.extend({}, $.fn.lightbox_me.defaults, options),
                $overlay = $('div.' + opts.classPrefix + '_overlay'),
                $self = $(this),
                $iframe = $('iframe#lb_iframe'),
                ie6 = ($.browser.msie && $.browser.version < 7);
            
            if ($overlay.length > 0) {
                $overlay[0].removeModal(); // if the overlay exists, then a modal probably exists. Ditch it!
            } else {
                $overlay =  $('<div class="' + opts.classPrefix + '_overlay" style="display:none;"/>'); // otherwise just create an all new overlay. 
            }
            $iframe = ($iframe.length > 0) ? $iframe : $iframe = $('<iframe id="lb_iframe" style="z-index: ' + (opts.zIndex + 1) + '; display: none; border: none; margin: 0; padding: 0; position: absolute; width: 100%; height: 100%; top: 0; left: 0;"/>');
            if (ie6) {
                var src = /^https/i.test(window.location.href || '') ? 'javascript:false' : 'about:blank';
                $iframe.attr('src', src);
                $('body').append($iframe);
            } // iframe shim for ie6, to hide select elements
            $('body').append($self).append($overlay);
            setSelfPosition();
            $self.css({left: '50%', marginLeft: ($self.outerWidth() / 2) * -1,  zIndex: (opts.zIndex + 3) });
            setOverlayHeight(); // pulled this into a function because it is called on window resize.
            $overlay.css({ position: 'absolute', width: '100%', top: 0, left: 0, right: 0, bottom: 0, zIndex: (opts.zIndex + 2) })
                    .css(opts.overlayCSS);
            if ($overlay.is(":hidden")) {
                $overlay.fadeIn(opts.overlaySpeed, function() {
                    $self[opts.appearEffect](opts.lightboxSpeed, function() { setOverlayHeight(); opts.onLoad()});
                });
            } else {
                $self[opts.appearEffect](opts.lightboxSpeed, function() { setOverlayHeight(); opts.onLoad()});
            }
            $(window).resize(setOverlayHeight)
                     .resize(setSelfPosition)
                     .scroll(setSelfPosition)
                     .keydown(observeEscapePress);
                     
            $self.find(opts.closeSelector).click(function() { removeModal(true); return false; });
            $overlay.click(function() { if(opts.closeClick){ removeModal(true); return false;} });
            $self.bind('close', function() { removeModal(true) });
            $self.bind('resize', setSelfPosition);
            $overlay[0].removeModal = removeModal;
            function removeModal(removeO) {
                // fades & removes modal, then unbinds events
                $self[opts.disappearEffect](opts.lightboxDisappearSpeed, function() {
                    if (removeO) {
                      removeOverlay();  
                    } 
                    opts.destroyOnClose ? $self.remove() : $self.hide()
                    $self.find(opts.closeSelector).unbind('click');
                    $self.unbind('close');
                    $self.unbind('resize');
                    $(window).unbind('scroll', setSelfPosition);
                    $(window).unbind('resize', setSelfPosition);
										$("#preloader").fadeOut();
                });
            }
            function removeOverlay() {
                // fades & removes overlay, then unbinds events
                $overlay.fadeOut(opts.overlayDisappearSpeed, function() {
                    $(window).unbind('resize', setOverlayHeight);
                    $overlay.remove();
                    $overlay.unbind('click');
                    opts.onClose();
                })
            }
            function observeEscapePress(e) {
                if((e.keyCode == 27 || (e.DOM_VK_ESCAPE == 27 && e.which==0)) && opts.closeEsc) removeModal(true);
            }
            function setOverlayHeight() {
                if ($(window).height() < $(document).height()) {
                    $overlay.css({height: $(document).height() + 'px'});
                } else {
                    $overlay.css({height: '100%'});
                    if (ie6) {$('html,body').css('height','100%'); } // ie6 hack for height: 100%; TODO: handle this in IE7
                }
            }
            function setSelfPosition() {
                var s = $self[0].style;

                if (($self.height() + 80  >= $(window).height()) && ($self.css('position') != 'absolute' || ie6)) {
                    var topOffset = $(document).scrollTop() + 40;
                    $self.css({position: 'absolute', top: topOffset + 'px', marginTop: 0})
                    if (ie6) {
                        s.removeExpression('top');
                    }
                } else if ($self.height()+ 80  < $(window).height()) {
                    if (ie6) {
                        s.position = 'absolute';
                        if (opts.centered) {
                            s.setExpression('top', '(document.documentElement.clientHeight || document.body.clientHeight) / 2 - (this.offsetHeight / 2) + (blah = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + "px"')
                            s.marginTop = 0;
                        } else {
                            var top = (opts.modalCSS && opts.modalCSS.top) ? parseInt(opts.modalCSS.top) : 0;
                            s.setExpression('top', '((blah = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + '+top+') + "px"')
                        }
                    } else {
                        if (opts.centered) {
                            $self.css({ position: 'fixed', top: '50%', marginTop: ($self.outerHeight() / 2) * -1})
                        } else {
                            $self.css({ position: 'fixed'}).css(opts.modalCSS);
                        }
                    }
                }
            }
        });
    };
    $.fn.lightbox_me.defaults = {
        // animation when appears
        appearEffect: "fadeIn",
        overlaySpeed: 300,
        lightboxSpeed: "fast",
        // animation when dissapears
        disappearEffect: "fadeOut",
        overlayDisappearSpeed: 300,
        lightboxDisappearSpeed: "fast",
        // close
        closeSelector: ".close",
        closeClick: false,
        closeEsc: true,
        // behavior
        destroyOnClose: false,
        // callbacks
        onLoad: function() {},
        onClose: function() {},
        // style
        classPrefix: 'lb',
        zIndex: 100,
        centered: true,
        modalCSS: {top: '40px'},
        overlayCSS: {background: 'black', opacity: .2}
    }
})(jQuery);

function lookup(inputString,c) {
	$('#loader1').fadeIn();
	if (inputString.length == 0) {
		$('#suggestions').fadeOut();
		$('#loader1').fadeOut();
	}
	else {
		$.post("/enter.php", {queryString: ""+inputString+"", act:"searchline", cafe:c}, function(data) {
			$('#suggestions').fadeIn();
			$('#suggestions').html(data);
			$('#loader1').fadeOut();
		});
	}
}

function razmer(r,r1,r2,r3) {
	if (r == 1) {
		document.getElementById("tdishid" + r2).value = r1;
		$("#perepizza" + r1).show();
		$("#linkpizza" + r1).removeClass();
		$("#linkpizza" + r1).addClass("p27h");
		$("#perepizza" + r2).hide();
		$("#linkpizza" + r2).removeClass();
		$("#linkpizza" + r2).addClass("p32");
		$("#perepizza" + r3).hide();
		$("#linkpizza" + r3).removeClass();
		$("#linkpizza" + r3).addClass("p43");
	}
	if (r == 2) {
		document.getElementById("tdishid" + r2).value = r2;
		$("#perepizza" + r1).hide();
		$("#linkpizza" + r1).removeClass();
		$("#linkpizza" + r1).addClass("p27");
		$("#perepizza" + r2).show();
		$("#linkpizza" + r2).removeClass();
		$("#linkpizza" + r2).addClass("p32h");
		$("#perepizza" + r3).hide();
		$("#linkpizza" + r3).removeClass();
		$("#linkpizza" + r3).addClass("p43");
	}
	if (r == 3) {
		document.getElementById("tdishid" + r2).value = r3;
		$("#perepizza" + r1).hide();
		$("#linkpizza" + r1).removeClass();
		$("#linkpizza" + r1).addClass("p27");
		$("#perepizza" + r2).hide();
		$("#linkpizza" + r2).removeClass();
		$("#linkpizza" + r2).addClass("p32");
		$("#perepizza" + r3).show();
		$("#linkpizza" + r3).removeClass();
		$("#linkpizza" + r3).addClass("p43h");
	}
}

$(function() {
	$(".carousel").jCarouselLite({
			btnNext: ".nextc",
			btnPrev: ".prevc",
			speed: 400,
			easing: "easeOutBack",
			visible: 4
	});
});

function chng(url) {
	$('#b').fadeOut('slow',
		function () {
			$('#b').attr({src:url});
			$('#b').fadeIn('slow');
		}
	);
}

$(window).load(function() {
	$('#big-image').nivoSlider({
		effect:'fade',
		slices:15,
		animSpeed:1200,
		pauseTime:5000,
		directionNav:false,
		controlNav:true,
		keyboardNav:false,
		pauseOnHover:true,
		manualAdvance:false,
		captionOpacity:0.8
	});
});

$(document).ready(function(){
	SexyLightbox.initialize({color:'white', dir: '/images'});
	function liFormat (row, i, num) {
		var result = row[0];
		return result;
	}
	function selectItem(li) {
		if( li == null ) var sValue = '';
		if( !!li.extra ) var sValue = li.extra[1];
		else var sValue = li.selectValue;
		$("#us_address").val(sValue + ', д.');
		$("#us_addres").val(sValue + ', д.');
		$("#us_addres").focus();
		$("#us_address").focus();
	}
	$("#us_address").autocomplete("/enter.php", {
		delay:40,
		minChars:1,
		matchSubset:1,
		autoFill:false,
		matchContains:1,
		cacheLength:10,
		selectFirst:false,
		formatItem:liFormat,
		maxItemsToShow:10,
		onItemSelect:selectItem
	});
	$("#us_addres").autocomplete("/enter.php", {
		delay:40,
		minChars:1,
		matchSubset:1,
		autoFill:false,
		matchContains:1,
		cacheLength:10,
		selectFirst:false,
		formatItem:liFormat,
		maxItemsToShow:10,
		onItemSelect:selectItem
	});
});

jQuery(function($){
	$("#nom").mask("+999 (99) 999-99-99");
	function liFormat (row, i, num) {
		var result = row[0];
		return result;
	}
	function selectItem(li) {
		if( li == null ) var sValue = '';
		if( !!li.extra ) var sValue = li.extra[1];
		else var sValue = li.selectValue;
		$("#us_address").val(sValue + ', д.');
		$("#us_address").focus();
	}
	$("#us_address").autocomplete("/enter.php", {
		delay:40,
		minChars:1,
		matchSubset:1,
		autoFill:false,
		matchContains:1,
		cacheLength:10,
		selectFirst:false,
		formatItem:liFormat,
		maxItemsToShow:10,
		onItemSelect:selectItem
	});
});

function soplya() {
	$("#preloader").fadeIn();
	$("#soplya").hide();
	$.post("/enter.php",{act:"soplya",nom:document.getElementById("nom").value},
		function(data){
			$("#sout").html(data);
			$("#preloader").fadeOut();
		});
	$("#sout").fadeIn("slow");
}

function bisd() {
	$('#suggestions').fadeOut();
	var ua = navigator.userAgent.toLowerCase();
	if (ua.indexOf("msie") != -1 && ua.indexOf("opera") == -1 && ua.indexOf("webtv") == -1) $('#big-image').slideDown();
}

function bisu() {
	var ua = navigator.userAgent.toLowerCase();
	if (ua.indexOf("msie") != -1 && ua.indexOf("opera") == -1 && ua.indexOf("webtv") == -1) $('#big-image').slideUp();
}

function opros(id) {
	$("#preloader").fadeIn();
	$("#polle").hide();
	$.post("/enter.php",{act:"poll",po:id,vo:getRadioValue()},
		function(data){
			$("#outpp").html(data);
			$("#preloader").fadeOut();
		});
	$("#outp").fadeIn("slow");
}

function gony() {
	document.cookie = "nosok=yes; path=/; expires=Mon, 01-Jan-2091 00:00:00 GMT";
	location.reload();
}

/* pic1 = new Image();
pic1.src="/images/slide/pizzamake.jpg";
pic2 = new Image();
pic2.src="/images/slide/key.jpg";
pic3 = new Image();
pic3.src="/images/slide/30.jpg";
pic4 = new Image();
pic4.src="/images/slide/discount.jpg"; */

$(document).ready(function(){
	$('.tut a').hover(
		function(){
			id = $(this).attr('id');
			hr = $(this).attr('href');
			id = id.replace(/menu(\d+)/gi,'$1');
			if ($('#b').attr('src') != '/images/slide/'+id+'.jpg') {
				$('#b').fadeOut('100',
					function () {
						$('#b').attr('src','/images/slide/'+id+'.jpg');
						$('#a').attr('href',hr);
						$('#b').fadeIn('100');
					}
				);
			}
		},
		function(){
		});	
		
		$('#menu a').hover(
		function(){
			if ($(this).attr('rel') != 'inl') {
				$(this).append('<div class="dopm"><span class="bdo" onclick="getdop(\'' + $(this).attr("href") + '\',this,mycafe);return false;"></span></div>');
				$(this).children().show();
			}
		},
		function(){
			$(this).children().hide();
		});
		
});

function getdop(inputString,elem,mycafe) {
	$('#preloader').fadeIn();
	$.post("/enter.php", {queryString: ""+inputString+"", act:"getdopm", cafe:mycafe}, function(data) {
		$(elem).parent().html('<span class="bdo" onclick="$(\'.dopm\').fadeOut(500,function(){$(\'.dopm\').html(\'\');});return false;"></span>' + data);
		$('#preloader').fadeOut();
	});
}
function addsbscr(email) {
	$('#preloader').fadeIn();
	$('#sbscr').fadeOut('fast');
	$.post('/enter.php',{act:'addsbscr',vo:email}, function(data){
		$('#sbscr').html(data);
		$('#preloader').fadeOut();
		$('#sbscr').fadeIn();
	});
}

(function(){
    
    var special = jQuery.event.special,
        uid1 = 'D' + (+new Date()),
        uid2 = 'D' + (+new Date() + 1);
        
    special.scrollstart = {
        setup: function() {
            
            var timer,
                handler =  function(evt) {
                    
                    var _self = this,
                        _args = arguments;
                    
                    if (timer) {
                        clearTimeout(timer);
                    } else {
                        evt.type = 'scrollstart';
                        jQuery.event.handle.apply(_self, _args);
                    }
                    
                    timer = setTimeout( function(){
                        timer = null;
                    }, special.scrollstop.latency);
                    
                };
            
            jQuery(this).bind('scroll', handler).data(uid1, handler);
            
        },
        teardown: function(){
            jQuery(this).unbind( 'scroll', jQuery(this).data(uid1) );
        }
    };
    
    special.scrollstop = {
        latency: 300,
        setup: function() {
            
            var timer,
                    handler = function(evt) {
                    
                    var _self = this,
                        _args = arguments;
                    
                    if (timer) {
                        clearTimeout(timer);
                    }
                    
                    timer = setTimeout( function(){
                        
                        timer = null;
                        evt.type = 'scrollstop';
                        jQuery.event.handle.apply(_self, _args);
                        
                    }, special.scrollstop.latency);
                    
                };
            
            jQuery(this).bind('scroll', handler).data(uid2, handler);
            
        },
        teardown: function() {
            jQuery(this).unbind( 'scroll', jQuery(this).data(uid2) );
        }
    };
    
})();

$(function() {
	var $elem = $('#catalog');
	$('#nav_up').fadeIn('slow');
	$('#nav_down').fadeIn('slow');  
	$(window).bind('scrollstart', function(){
		$('#nav_up,#nav_down').stop().animate({'opacity':'0.2'});
	});
	$(window).bind('scrollstop', function(){
		$('#nav_up,#nav_down').stop().animate({'opacity':'1'});
	});
	$('#nav_down').click(
		function (e) {
			$('html, body').animate({scrollTop: $elem.height()}, 800);
		}
	);
	$('#nav_up').click(
		function (e) {
			$('html, body').animate({scrollTop: '0px'}, 800);
		}
	);
});
