﻿$(document).ready(function() {



	scroll2 = $("IMG", ".scroll");
	if (scroll2.length>0) {
		all_scroll = 0;
		for (i=0;i<scroll2.length;i++) {
			all_scroll += $(scroll2[i]).width();
		}
		$(".scroll DIV").css("width", all_scroll+50+"px");
	}

	$(".scroll IMG").click(function() {
		$(".big_photo SPAN").html("<img src='"+$("#"+this.id).attr("name")+"'/>");

		if ($.browser.msie && $.browser.version == 6) {
		} else {
			$(".big_photo").css("left", "50%");
			$(".big_photo").css("margin-left", "-"+($(".big_photo").width()/2));

			if (document.documentElement.clientHeight>$(".big_photo").height()) {
				$(".big_photo").css("top", "50%");
				$(".big_photo").css("margin-top", "-"+($(".big_photo").height()/2));
			} else {
				$(".big_photo").css("top", "10px");
			}
		}

		$(".big_photo").show();
	});

	$("#div_say2").click(function() {
		$('#samokat').animate({opacity:0}, 500);
		$('#div_say2').hide();
	});
	
	$("#div_say").click(function() {
		/*$('#samokat').animate({opacity:0}, 500);*/
		
		$('#div_say').hide();
		
		auto_img = $(".samokat_and_motik").find("img");
		img = new Array();
		for (i=0;i<auto_img.length;i++) {
			img[i] = $(auto_img[i]).attr("id");
		}
		$(".samokat_and_motik").css("margin-top", "-19px");
		setTimeout('$("#'+img[0]+'").show(); mor(1, "'+img+'")', 100);
	});
	
	var this_card = '';
	$(".card DIV").mouseover(function() {
		margin = parseInt($("#"+this.id).css("margin-left"));
		if (margin > 0) {
			$("#"+this.id).css("margin-left", margin+80+"px");
		}
		margin2 = parseInt($("#"+this_card).css("margin-left"));
		if (this_card!='' && margin2 > 0) {
			$("#"+this_card).css("margin-left", margin2-80+"px");
		}
		$(".cards").hide();
		$("#"+this.id+"_text").show();
	});

	$(".card DIV").mouseout(function() {
		this_card = this.id;
	});

	$(".sel UL LI").click(function() {
		if ($("#"+this.id).attr("class") != 'first') {

			$(".sel UL LI.first DIV SPAN").text($("#"+this.id).text()).attr("class", this.id);
			$(".div_phones").hide();
			$("#"+this.id+"_text").show();
			$(".sel UL LI").css("display", "none");
			eraseCookie('sel_city');
		//	eraseCookie('sel_city_name');
			var city_id = this.id.substr(1);
			//alert(city_id);
			createCookie('sel_city', city_id, 365);


		}
	})

	$(".sel UL LI.first").click(function() {
		$('.sel UL LI').show();
		$('#'+$('.sel UL LI.first DIV SPAN').attr('class')).hide();
	});


	$(".sel UL LI").mouseover(function() {
		if ($("#"+this.id).attr("class") != 'first') {
			$("#"+this.id).attr("class", "activ");
		}
	});

	$(".sel UL LI").mouseout(function() {
		if ($("#"+this.id).attr("class") != 'first') {
			$("#"+this.id).attr("class", "");
		}
	});


	$(".div_logo, .div_top, .div_cc, .m4008, .menu_min").mouseover(function() {
		$(".sel UL LI").css("display", "none");
	});

	$(".invest-center, .invest-left").mouseover(function() {
		$('.select_reit UL').css('margin-bottom', '15px')
		$(".select_reit UL LI").css("display", "none");
	});

	$(".select_reit UL LI").mouseover(function() {
		if ($("#"+this.id).attr("class")!="first") {
			$("#"+this.id).attr("class", "activ");
		}
	});

	$(".select_reit UL LI").mouseout(function() {
		if ($("#"+this.id).attr("class")!="first") {
			$("#"+this.id).attr("class", "");
		}
	});

	$(".select_reit UL LI.first").click(function() {
		$('.select_reit UL LI').show();
		$('.select_reit UL').css('margin-bottom', '-'+($('.select_reit UL').height()-29)+'px');
		$('#'+$('#'+this.id+" SPAN").attr("class")).hide();
	});

	$(".select_reit UL LI").click(function() {
		if ($("#"+this.id).attr("class")!="first") {
			$(".select_reit UL LI.first SPAN").text($("#"+this.id).text());
			$('.select_reit UL').css('margin-bottom', '15px')
			$(".select_reit UL LI").css("display", "none");
			$(".select_reit UL LI.first SPAN").attr("class", this.id);
			$(".invest-right TABLE").hide();
			$("#"+this.id+"_text").show();
		}
	});





	//alert(tid);
	$("#title_1").click(function() {	$("#text_1").toggle();});
	$("#title_2").click(function() {	$("#text_2").toggle();});
	$("#title_3").click(function() {	$("#text_3").toggle();});
	$("#title_4").click(function() {	$("#text_4").toggle();});
	$("#title_5").click(function() {	$("#text_5").toggle();});
	$("#title_6").click(function() {	$("#text_6").toggle();});
	$("#title_7").click(function() {	$("#text_7").toggle();});
	$("#title_8").click(function() {	$("#text_8").toggle();});
	$("#title_9").click(function() {	$("#text_9").toggle();});
	$("#title_10").click(function() {	$("#text_10").toggle();});



});

