isIE = $.browser.msie;
delay = 3000;
tID = null;
//прелоад картинок
img1 = new Image();
img1.src = "i/point-ro.png";
img2 = new Image();
img2.src = "i/point-lo.png";
img3 = new Image();
img3.src = "i/point-po.png";
j = 1;
for (i=4;i<9;i++) {
	eval("img"+i+" = new Image()");
	eval("img"+i+".src = 'i/newmap/map_"+(j++)+".png'");
}
function r_over(parentID) {
    $("#"+parentID+" div.l").css("background-color","#d74302"); 
    $("#"+parentID+" div.r img").attr("src","i/point-ro.png");
    $("#"+parentID+" div.l img").attr("src","i/point-po.png");
    if (isIE) $("#"+parentID+"Info").removeClass("hidden");
    else $("#"+parentID+"Info").stop().fadeTo(0,1).fadeIn("fast");
    if (isIE) $("#"+parentID+"Img").removeClass("hidden");
    else $("#"+parentID+"Img").stop().fadeTo(0,1).fadeIn("fast"); 
}
function r_out(parentID) {
    $("#"+parentID+" div.l").css("background-color","#86320d"); 
    $("#"+parentID+" div.r img").attr("src","i/point-r.png");
    $("#"+parentID+" div.l img").attr("src","i/point-p.png");
    if (isIE) $("#"+parentID+"Info").addClass("hidden");
    else $("#"+parentID+"Info").fadeOut("fast");
    if (isIE) $("#"+parentID+"Img").addClass("hidden");
    else $("#"+parentID+"Img").fadeOut("fast");
}
function l_over(parentID) {
    $("#"+parentID+" div.r").css("background-color","#d74302"); 
    $("#"+parentID+" div.l img").attr("src","i/point-lo.png");
    $("#"+parentID+" div.r img").attr("src","i/point-po.png");
    if (isIE) $("#"+parentID+"Info").removeClass("hidden");
    else $("#"+parentID+"Info").stop().fadeTo(0,1).fadeIn("fast");
    if (isIE) $("#"+parentID+"Img").removeClass("hidden");
    else $("#"+parentID+"Img").stop().fadeTo(0,1).fadeIn("fast"); 
}
function l_out(parentID) {
    $("#"+parentID+" div.r").css("background-color","#86320d"); 
    $("#"+parentID+" div.l img").attr("src","i/point-l.png");
    $("#"+parentID+" div.r img").attr("src","i/point-p.png");
    if (isIE) $("#"+parentID+"Info").addClass("hidden");
    else $("#"+parentID+"Info").fadeOut("fast");
    if (isIE) $("#"+parentID+"Img").addClass("hidden");
    else $("#"+parentID+"Img").fadeOut("fast");
}
//действия сразу после загрузки страницы
$(function() {
	// выровнять участки
	alignPoints();
	$(window).resize(alignPoints);
	// подсветка участков при наведении и открытие окна при клике
	$("div.point-r").each(function() {
		$("#"+this.id+" div").hover( 
		    function () {
		    	clearTimeout(tID);
		    	$("div.point-r div,div.point-l div").not(this).trigger("customout");
		    	id = $(this).parent().attr("id");
		    	r_over(id);
		    },  
		    function () {
		    	id = $(this).parent().attr("id");
		    	r_out(id);
		    	tID = setTimeout("showPoint(1)",delay);
		    }
		).bind("customout",function(){
	    	id = $(this).parent().attr("id");
	    	r_out(id);
		}).click(openBlock);
	});	 
	$("div.point-l").each(function() {
		$("#"+this.id+" div").hover( 
		    function () {
		    	clearTimeout(tID);
		    	$("div.point-r div,div.point-l div").not(this).trigger("customout");
		    	id = $(this).parent().attr("id");
		    	l_over(id);
		    },  
		    function () {
		    	id = $(this).parent().attr("id");
		    	l_out(id);
		    	tID = setTimeout("showPoint(1)",delay);
		    } 
		).bind("customout",function(){
	    	id = $(this).parent().attr("id");
	    	l_out(id);
		}).click(openBlock);
	});
	// разворачивание в левой колонке		 
	$("#feedback a").click(function() {
			el = $(this).parent().next("div");
			if (el.css("display")=="none") {
				el.show("fast");
			} else {	
				el.hide("fast");
			}
			return false;
	});		
	// отправка формы
	$("#feedbacktable form").submit(function() {
		if ($("#formName").val()=="") {
			alert("Не заполнено обязательное поле \"Имя\"");
			return false;
		}	
		if ($("#formEmail").val()=="") {
			alert("Не заполнено обязательное поле \"Электронная почта\"");
			return false;
		}	
		$("#feedbacktable").load("form.php",{
			name: $("#formName").val(),
			email: $("#formEmail").val(),
			city: $("#formCity").val(),
			phone: $("#formPhone").val(),
			company: $("#formCompany").val(),
			message: $("#formMessage").val()
		});
		return false;
	});
	tID = setTimeout("showPoint(1)",delay);
});
// функция открытия окна при клике
function openBlock() {
	return false;
}
// функция выравнивания участков
function alignPoints() {
	offset = $("#map img").offset();
	$("#point1").css("left",offset.left+41)
	.css("top",offset.top+342);
	$("#point2").css("left",offset.left+500)
	.css("top",offset.top+90);
	$("#point3").css("left",offset.left+415)
	.css("top",offset.top+205);
	$("#point4").css("left",offset.left+81)
	.css("top",offset.top+113);
	$("#point5").css("left",offset.left+290)
	.css("top",offset.top+350);
	$(".info").css("left",offset.left+507)
	.css("top",offset.top+310);
	$(".infoContainer").fadeTo(0,0.9);
	$("#point1Img").css("left",offset.left+146)
	.css("top",offset.top+264);
	$("#point2Img").css("left",offset.left+289)
	.css("top",offset.top+40);
	$("#point3Img").css("left",offset.left+94)
	.css("top",offset.top+155);
	$("#point4Img").css("left",offset.left+143)
	.css("top",offset.top+141);
	$("#point5Img").css("left",offset.left+289)
	.css("top",offset.top+165);
}
function showPoint(id) {
	el = $("#point"+id);
	if (el.attr("class")=="point-r") {
		r_over("point"+id);
	} else {
		l_over("point"+id);
	}	
	tID = setTimeout("hidePoint("+id+")",delay*0.4);
}
function hidePoint(id) {
	el = $("#point"+id);
	if (el.attr("class")=="point-r") {
		r_out("point"+id);
	} else {
		l_out("point"+id);
	}	
	tID = setTimeout("showPoint("+(id==5?1:(id+1))+")",delay);
}