// size
if(document.documentElement.clientHeight < 770 || document.documentElement.clientWidth < 700)
	size = 'small';
else
	size = 'medium';
	
var oaFields = {
	adv_comp: {re: 'def'},
	adv_cont: {re: 'def'},
	adv_adv: {re: 'def'},
	adv_bob: {re: 'def'}
};
var obFields = {
	banner_comp: {re: 'def'},
	banner_cont: {re: 'def'},
	banner_adv: {re: 'def'},
	banner_bob: {re: 'def'}
};
var abFields = {	
	contact: {re: 'def'},
	phone: {re: 'def'},
	address: {re: 'def'}
};

var contFields = {
	name: {re: 'def', notice: 'Укажите свое Имя'},
	mail: {re: 'def', notice: 'Укажите email'},
	question: {re: 'def', notice: 'Задайте вопрос'}
};

function noticeFunc(notice, color) {
	for(var i in this.check) {		
		if(this.na.hasOwnProperty(i)) {
			$('#caption_'+i).css({color: 'red'});		
			if(this.check[i].hasOwnProperty('notice'))
				$('#notice_'+i).html(this.check[i].notice).slideDown();	
		}
		else { 
			$('#caption_'+i).css({color: color});
			if(this.check[i].hasOwnProperty('notice'))
				$('#notice_'+i).slideUp();
		}
	}	
}

function advBanner(callback, context) {
	var date = new Date();
	var year = date.getFullYear();
	var month = date.getMonth();
	var time = date.getDate();
	var new_date = new Date(year+1, month, time);
	var cookie_count = document.cookie.match(/count=(\d+)/);
	if(cookie_count && cookie_count[1]) {
		cookie_count[1] = parseInt(cookie_count[1]);
		if(cookie_count[1] > 0) {					
			new_count = cookie_count[1] + 1;		
			if(new_count >= 10) {			
				callback.call(context);
				document.cookie = 'count=0; path=/; expires='+new_date.toUTCString();
			}
			else
				document.cookie = 'count='+new_count+'; path=/; expires='+new_date.toUTCString();
		}
	}
	else {
		
		document.cookie = 'count=1; path=/; expires='+new_date.toUTCString();
	}
}

var oa, ob;

var biga_arr_lat = [66, 73, 71, 65];
var biga_arr_ru = [188, 66, 85, 70];
var biga_num = 0;
var price_arr_lat = [80, 82, 73, 67, 69];
var price_arr_ru = [71, 72, 70, 81, 67];
var price_num = 0;
var adv_arr_lat = [65, 68, 86];
var adv_num = 0;
document.onkeyup = function(event) {
	if (window.event) event = window.event;
	var key = event.keyCode ? event.keyCode : event.which ? event.which : null;		
	if(key == biga_arr_lat[biga_num] || key == biga_arr_ru[biga_num] || key == price_arr_lat[price_num] || key ==  price_arr_ru[price_num] || key == adv_arr_lat[adv_num]) {
		if(key == biga_arr_lat[biga_num] || key == biga_arr_ru[biga_num]) {
			if(biga_num == 3) {				
				if(key == biga_arr_lat[biga_num]) {}
					//alert('biga');
				else {}
					//alert('бига');
				biga_num = 0;
			}
			else
				biga_num++				
		}
		else if(key == price_arr_lat[price_num] || key == price_arr_ru[price_num]) {			
			if(price_num == 4) {				
				window.location.href = 'http://biga.ru/portfolio/price';
				price_num = 0;
			}
			else
				price_num++
		}
		else if(key == adv_arr_lat[adv_num]) {
			
			if(adv_num == 2) {				
				ab.show();
				adv_num = 0;
			}
			else
				adv_num++
		}
	}	
	else
		price_num = biga_num = adv_num = 0;
	
	
}