$(window).resize(function() {

});

function mor(id, img_array) {
	img_array = img_array.split(",");
	if (img_array[id]!=undefined && img_array[id]!='') {
		setTimeout('$("#'+img_array[(id-1)]+'").hide(); $("#'+img_array[id]+'").show(); mor('+(id+1)+', "'+img_array+'")', 100);
	}
}

function change_tr(id) {
	tr = $("TR", "."+id);
	if (tr.length > 0) {
		for (i=1;i<tr.length;i++) {
			if (i%2==0) {
				$(tr[i]).attr("class", "tdgrey");
			} else {
				$(tr[i]).attr("class", "");
			}
		}
	}
}

/*function display_map(id) {
	if ($('#td_'+id).css("display") == 'none') {
		$('#td_'+id).show();
		$('#tr_'+id+' .onmap').hide();
		$('#tr_'+id+' .nomap').show();
	} else {
		$('#td_'+id).hide();
		$('#tr_'+id+' .onmap').show();
		$('#tr_'+id+' .nomap').hide();
	}
}*/


function initialize(id,latitude,longitude) {
						 if (GBrowserIsCompatible()) {
							 var map = new GMap2(document.getElementById("map_container"+id));
 							 map.addControl(new GSmallMapControl()); // масштаб и перемещение карты
							 map.addControl(new GMapTypeControl()); // переключение типов карты
							 //map.checkResize();
							 map.setCenter(new GLatLng(latitude,longitude), 13);

							var point = new GLatLng(latitude,longitude);
 							var marker = new GMarker(point);
 							map.addOverlay(marker);


 						}
 						}







function display_map(id, latitude,longitude, map_id) {

	if ($('#td_'+id).css("display") == 'none') {
		$('#td_'+id).show();
		if ($('#tr_'+id).attr("class") == "noimg") {
			old_class = "noimg";
			$('#tr_'+id).attr("class", "noimg tr_activ");
		} else {
			$('#tr_'+id).attr("class", "tr_activ");
		}


		$('#tr_'+id+' .onmap').hide();
		$('#tr_'+id+' .nomap').show();
		initialize(map_id,latitude,longitude);

	} else {
		$('#td_'+id).hide();
		if ($('#tr_'+id).attr("class") == "noimg tr_activ") {
			$('#tr_'+id).attr("class", "noimg");
		} else {
			$('#tr_'+id).attr("class", "");
		}

		$('#tr_'+id+' .onmap').show();
		$('#tr_'+id+' .nomap').hide();
	}
}



function dis_main_map() {
	if ($("#map_main_1").css("display") == "block") {
		$("#hide_map").hide();
		$("#show_map").show();
		$("#map_main_1").hide();
	} else {
		$("#hide_map").show();
		$("#show_map").hide();
		$("#map_main_1").show();
	}
}


var c_pos=0;
function c_prev(id, id2) {
	if (c_pos==0) {
		c_set(get_total_photo(id), 1000, id, id2);
	} else {
		c_set(--c_pos,1000,id,id2);
	}
}

function c_next(id, id2) {
	if (c_pos==get_total_photo(id)) {
		c_pos = 0;
		c_set(0, 1000, id, id2);
	} else {
		c_set(++c_pos, 1000, id, id2);
	}
}

function c_set(pos, delay, id, id2) {
	c_pos = pos;
	$('#'+id).animate({marginLeft:-pos*200}, delay );
}

function get_total_photo(id) {
	return $("DIV DIV", $(".main_prod")).length-1;
}

function change_auto_key(type) {
	if (type == 'key') {
		if ($("#key_2").css("display")=='none') {
			$("#key_2").show();
			$("#auto_1").show();
		}
	} else if (type == 'auto') {
		if ($("#auto_1").css("display") != "none") {
			$("#auto_1").hide();
			$("#key_2").hide();
		}
	}
}

function change_text(id, text) {
	if ($("#"+id).val() == text) {
		$("#"+id).attr("value", "");
	} else if ($("#"+id).val() == ''){
		$("#"+id).attr("value", text);
	}
}

function createCookie(name,value,days) {
	//alert('create');
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	//alert('erase');
	createCookie(name,"",-1);
}



