(function($){
	$(document).ready(function(){
		var
			
			$submit = $('#popup .button-holder .error'),
			$frmfos = $('#frmfos select'),
			$selectteam = $('.box select')
		;
		
		
		if($selectteam.length > 0){
			$($selectteam).click(function(){
				var idotdel = $($selectteam).val();				
				//alert (cena_jq);
				
				if (idotdel == 00){
					$('.our_team').show();
				}
				else{
					$('.our_team').hide();
					$('#block_'+idotdel).show();
				}
				
			});
		};
		
		
		
		
		
		
		
		if($frmfos.length > 0){
			$($frmfos).click(function(){
				var cena_jq = $('#cena_jq').val();
				var cena_jq2 = $('#cena_jq2').val();
				var cena_jq3 = $('#cena_jq3').val();
				//alert (cena_jq);
				
				if (cena_jq == 01){
					$('#summa').html('от 40000 руб');
				}
				else{
					$('#summa').html('');
				}
				if (cena_jq2 == 02){
					$('#summa').html('от 70000 руб');
				}
				if (cena_jq3 == 01){
					$('#summa').html('от 70000 руб');
				}
				if (cena_jq3 == 02){
					$('#summa').html('по договоренности');
				}
				
				if (cena_jq2 == 00){					
					$('#p02').hide();
					
				}
				if (cena_jq2 == 01){
					$('#p02').show();
				}
				if (cena_jq2 == 02){
					$('#p02').hide();
				}
				if (cena_jq == 02){
					$('#p01').show();
				}
				else{
					$('#p01').hide();
					$('#p02').hide();
					$('#cena_jq2').val(00);					
				}
			});
		};
		
		if($submit.length > 0){	
			
			$($submit).click(function(){
				var pid = $('#popup  #pid').val();
				var fio = $('#popup  #name').val();
				var email = $('#popup  #mail').val();
				var text = $('#popup  #text').val();
				
				var tip = $('#popup  #tip').val();
				var god = $('#popup  #god').val();
				
				var got = $('#got2:checked').val();
				var obr = $('#obr2:checked').val();
				
				
				if (!fio){
				$("#popup label[for='name'] span").html('*<br />Не заполнено');
				var ifio = 0;
				}
				else {
					var ifio = 1;
					$("#popup label[for='name'] span").html('*');
				}
				
				if (!email){
				$("#popup label[for='mail'] span").html('*<br />Не заполнено');
				var iemail = 0;
				}
				else {
					var iemail = 1;
					$("#popup label[for='mail'] span").html('*');
				}
				
				if (!text){
				$("#popup label[for='text'] span").html('*<br />Не заполнено');
				var itele = 0;
				}
				else {
					if (text.length > 250){
					var itele = 0;
					$("#popup label[for='text'] span").html('*<br />Не более 100 символов');
					}
					else{
					var itele = 1;
					$("#popup label[for='text'] span").html('*');
					}
				}
				if ((itele == 1) & (iemail == 1) & (ifio == 1)){
					$.post("/sendemail.php", { pid: pid, fio: fio, email: email, text: text, got: got, obr: obr, tip: tip, god: god});
					//alert (pid+'-'+fio+'-'+email+'-'+text+'-'+got+'-'+obr);
					//alert ('Сейчас отправим');
					$('#popup .top-wrap h3').html('Запрос получен');
					$('#popup .order-form').html('');
					var itele = 0;
					var iemail = 0;
					var ifio = 0;
					window.location.reload();	
				}
			
			});
			
			
		};
	
	});
})(jQuery);

/*@cc_on
if (@_jscript_version==5.6 || (@_jscript_version==5.7 && navigator.userAgent.toLowerCase().indexOf("msie 6.") != -1)){
	document.execCommand('BackgroundImageCache', false, true);
}
@*/
$(function(){
	
	var params = {
		changedEl: ".lineForm select",
		visRows: 5,
		scrollArrows: true
	}
	cuSel(params);
	$("#jqueryOnchange").change(
	function()

	{
		var pid = $(this).val();
		$.cookie("city_id",pid,{expires: 7, path: '/', domain: 'center25.ru'});
		$.cookie("city_id",pid,{expires: 7, path: '/', domain: '.center25.ru'});
		window.location.reload();
		/*$.post("/index.php", { pid: pid, action: "city"}, function(data){
			if (data){
			window.location.reload();
			}
		});	*/	
		return;

	});	
	$("#map4").gMap({ 
				controls: false,
				scroll: false,
				scrollwheel: false,
				markers: [{ latitude: 55.057726,
                              longitude: 82.914193,                              
                              popup: false }],
				latitude: 55.047726,
                longitude: 82.928193,
                zoom: 12 });
				
	$("#map3").gMap({ 
				controls: false,
				scroll: false,
				scrollwheel: false,
				markers: [{ latitude: 55.769802,
                              longitude: 37.644950,
                             popup: false },
							
							{ latitude: 55.783949,
                              longitude: 37.702116,    
                              popup: false },
							 { latitude: 55.762523,
                              longitude: 37.553907,                             
                              popup: false } 
							  ],
				latitude: 55.749264,
                longitude: 37.66534,
                zoom: 9 });
	});