function oaClass() {		
		this.framed = false;
		this.init = function() {			
			var self = this;
			this.framed = new Framed(1);
			this.form = new Form(document.forms.order_adv);
			this.photo = false;
			this.photo_b = false;
			this.photo_input = false;
			this.send = false;
			this.send_b = false;
			this.send_input = false;
			this.reload_button = false;
			this.upload = false;
			// получаем контент
			var inner = $('.oa');
			inner[0].style.display = 'block';
			// получаем размер
			this.framed.size.call(this.framed, inner[0]);
			// вставляем контент
			this.framed.box_inner.appendChild(inner[0]);
			// определяем элементы
			this.photo = $(this.framed.box_inner).find('.photo');
			this.photo_b = this.photo.find('b');
			this.photo_input = this.photo.find('input');
			this.send = $(this.framed.box_inner).find('.send');
			this.send_b = this.send.find('b');
			this.send_input = this.send.find('input');
			this.reload_button = $(this.framed.box_inner).find('.reload');			
			// upload								
			this.upload = new AjaxUpload(this.photo[0], {
				action: 'index.php', 
				name: 'image_adv',
				onSubmit : function(file, ext) {
					this.disable();					
					self.photo.find('.bg').animate({paddingLeft: '20px'}, 100, function() {
						self.photo.find('.bg').css({background: 'url(templates/site/images/button_min_loader.gif) no-repeat 0 50%'});
					});
					return true;
				},
				onComplete: function(file, response) {					
					self.photo.find('.bg').stop().css({background: 'none'});
					self.photo.find('.bg').stop().animate({paddingLeft: '0px'}, 100);											
					self.disablePhoto.call(self);
				},
				data: {ajax: '1', order_adv: '1'}
			});			
		}
		this.reloadEvent = function () {			
			var oa_button = $('.order_adv');
			if(oa_button.length > 0) {
				var self = this;				
				oa_button.click(function() {					
					self.show.call(self);
					return false;
				});
			}
		}
		
		this.show = function() {
			var self = this;
			// показываем слой
			overlay.show({opacity: '0.5', filter: 'progid:DXImageTransform.Microsoft.Alpha(opacity=50)'});
			// показываем блок
			this.framed.show();
			// центрируем
			this.framed.setCenter(this.framed.box_inner_size.width, this.framed.box_inner_size.height);
			// анимируем		
			$(this.framed.box_inner).stop().animate({width: self.framed.box_inner_size.width + 'px', height: self.framed.box_inner_size.height + 'px'}, 100, function() {
				$(self.framed.box_inner).animate({opacity: 1, filter: 'alpha(opacity=100)'}, 100);
			});		
			// обработка закрытия		
			overlay.box.onclick = function() {
				self.framed.hide.call(self.framed);
				overlay.hide();
				return false;
			}
			
			$(self.framed.box_inner).find('.close').click(function() {
				self.framed.hide.call(self.framed);
				overlay.hide();
				return false;
			});
			
			// обработка отправки			
			this.eventSend(1);
			// обработка reload
			this.reload_button.click(function() {
				self.enableSend.call(self);
				self.enablePhoto.call(self);
				return false;
			});
		}
			
		this.eventSend = function(on) {
			if(on) {
				var self = this;
				this.send[0].onclick = function() {
					if(self.form.t.call(self.form, oaFields, noticeFunc, '#5c5c5c')) {
						var data = $(document.forms.order_adv).serialize();						
						data += '&ajax=1&site=1';
						$.ajax({url: 'index.php', type: 'POST', data: data, dataType: 'html', success: function(r) {
							if(/send/.test(r)) {
								self.disableSend();
							}
						}});
					}
					return false;
				}
			}
			else {
				this.send[0].onclick = function() {					
					return false;
				}
			}
		}
		
		this.disableSend = function() {
			this.send.find('*').css({cursor: 'default'});
			this.send.find('.l').css({background: 'url(templates/site/images/b1l_d.gif) no-repeat 0 0'});
			this.send.find('.c').css({background: 'url(templates/site/images/b1c_d.gif) repeat-x 0 0'});
			this.send.find('.r').css({background: 'url(templates/site/images/b1r_d.gif) no-repeat 0 0'});
			this.send_b.text('Заказ принят');
			this.send_input.attr('value', 'Заказ принят');
			this.reload_button.css({display: 'block'});			
			this.eventSend(0);
		}
		
		this.enableSend = function() {
			this.send.find('*').css({cursor: 'pointer'});
			this.send.find('.l').css({background: 'url(templates/site/images/b1l.gif) no-repeat 0 0'});
			this.send.find('.c').css({background: 'url(templates/site/images/b1c.gif) repeat-x 0 0'});
			this.send.find('.r').css({background: 'url(templates/site/images/b1r.gif) no-repeat 0 0'});
			this.send_b.text('Нажмите, чтобы заказать баннер');
			this.send_input.attr('value', 'Нажмите, чтобы заказать баннер');
			this.reload_button.css({display: 'none'});			
			this.eventSend(1);			
		}
		
		this.disablePhoto = function() {
			this.photo.find('*').css({cursor: 'default'});
			this.photo.find('.l').css({background: 'url(templates/site/images/b1l_d.gif) no-repeat 0 0'});
			this.photo.find('.c').css({background: 'url(templates/site/images/b1c_d.gif) repeat-x 0 0'});
			this.photo.find('.r').css({background: 'url(templates/site/images/b1r_d.gif) no-repeat 0 0'});
			this.photo_b.text('Загружено');
			this.photo_input.attr('value', 'Загружено');
		}
		
		this.enablePhoto = function() {
			this.photo.find('.l').css({background: 'url(templates/site/images/b1l.gif) no-repeat 0 0'});
			this.photo.find('.c').css({background: 'url(templates/site/images/b1c.gif) repeat-x 0 0'});
			this.photo.find('.r').css({background: 'url(templates/site/images/b1r.gif) no-repeat 0 0'});
			this.photo_b.text('Загрузить');
			this.photo_input.attr('value', 'Загрузить');
			this.upload.enable();
		}
			
		
	}


