function getBrowserInfo() {
 var t,v = undefined;
 if (window.opera) t = 'Opera';
 else if (document.all) {
  t = 'IE';
  var nv = navigator.appVersion;
  var s = nv.indexOf('MSIE')+5;
  v = nv.substring(s,s+1);
 }
 else if (navigator.appName) t = 'Netscape';
 return {type:t,version:v};
}
 
function addfavorite(a){
 var url = 'http://gidposaunam.ru';
 var title = "Гид по саунам. Все бани Cанкт-Петербурга и Ленинградской области";
 var b = getBrowserInfo();
 if (b.type == 'IE' && 7 > b.version && b.version >= 4) window.external.AddFavorite(url,title);
 else if (b.type == 'Opera') {
  a.href = url;
  a.rel = "sidebar";
  a.title = url+','+title;
  //return true;
 }
 else if (b.type == "Netscape") window.sidebar.addPanel(title,url,"");
 else alert("Нажмите CTRL-D, чтобы добавить страницу в закладки.");
 //return false;
}

function selrayonmetro(obj){
	var sel=document.getElementById(obj);
	var metro=document.getElementById('metro');
	var rayon=document.getElementById('rayon');
	if(sel.disabled==true){
		metro.disabled=true;
		rayon.disabled=true;
		sel.disabled=false;
	}
}

function ajaxer(){
	$('a[href^="/"]').click(function(){$("#content").ajaxload($(this).attr("href"));return false;});
	$("form").submit(function(){$("#content").ajaxload($(this).attr('action'),$(this).serialize());return false;});
}

function map(adr,name) {
	//$("#YMapsID").toggle("slow");
	
		var geoResult;
		var map = new YMaps.Map(document.getElementById("YMapsID"));
		map.enableScrollZoom();
		
		var s = new YMaps.Style();
		s.iconStyle = new YMaps.IconStyle("example#customPointIcon");
		s.iconStyle.offset = new YMaps.Point(0, -60);
		s.iconStyle.href = "http://gidposaunam.ru/design_images/ikonkakarta.png";
		s.iconStyle.size = new YMaps.Point(41, 56);
		//s.iconStyle.shadow = new YMaps.IconShadowStyle();
		//s.iconStyle.shadow.offset = new YMaps.Point(0, -25);
		//s.iconStyle.shadow.href = "http://info.maps.yandex.net/api/i/dot_shadow.png";
		//s.iconStyle.shadow.size = new YMaps.Point(25, 23);
		YMaps.Styles.add("example#customPoint", s);
		
		var t = new YMaps.Template();
		t.text = "<div><img alt=\""+name+"\" style=\"height:$[style.iconStyle.size.y];width:$[style.iconStyle.size.x];\" src=\"$[style.iconStyle.href]\"\/><div class=\"CustomPointName\">$[name|0]</div></div>";
		YMaps.Templates.add("example#customPointIcon", t);
		
		map.addControl(new YMaps.SmallZoom(), new YMaps.ControlPosition(YMaps.ControlPosition.TOP_LEFT));
		var geocoder = new YMaps.Geocoder(adr, {results: 1, boundedBy: map.getBounds()});
		YMaps.Events.observe(geocoder, geocoder.Events.Load, function () {
			if (this.length()) {
				geoResult = this.get(0);
				//map.addOverlay(geoResult);
				map.setBounds(geoResult.getBounds());
				var placemark = new YMaps.Placemark(geoResult.getGeoPoint(), {hasBalloon: false, style: "example#customPoint"});
				 placemark.name ="";
				//placemark.getBalloon().setOptions({hasCloseButton: false, mapAutoPan: 0});
				map.addOverlay(placemark);  
			}
		});
}

function close_button(){
	var poz=$('#popup').position();
	$('#popup').width()-$('#close_button').width()
	$('#close_button').css("top",poz.top+2).css("left",poz.left+($('#popup').width()-$('#close_button').width())+3);
}

$(document).ready(function(){
						   
	$("a[href*=http://maps.yandex.ru/agreement.xml]").parent().html('');						
	$('#fullscreen').height($(document).height());
	$(".tdover").hover(
		function(){$(this).animate( { backgroundColor: "#FEFBEB"}, 700);},
		function(){$(this).animate( { backgroundColor: "#FCF3CA"}, 300);}
	);
	$(".tdover").click(
		function(){window.location=$(this).find("a").attr("href")}					   
	);
	$("input[type='checkbox']").custCheckBox();
	//ajaxer();
});

jQuery.fn.center =function(relative) {
			var rel=(relative==null)?$(window):relative;
			return this.each(function(){
				var $self = jQuery(this);
				$self.css("position","absolute");
				$self.css("top", (rel.height() - $self.height())/2 + 'px');
				$self.css("left",(rel.width() - $self.width())/2 + 'px');
			});
		};

jQuery.fn.ajaxload=function(url,data){
	var getpost=(data==null)?"GET":"POST";
	return this.each(function(){
		var $obj = jQuery(this);
		$.ajax({
			type: getpost,
			url: "/content"+url,
			data: data,
			async: false,
			cache: false,
			success: function(html){$obj.html(html);}
		});
	})
}

function popup(state,file,data) {
	switch (state){
		case "load":
			$('#fullscreen').css({display:"block"}).fadeTo("slow",0.7);
			$("#ajax-loader").center().show();
			$("#popup").ajaxload(file,data).center().show();	
			close_button();
			$('#close_button').show();
			$("#ajax-loader").hide();				
			break;
					
		case "reload":
			$("#popup").hide();
			$('#close_button').hide();
			$("#ajax-loader").center().show();
			$("#popup").ajaxload(file,data).center().show();
			close_button();
			$('#close_button').show();
			$("#ajax-loader").hide();		
			break;
					
		case "unload":
			$("#popup").hide();
			$('#close_button').hide();
			$('#fullscreen').css({display:"block"}).fadeTo("slow",0,function (){$('#fullscreen').css({display:"none"})});
			break;
	}

}

$(document).ready(function(){
  
})