$(function(){
	$(document).ready(function(){
		$('.link-popup').simplebox();		
				
	});
});

(function($) {
	$.fn.simplebox = function(options) { 
		return new Simplebox(this, options); 
	};
	
	function Simplebox(context, options) { this.init(context, options); };
	
	
				
	
	Simplebox.prototype = {
		options:{},
		init: function (context, options){
			this.options = $.extend({
				duration: 300,
				linkClose: 'a.close, a.btn-close',
				divFader: 'fader',
				faderColor: 'black',
				opacity: 0.7,
				wrapper: '#wrapper',
				linkPopap: '.link-submit'
			}, options || {});
			this.btn = $(context);
			this.select = $(this.options.wrapper).find('select');
			this.initFader();
			this.btnEvent(this, this.btn);
		},
		btnEvent: function($this, el){
			el.click(function(){
				if ($(this).attr('href')) $this.toPrepare(this.href.substr(this.href.indexOf("#")));
				else $this.toPrepare($(this).attr('title'));
				return false;
			});
		},
		calcWinWidth: function(){
			this.winWidth = $('body').width();
			if ($(this.options.wrapper).width() > this.winWidth) this.winWidth = $(this.options.wrapper).width();
		},
		toPrepare: function(obj){
			this.popup = $(obj);
			this.btnClose = this.popup.find(this.options.linkClose);
			this.submitBtn = this.popup.find(this.options.linkPopap);
			
			if ($.browser.msie) this.select.css({visibility: 'hidden'});
			this.calcWinWidth();
			this.winHeight = $(window).height();
			this.winScroll = $(window).scrollTop();
			
			this.popupTop = this.winScroll + (this.winHeight/2) - this.popup.outerHeight(true)/2;
			if (this.popupTop < 0) this.popupTop = 0;
			this.faderHeight = $(this.options.wrapper).outerHeight();
			if ($(window).height() > this.faderHeight) this.faderHeight = $(window).height();
			
			this.popup.css({
				top: this.popupTop,
				left: this.winWidth/2 - this.popup.outerWidth(true)/2
			}).hide();
			this.fader.css({
				width: this.winWidth,
				height: this.faderHeight
			});
			this.initAnimate(this);
			this.initCloseEvent(this, this.btnClose, true);
			this.initCloseEvent(this, this.submitBtn, false);
			this.initCloseEvent(this, this.fader, true);
		},
		initCloseEvent: function($this, el, flag){
			el.click(function(){
				$this.popup.fadeOut($this.options.duration, function(){
					$this.popup.css({left: '-9999px'}).show();
					if ($.browser.msie) $this.select.css({visibility: 'visible'});
					$this.submitBtn.unbind('click');
					$this.fader.unbind('click');
					$this.btnClose.unbind('click');
					$(window).unbind('resize');
					if (flag) $this.fader.fadeOut($this.options.duration);
					else {
						if ($this.submitBtn.attr('href')) $this.toPrepare($this.submitBtn.attr('href'));
						else $this.toPrepare($this.submitBtn.attr('title'));
					}
				});
				return false;
			});
		},
		initAnimate:function ($this){
			$this.fader.fadeIn($this.options.duration, function(){
				$this.popup.fadeIn($this.options.duration);
			});
			$(window).resize(function(){
				$this.calcWinWidth();
				$this.popup.animate({
					left: $this.winWidth/2 - $this.popup.outerWidth(true)/2
				}, {queue:false, duration: $this.options.duration});
				$this.fader.css({width: $this.winWidth});
			});
		},
		initFader: function(){
			if ($(this.options.divFader).length > 0) this.fader = $(this.options.divFader);
			else{
				this.fader = $('<div class="'+this.options.divFader+'"></div>');
				$('body').append(this.fader);
				this.fader.css({
					position: 'absolute',
					zIndex: 1001,
					left:0,
					top:0,
					background: this.options.faderColor,
					opacity: this.options.opacity
				}).hide();
			}
		}
	}
}(jQuery));