function obClass() {
	var self = this;
	this.framed = false;
	this.init = function() {			
		var self = this;
		this.framed = new Framed(1);
		this.form = new Form(document.forms.order_banner);
		this.photo = false;
		this.photo_b = false;
		this.photo_input = false;
		this.send = false;
		this.send_b = false;
		this.send_input = false;
		this.reload_button = false;
		this.upload = false;
		// получаем контент
		var inner = $('.ob');
		inner[0].style.display = 'block';
		// получаем размер
		this.framed.size.call(this.framed, inner[0]);
		// вставляем контент
		this.framed.box_inner.appendChild(inner[0]);
		// определяем элементы
		this.photo = $(this.framed.box_inner).find('.photo');
		this.photo_b = this.photo.find('b');
		this.photo_input = this.photo.find('input');
		this.send = $(this.framed.box_inner).find('.send');
		this.send_b = this.send.find('b');
		this.send_input = this.send.find('input');
		this.reload_button = $(this.framed.box_inner).find('.reload');		
		// upload								
		this.upload = new AjaxUpload(this.photo[0], {
			action: 'index.php', 
			name: 'image_banner',
			onSubmit : function(file, ext) {
				this.disable();					
				self.photo.find('.bg').animate({paddingLeft: '20px'}, 100, function() {
					self.photo.find('.bg').css({background: 'url(templates/site/images/button_min_loader.gif) no-repeat 0 50%'});
				});
				return true;
			},
			onComplete: function(file, response) {					
				self.photo.find('.bg').stop().css({background: 'none'});
				self.photo.find('.bg').stop().animate({paddingLeft: '0px'}, 100);										
				self.disablePhoto();

			},
			data: {ajax: '1', order_banner: '1'}
		});			
	}
	this.reloadEvent = function () {			
		var ob_button = $('.order_banner');		
		if(ob_button.length > 0) {
			var self = this;				
			ob_button[0].onclick = function() {					
				self.show.call(self);
				return false;
			};
		}
	}
	
	this.show = function() {		
		// показываем слой
		overlay.show({opacity: '0.5', filter: 'progid:DXImageTransform.Microsoft.Alpha(opacity=50)'});
		// показываем блок
		this.framed.show();
		// центрируем
		this.framed.setCenter(this.framed.box_inner_size.width, this.framed.box_inner_size.height);
		// анимируем		
		$(this.framed.box_inner).stop().animate({width: self.framed.box_inner_size.width + 'px', height: self.framed.box_inner_size.height + 'px'}, 100, function() {
			$(self.framed.box_inner).animate({opacity: 1, filter: 'alpha(opacity=100)'}, 100);
		});		
		// обработка закрытия		
		overlay.box.onclick = function() {
				self.framed.hide.call(self.framed);
				overlay.hide();
				return false;
			}
			
			$(self.framed.box_inner).find('.close').click(function() {
				self.framed.hide.call(self.framed);
				overlay.hide();
				return false;
			});
		// обработка отправки			
		this.eventSend(1);
		// обработка reload
		this.reload_button.click(function() {
			self.enableSend.call(self);
			self.enablePhoto.call(self);
			return false;
		});
	}
		
	this.eventSend = function(on) {
		if(on) {
			var self = this;
			this.send[0].onclick = function() {
				if(self.form.t.call(self.form, obFields, noticeFunc, '#5c5c5c')) {
					var data = $(document.forms.order_banner).serialize();
					data += '&ajax=1&site=1';					
					$.ajax({url: 'index.php', type: 'POST', data: data, dataType: 'html', success: function(r) {
						if(/send/.test(r)) {
							self.disableSend();
						}
					}});
				}
				return false;
			}
		}
		else {
			this.send[0].onclick = function() {					
				return false;
			}
		}
	}
	
	this.disableSend = function() {
		this.send.find('*').css({cursor: 'default'});
		this.send.find('.l').css({background: 'url(templates/site/images/b1l_d.gif) no-repeat 0 0'});
		this.send.find('.c').css({background: 'url(templates/site/images/b1c_d.gif) repeat-x 0 0'});
		this.send.find('.r').css({background: 'url(templates/site/images/b1r_d.gif) no-repeat 0 0'});
		this.send_b.text('Заказ принят');
		this.send_input.attr('value', 'Заказ принят');
		this.reload_button.css({display: 'block'});		
		this.eventSend(0);
	}
	
	this.enableSend = function() {
		this.send.find('*').css({cursor: 'pointer'});
		this.send.find('.l').css({background: 'url(templates/site/images/b1l.gif) no-repeat 0 0'});
		this.send.find('.c').css({background: 'url(templates/site/images/b1c.gif) repeat-x 0 0'});
		this.send.find('.r').css({background: 'url(templates/site/images/b1r.gif) no-repeat 0 0'});
		this.send_b.text('Нажмите, чтобы заказать баннер');
		this.send_input.attr('value', 'Нажмите, чтобы заказать баннер');
		this.reload_button.css({display: 'none'});		
		this.eventSend(1);			
	}
	
	this.disablePhoto = function() {
		this.photo.find('*').css({cursor: 'default'});
		this.photo.find('.l').css({background: 'url(templates/site/images/b1l_d.gif) no-repeat 0 0'});
		this.photo.find('.c').css({background: 'url(templates/site/images/b1c_d.gif) repeat-x 0 0'});
		this.photo.find('.r').css({background: 'url(templates/site/images/b1r_d.gif) no-repeat 0 0'});
		this.photo_b.text('Загружено');
		this.photo_input.attr('value', 'Загружено');
	}
	
	
	this.enablePhoto = function() {
		this.photo.find('.l').css({background: 'url(templates/site/images/b1l.gif) no-repeat 0 0'});
		this.photo.find('.c').css({background: 'url(templates/site/images/b1c.gif) repeat-x 0 0'});
		this.photo.find('.r').css({background: 'url(templates/site/images/b1r.gif) no-repeat 0 0'});
		this.photo_b.text('Загрузить');
		this.photo_input.attr('value', 'Загрузить');
		this.upload.enable();
	}
		
	
}


