$(window).load(function(){
	$("#shadow").click(function(){
		$(this).fadeOut("slow");
		$(".popupBox").fadeOut("fast");
		$(".popupBox1").fadeOut("fast");
		$(".callback").show();
		$(".callback1").show();
	});
	$(".tab").click(function(){
		$(".popupBox").fadeOut("fast");
		$(".popupBox1").fadeOut("fast");
		$(".callback").show();
		$("#shadow").fadeOut("slow");
		$(".callback1").show();
	});
	$(".callback").click(function(){
		$(".popupBox").fadeIn("normal");
		$(".slideBox").show();
		$(".callback").hide();
		$("#shadow").fadeIn("fast", function(){
			$(this).fadeTo("fast", 0.5);								 
		});						 
		$("#window").show();
		$h=$("#site").height()+$(".topPanel").height();
		if($h<1000)$h=800;
		$("#shadow").height($h+"px");
		$("#shadow").width($("#site").width());
		return false;
	});
	$(".callback1").click(function(){
		$(".popupBox1").fadeIn("normal");
		$(".slideBox").show();
		$(".callback1").hide();
		$("#shadow").fadeIn("fast", function(){
			$(this).fadeTo("fast", 0.5);								 
		});						 
		$("#window").fadeIn("normal");	
		$h=$("#site").height()+$(".topPanel").height();
		if($h<1000)$h=800;
		$("#shadow").height($h+"px");
		$("#shadow").width($("#site").width());						
		return false;
	});
});
$(document).ready(function(){
	$(".qandaList .faq").click( function() {
		if($(this).next().is(":hidden")){
			$(this).next().slideDown("slow");
		}else{
			$(this).next().slideUp("slow")	
		}
		return false;
	});
	$(".pcancel").click(function(){
		$("#shadow").click();
	});

	$("#za1").validate();
	$("#za2").validate();

	$(".forClear").each(function(){
		$(this).attr("val",$(this).val());
		$(this).focus(function(){
			if($(this).val()==$(this).attr("val"))
				$(this).val('');
		});
		$(this).blur(function(){
			if(!$(this).val())
				$(this).val($(this).attr("val"));
		});
	});

	$(".imgBox .img.bl").live("mouseover", function() {
		var nsrc=$(this).next().attr("src").substr(0,$(this).next().attr("src").length-5)+'1.jpg';
		$(this).next().attr("src",nsrc);
	});
	
	$(".imgBox .img.bl").live("mouseout", function() {
		var nsrc=$(this).next().attr("src").substr(0,$(this).next().attr("src").length-5)+'0.jpg';
		$(this).next().attr("src",nsrc);
	});
	
	
	if(location.hash){hch();}

	$(".aj").live("click", function() {
		$this=$(this);
		location.hash=$(this).attr("g");		
		return false;
	});

	$(".select").each(function(){
		$this=$(this);
		$select=$("select", this);
		html='<ul>';
		$("option", $select).each(function(){
			html+='<li id="'+$(this).attr("value")+'">'+$(this).text()+'</li>';							   
		});
		html+='</ul>';
		$select.after(html);
		if($("option:selected",$select).text())
		$("span", this).text($("option:selected",$select).text());
		else
		$("span", this).text($("option:first",$select).text()); 
		$this.click(function(){
			$("ul", this).slideToggle("fast");
		});
		$this.hover(
			function(){},
			function(){ $("ul", this).slideUp("fast"); },
			function(){ $("#main").slideUp("fast"); }
		);
		$("li", $this).hover(
			function(){ $(this).addClass("a")},
			function(){ $(this).removeClass("a")}
		);
		$("li", $this).click(function(){
			$select=$(this).parents(".select:first");
			val=$(this).attr("id");
			text=$(this).text();
			$("select",$select).val(val);
			$("select",$select).change();
			$("span",$select).text(text);
		});
	});

	if(document.getElementById("YMapsID")){
    YMaps.jQuery(window).load(function () {
        var map = new YMaps.Map(YMaps.jQuery("#YMapsID")[0]);
        map.setCenter(new YMaps.GeoPoint(37.562492,55.745596), 16, YMaps.MapType.MAP);
        map.addControl(new YMaps.Zoom());
        map.addControl(new YMaps.ToolBar());
        YMaps.MapType.PMAP.getName = function () { return ""; };
        map.addControl(new YMaps.TypeControl([
            YMaps.MapType.MAP,
            YMaps.MapType.SATELLITE,
            YMaps.MapType.HYBRID,
            YMaps.MapType.PMAP
        ], [0, 1, 2, 3]));

        YMaps.Styles.add("constructor#pmblmPlacemark", {
            iconStyle : {
                href : "http://api-maps.yandex.ru/i/0.3/placemarks/pmblm.png",
                size : new YMaps.Point(28,29),
                offset: new YMaps.Point(-8,-27)
            }
        });


        YMaps.Styles.add("constructor#006CFFc85Polyline", {
            lineStyle : {
                strokeColor : "006CFFc8",
                strokeWidth : 5
            }
        });
       map.addOverlay(createObject("Placemark", new YMaps.GeoPoint(37.557548,55.745955), "constructor#pmblmPlacemark", "The 60`s"));
       map.addOverlay(createObject("Polyline", [new YMaps.GeoPoint(37.567118,55.744192),new YMaps.GeoPoint(37.567933,55.744531),new YMaps.GeoPoint(37.568105,55.745051),new YMaps.GeoPoint(37.564951,55.745499),new YMaps.GeoPoint(37.558728,55.746165),new YMaps.GeoPoint(37.558084,55.746155),new YMaps.GeoPoint(37.557655,55.745986)], "constructor#006CFFc85Polyline", ""));
        
        function createObject (type, point, style, description) {
            var allowObjects = ["Placemark", "Polyline", "Polygon"],
                index = YMaps.jQuery.inArray( type, allowObjects),
                constructor = allowObjects[(index == -1) ? 0 : index];
                description = description || "";
            
            var object = new YMaps[constructor](point, {style: style, hasBalloon : !!description});
            object.description = description;
            
            return object;
        }
    });
	}	   
});

$(window).hashchange(function(){
	hch();
});

function hch(){
	if($('.textBox').length){
		if(location.hash){
			var h=location.hash;
			h=h.substr(1,h.length);
			var url='../../aj/'+h+'/';
		}
		else{
			var url='../../aj/'+$(".textBox").attr("n")+'/';
		}
		$.post(url, function(data){
			if(data){
				$('.textBox').html(data);
			}
		});		
	}
	
}
