$().ready(function(){
	window.setTimeout(function(){
//			$("input[type=checkbox]").removeAttr("checked");
			$(".b-img-now").click(function(){
				var _href = $(this).attr("href");
				$(".b-img-max").attr("src",_href);
				return false;
			});
			$(".b-metro-select").click(function(){
				var _metro = window.open('/sm.asp','new','width=650,height=690,toolbar=0')
				return false;
			});
			_maps();
			$(".b-direction").click(function(){
				var _num = $(this).attr("class");
				_num=_num.replace("b-direction b-direction-","");
				if ($(this).attr("checked"))
				{
					_flash.setPressed(_num, 1);
				}
				else{
					_flash.setPressed(_num, 0);
				}
			});

			$("[name='region']").click(function(){
				var _num = $(this).attr("class");
				_num=_num.replace("b-map-","");
				if ($(this).attr("checked"))
				{
					_flash.setPressed(_num, 1);
				}
				else{
					_flash.setPressed(_num, 0);
				}
			});
			$(".b-checked").bind("click",function(){
				var _id = $(this).attr("rel");
				var _text = $.cookie('items') || "";
				var _mesh = _text.split("-");
				
				if ($(this).attr("checked"))
				{	
					_mesh.push(_id);
					$(this).addClass("b-checked-yes");
					$(this).parents(".b-item").addClass("yea");
				}
				else{
					_mesh = $.grep(_mesh, function(value) {
						return value != _id;
					});
					$(this).addClass("b-checked-none");
					$(this).parents(".b-item").removeClass("yea");
				}
				_text = _mesh.join("-");
				$.cookie('items', _text, {expires: 365, path: '/'});
			});

			if ($(".b-main-img").size()>0)
			{
				swfobject.embedSWF("/img/header.swf", "b-main-img", "678", "323", "9.0.0");
			}
			$(".b-prepare").click(function(){
				if ($(this).text() == "Просмотреть выбранные")
				{
					$(this).html("Просмотреть все");
					$(".b-item").not(".yea").addClass("g-hidden");
				}
				else {
					$(this).html("Просмотреть выбранные");
					$(".b-item").removeClass("g-hidden");
				}
				
				return false;
			});

			//$(".b-checked:checked").removeAttr("checked");

	},300);
});
function receive(id,value)
{
	if ($(".b-map-"+id))
	{
		if (value)
		{
			$(".b-map-"+id).attr("checked","checked");
		}
		else{
			$(".b-map-"+id).removeAttr("checked");
		}
	}
}
function receive2(id,value)
{
	if ($(".b-direction-"+id))
	{
		if (value)
		{
			$(".b-direction-"+id).attr("checked","checked");
		}
		else{
			$(".b-direction-"+id).removeAttr("checked");
		}
	}
}
function FindMetro(s)
{
	$(".b-metro-list").val(s);
}
function _maps(){
	if ($(".b-map").size()>0)
	{
		swfobject.embedSWF("/img/map-flat-js.swf", "bmap", "401", "452", "9.0.0");
		_flash = getFlashMovieObject("bmap");
	}
	if ($(".b-map-cotteges").size()>0)
	{
		swfobject.embedSWF("/img/map-cottage-new-js.swf", "bmapcotteges", "500", "500", "9.0.0");
		_flash = getFlashMovieObject("bmapcotteges");
	}
}

function getFlashMovieObject(movieName)
{
  if (window.document[movieName]) 
  {
      return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(movieName);
  }
}