function abClass() {		
	this.framed = false;
	this.init = function() {			
		var self = this;
		this.framed = new Framed(1);
		this.form = new Form(document.forms.certificate);		
		this.send = false;
		this.send_b = false;
		this.send_input = false;		
		this.upload = false;
		// получаем контент
		var inner = $('.ab');
		inner[0].style.display = 'block';
		// получаем размер
		this.framed.size.call(this.framed, inner[0]);
		// вставляем контент
		this.framed.box_inner.appendChild(inner[0]);
		// определяем элементы
		this.send = $(this.framed.box_inner).find('.send');
		this.send_b = this.send.find('b');
		this.send_input = this.send.find('input');	
		this.a_close = $(this.framed.box_inner).find('a.close');
		// upload												
	}
	
	this.show = function() {
		var self = this;
		// показываем слой
		overlay.show({opacity: '0.5', filter: 'progid:DXImageTransform.Microsoft.Alpha(opacity=50)'});
		// показываем блок
		this.framed.show();
		// центрируем
		this.framed.setCenter(this.framed.box_inner_size.width, this.framed.box_inner_size.height);
		// анимируем		
		$(this.framed.box_inner).stop().animate({width: self.framed.box_inner_size.width + 'px', height: self.framed.box_inner_size.height + 'px'}, 100, function() {
			$(self.framed.box_inner).animate({opacity: 1, filter: 'alpha(opacity=100)'}, 100);
		});		
		// обработка закрытия		
		overlay.box.onclick = function() {
				self.framed.hide.call(self.framed);
				overlay.hide();
				return false;
			}
			
			$(self.framed.box_inner).find('.close').click(function() {
				self.framed.hide.call(self.framed);
				overlay.hide();
				return false;
			});
		// обработка отправки			
		this.eventSend(1);
		// обработка reload		
	}
		
	this.eventSend = function(on) {
		if(on) {
			var self = this;
			this.send[0].onclick = function() {
				if(self.form.t.call(self.form, abFields, noticeFunc, '#5c5c5c')) {
					var data = $(document.forms.certificate).serialize();
					data += '&ajax=1';				
					$.ajax({url: 'index.php', type: 'POST', data: data, dataType: 'html', success: function(r) {
						if(/send/.test(r)) {							
							self.disableSend();
						}
					}});
				}
				return false;
			}
		}
		else {
			this.send[0].onclick = function() {					
				return false;
			}
		}
	}
	
	this.disableSend = function() {
		this.send.find('*').css({cursor: 'default'});
		this.send.find('.l').css({background: 'url(templates/site/images/b1l_d.gif) no-repeat 0 0'});
		this.send.find('.c').css({background: 'url(templates/site/images/b1c_d.gif) repeat-x 0 0'});
		this.send.find('.r').css({background: 'url(templates/site/images/b1r_d.gif) no-repeat 0 0'});
		this.send_b.text('Подарок уже в пути');
		this.send_input.attr('value', 'Подарок уже в пути');
		this.a_close.fadeIn();
		this.eventSend(0);
	}

	$('#certificate_order').click(function() {
		$('#certificate_img').fadeOut(function() {
			$('#certificate_form').fadeIn();
		});
	});
	
}