function ch_flag_added_enable() {
	if ($("#flag_added_enable").attr("checked") != true) {
		$("#from_added_day").attr("disabled", 1);
		$("#from_added_month").attr("disabled", 1);
		$("#from_added_year").attr("disabled", 1);

		$("#to_added_day").attr("disabled", 1);
		$("#to_added_month").attr("disabled", 1);
		$("#to_added_year").attr("disabled", 1);
	} else {
		$("#from_added_day").attr("disabled", 0);
		$("#from_added_month").attr("disabled", 0);
		$("#from_added_year").attr("disabled", 0);

		$("#to_added_day").attr("disabled", 0);
		$("#to_added_month").attr("disabled", 0);
		$("#to_added_year").attr("disabled", 0);
	}
}
function ch_flag_torg_enable() {
	if ($("#flag_torg_enable").attr("checked") != true) {
		$("#from_torg_day").attr("disabled", 1);
		$("#from_torg_month").attr("disabled", 1);
		$("#from_torg_year").attr("disabled", 1);

		$("#to_torg_day").attr("disabled", 1);
		$("#to_torg_month").attr("disabled", 1);
		$("#to_torg_year").attr("disabled", 1);
	} else {
		$("#from_torg_day").attr("disabled", 0);
		$("#from_torg_month").attr("disabled", 0);
		$("#from_torg_year").attr("disabled", 0);

		$("#to_torg_day").attr("disabled", 0);
		$("#to_torg_month").attr("disabled", 0);
		$("#to_torg_year").attr("disabled", 0);
	}
}

//Анектирование на главной

var flag = false;
var shift_x;
var shift_y;

var lastZ = 1000;

indicator_image = new Image();
indicator_image.src = "/_img/indicator.gif";

function start_drag(itemToMove,e){
	if(!e) e = window.event;
	flag = true;

	lastZ += 1;
	itemToMove.style.zIndex = lastZ;

	shift_x = e.clientX-parseInt(itemToMove.style.left);
	shift_y = e.clientY-parseInt(itemToMove.style.top);

	if(e.stopPropagation) e.stopPropagation();
	else e.cancelBubble = true;
	if(e.preventDefault) e.preventDefault();
	else e.returnValue = false;
}

function end_drag() {
	flag = false;
}

function dragIt(itemToMove,e) {
	if(!flag) return;
	if(!e) e = window.event;
	itemToMove.style.left = (e.clientX-shift_x) + "px";
	itemToMove.style.top = (e.clientY-shift_y) + "px";

	if(e.stopPropagation) e.stopPropagation();
	else e.cancelBubble = true;
	if(e.preventDefault) e.preventDefault();
	else e.returnValue = false;
}

function show_spec_anket_window() {
	$("#spec_anket").css("visibility", "visible");
	$("#question_1").css("display", "block");

	$("#question_2").css("display", "none");
	$("#question_3").css("display", "none");
	$("#question_4").css("display", "none");
	$("#question_5").css("display", "none");
	$("#question_6").css("display", "none");
}

function hide_spec_anket_window() {
	$("#spec_anket").css("visibility", "hidden");
}
function spec_anket_next(item_question) {
	$("#question_"+item_question).css("display", "none");
	$("#question_"+(item_question+1)).css("display", "block");
	if (item_question == 5) {
		save_anket();
	}
}

function spec_anket_previous(item_question) {
	$("#question_"+item_question).css("display", "none");
	$("#question_"+(item_question-1)).css("display", "block");
}

function spec_anket_other(enable) {
	if (enable) {
		$("#question_other").css("display", "block");
	} else {
		$("#question_other").css("display", "none");
	}
}

var res_param = "";
function save_anket() {
	res_param = "";

	$("div#spec_anket input[type = 'checkbox']").each(
		function() {
			if ($(this).attr("checked")) {
				val = 1;
			} else {
				val = 0;
			}
			res_param += "&"+$(this).attr("name")+"="+val;
		}
	);
	$("div#spec_anket input[type = 'radio']").each(
		function() {
			if ($(this).attr("checked")) {
				res_param += "&"+$(this).attr("name")+"="+$(this).attr("value");
			}
		}
	)
	res_param += "&question5="+$("div#spec_anket textarea[name = 'question5']").val();
	res_param += "&question_other="+$("div#spec_anket input[name = 'question_other']").val();

	$.post("/ajax_sent_ankets.php", res_param);
}




function get_branches(page_id) {
	if (!page_id) return;

	location.hash = "page_id="+page_id;

	res_param = "&page_id="+page_id;
	$("#brach_title").text("");
	$("#brach_description").html("<img src=\"/_img/indicator.gif\"/> Пожалуйста, подождите...");
	$.post("/ajax_get_branches.php", res_param, function(xml) {
		var title = $("title", xml).text();
		var description = $("description", xml).text();
		$("#brach_title").text(title);
		$("#brach_description").html(description);
	});
}
if (location.hash.substring(1,8) == "page_id") {
	get_branches(location.hash.substring(9, location.hash.length));
}