// ready
jQuery(document).ready(function() {

	
	
	// order_adv
	oa = new oaClass();
	oa.init();
	oa.reloadEvent();
									
	// order_banner
	ob = new obClass();
	ob.init();
	ob.reloadEvent();
	
	// order_banner
	ab = new abClass();
	ab.init();	
	
	advBanner(ab.show, ab);
	
								
	//if(/#banner$/.test(window.location.href)) {
	//	ob.show();
	//}
	
	// Форма контакт
	if(document.forms.contact) {
		contForm = new Form(document.forms.contact);		
		// проверка данных
		document.forms.contact.onsubmit = function() {	
			if(contForm.t(contFields, noticeFunc, '#424242')) {
				var data = 'ajax=1&name='+encodeURIComponent(document.forms.contact.name.value)+'&mail='+encodeURIComponent(document.forms.contact.mail.value)+'&question='+encodeURIComponent(document.forms.contact.question.value);				
				$.ajax({url: 'index.php', type: 'POST', data: data, success: function(data) {							
					if(data == 1) {
						$('#contact_form').html('<b>Ваш вопрос отправлен, в течение суток мы ответим на него</b>');
					}					
				}
				});
			}			
			return false;
		}
	}	

	// баннер дачи.ру
	if($('#flashContent')[0]) {
		var flashvars = {};
		var params = {};
		var attributes = {};
		swfobject.embedSWF("uploads/portfolio/flash/dachi.swf", "flashContent", "240", "400", "10.0.0", "uploads/portfolio/flash/expressInstall.swf", flashvars, params, attributes);
	}
	
	// visitor
	if(document.getElementById('visitor')) {
		var v = new Visitor();		
		v.init();
	}
	
	// presentation
	if(document.getElementById('presentation_main')) {
		var p = new Presentation();
		if(/#present/.test(window.location.href)) {
			if(/\d{1,2}$/.test(window.location.href)) {
				setTimeout(function() {p.init(parseInt(window.location.href.match(/\d{1,2}$/)))}, 500);
			}
			else {
				setTimeout(p.init, 500);
			}
		}
	}
	
	// portfolio
	if(document.getElementById('portfolio_wrap')) {
		var p = new Portfolio();
		var href = window.location.href;
		if(/#[^#]+$/.test(href)) {
			var new_item = href.match(/#([^#]+)$/)[1];
			window.location.href = href.substr(0, href.length - href.match(/\/[^\/]+$/).toString().length) + '/' + new_item;
		}
	}
	
	// схема проезда
	if(document.getElementById("YMapsID")) {
		var map = new YMaps.Map(document.getElementById("YMapsID"));
		map.setCenter(new YMaps.GeoPoint(37.366842,55.765027), 14, YMaps.MapType.MAP);
		map.addControl(new YMaps.Zoom());
		map.addControl(new YMaps.ToolBar());
		map.addControl(new YMaps.TypeControl());        
		var s = new YMaps.Style();
		s.iconStyle = new YMaps.IconStyle();
		s.iconStyle.offset = new YMaps.Point(-8,-27);
		s.iconStyle.href = "http://api-maps.yandex.ru/i/0.3/placemarks/pmrdm.png";
		s.iconStyle.size = new YMaps.Point(28,29);
		YMaps.Styles.add("wizard#rdmPoint", s);        
		var placemark1 = new YMaps.Placemark(new YMaps.GeoPoint(37.364138,55.765002), {style: "wizard#rdmPoint", balloonOptions: {maxWidth: 300}});
		map.addOverlay(placemark1);
		placemark1.setBalloonContent("Рекламное Агентство Бига Тим");				
	}		
	
	p_hidden();
	
	
	
	
	// Busy	
	var busy_button = $('#busy');
	if(busy_button.length > 0) {
		var busy = new Framed();
		busy_button.click(function(e) {
			e = e || window.event;
			// показываем слой
			overlay.show({opacity: '0.5', filter: 'progid:DXImageTransform.Microsoft.Alpha(opacity=50)'});
			if(!busy.box_is_show) {			
				// получаем контент
				var inner = $('.busy');
				inner[0].style.display = 'block';		
				// получаем размер
				busy.size.call(busy, inner[0]);
				// вставляем контент		
				busy.box_inner.appendChild(inner[0]);
			}
			// показываем
			busy.show.call(busy);		
			// позиционируем
			busy.setPosition.call(busy, e);			
			// анимируем
			$(busy.box_inner).stop().animate({width: busy.box_inner_size.width + 'px', height: busy.box_inner_size.height + 'px'}, 100, function() {
				$(busy.box_inner).animate({opacity: 1, filter: 'alpha(opacity=100)'}, 100);
			});			
			// обработка закрытия
			overlay.box.onclick = $(busy.box_inner).find('.close')[0].onclick = function() {
				busy.hide.call(busy);
				overlay.hide();
			}						
			var input = busy.box_inner.getElementsByTagName('input');
			var input_vals = ['','','',''];			
			// обработка ввода данных
			for(var i = 0; i < input.length; i++) {
				if(input[i].getAttribute('type') == 'text') {					
					input[i].onkeyup = function() {
						var num = inArray( this, input );
						if(this.value.match(/^\d*$/))
							input_vals[num] = this.value;
						else
							this.value = input_vals[num];							
						if(num < 2) {
							if(this.value.length == 3) 
								input[num + 1].focus();
						}
						else if(num > 1) {
							if(this.value.length == 2)
								input[num + 1].focus();
						}
					}										
				}
			}
			// подсветка незаполненных полей
			$('input:button', busy.box_inner).click(function() {
				var err = false;
				for(var i = 0; i < input.length; i++) {
					if(input[i].getAttribute('type') == 'text') {
						if(i < 2) {
							if(!input[i].value.match(/^\d{3}$/)) {
								input[i].style.border = '1px solid red';
								err = true;
							}
							else 
								input[i].style.border = '1px solid #adadad';
						}								
						else if(i > 1) {
							if(!input[i].value.match(/^\d{2}$/)) {
								input[i].style.border = '1px solid red';
								err[i] = true;
							}
							else 
								input[i].style.border = '1px solid #adadad';								
						}
					}
				}										  						
				// отправляем
				if(!err) {
					var value = ''
					$('input:text', busy.box_inner).each(function() {					
						value += $(this).val();
					});
					$.ajax({url: 'index.php', type: 'POST', data: {ajax: 1, sec: 'contact', val: value}, success: function(data) {							
						if(data == 1) {
								$('.busy', busy.box_inner).css('width', '100%').html('<div class="succes">Ждите нашего звонка</div>');
								setTimeout(function() {
									busy.hide();
									overlay.hide();
								} , 3000);
							}
						}
					});
				}				
				return false;
			});
			return false;
		});
	}
	
	
	
	
	
	
	removeBorderTablePrice();
	tooltipInit();
});


// Tooltip
	function tooltipInit() {
		var tooltip_items = $('.tooltip');
		if(tooltip_items.length > 0) {
			var tooltip = new Framed();
			for(var i = 0; i < tooltip_items.length; i++) {
				tooltip_items[i].onmouseover = tooltip_items[i].onmouseout = function(e) {
					e = e || window.event;
					if(e.type == 'mouseover') {			
						// вставляем контент
						tooltip.box_inner.innerHTML = '<span style="font-size:12px; white-space:nowrap;">'+$(this).attr('title')+'</span>';
						// показываем
						tooltip.show.call(tooltip);
						// убираем таймер
						if(tooltip.box_hide_timer) {
							clearTimeout(tooltip.box_hide_timer);
							tooltip.box_hide_timer = false;
						}					
						// размеры																	
						var new_width = $(tooltip.box_inner).find('span').width();
						var new_height = $(tooltip.box_inner).find('span').height();
						// анимируем
						$(tooltip.box_inner).stop().animate({width: new_width + 'px', height: new_height + 'px'}, 100, function() {
							$(tooltip.box_inner).animate({opacity: 1, filter: 'alpha(opacity=100)'}, 100);
						});
					}
					else if(e.type == 'mouseout') {
						tooltip.box_hide_timer = setTimeout(function() {
							tooltip.hide.call(tooltip)}, 100);
					}
				}					
			}
			document.onmousemove = function(e) {
				e = e || window.event;	
				if(tooltip.box_is_show) tooltip.setPosition(e, tooltip.box);
			}
		}
	}

// Table Price
function removeBorderTablePrice() {
	$('table.price tr').not(':first-child').find('td:first-child').css({borderLeft: '1px solid white'});
	$('table.price tr').not(':first-child').find('td:last-child').css({borderRight: '1px solid white'});
	$('table.price tr:first-child td').css({background: '#fcfbe6'});
	$('table.price tr:last-child td').css({borderBottom: '1px solid white'});					
}

var overlay = {
	box: false,
	show: function(css) {
		if(!this.box) {
			this.box = document.createElement('div');
			this.box.id = 'overlay';
			document.body.appendChild(this.box);
		}
		var size = windowSize();
		this.box.style.width = size.vw + 'px';
		this.box.style.height = size.vh + 'px';
		if(css) {
			for(var i in css)
				this.box.style[i] = css[i];
		}
		this.box.style.display = 'block';
	},
	hide: function() {
		this.box.style.display = 'none';
	}
};


function p_hidden() {
	$('a.p_hidden_href').click(function() {
		var i = $('a.p_hidden_href').index(this);
		if($('.p_hidden_block').eq(i).is(':hidden')) {
			$('.p_hidden_block').eq(i).slideDown();
			if($('.p_hidden_block').eq(i).parents('tr').hasClass('noborder')) {
				$('.p_hidden_block').eq(i).parents('tr').find('td').css({borderTop: '1px solid #f7e8b7', borderBottom: '1px solid #f7e8b7'});
			}
		}
		else {
			$('.p_hidden_block').eq(i).slideUp();
			if($('.p_hidden_block').eq(i).parents('tr').hasClass('noborder')) {
				$('.p_hidden_block').eq(i).parents('tr').find('td').css({borderTop: '1px solid white', borderBottom: '1px solid white'});
			}
		}
		return false;
	});
}



function windowSize() {
	var 
		e = document.documentElement, 
		d = document.body,
		cw = e.clientWidth,
		ch = e.clientHeight,
		sw = e.scrollWidth,
		sh = e.scrollHeight,
		st = e.scrollTop > d.scrollTop ? e.scrollTop : d.scrollTop,
		sl = e.scrollLeft,
		vw = cw > sw ? cw : sw,
		vh = ch > sh ? ch : sh;
	return {'vw': vw, 'vh': vh, 'cw': cw, 'ch': ch, 'sw': sw, 'sh': sh, 'st': st, 'sl': sl}
}



function offsetPosition(element) {
		var offsetLeft = offsetTop = 0;
		do {
			offsetLeft += element.offsetLeft;
			offsetTop  += element.offsetTop;
		} while (element = element.offsetParent);
		return [offsetLeft, offsetTop];
	}	

function inArray( elem, array ) {
		for ( var i = 0, length = array.length; i < length; i++ )
			if ( array[ i ] === elem )
				return i;
		return -1;
	}
	

