// JavaScript Document
var cImage='';
var size = '';
$(document).ready(function(){
	
	/*  Фотогалерея  */
	
	$('.gal').children('img').click(function(){
		gal = $(this).parent()
		cImage = gal.find('img').index($(this));
		size = gal.find('img').size();
		$('.bg').css({width:$(document).width(),height:$(document).height(),zIndex:1000,'background':'#fff','opacity':'0.9', position:'absolute',left:'0',top:'0'}).show();
		tmp = $(this).attr('rel').split(',');
		if (tmp[1]>612) tmp[1] = 612;
		$('.gall_full').remove();
		$('body').append('<div class="gall_full">'+
	'		<div class="img_cont">'+
	'			<a href="' + url + 'photos/' + tmp[0] + '" title="В полный размер" target="_blank"><img src="' + tmp[0] + '" width="' + ((parseInt(tmp[1]) + 16)<613?tmp[1]:'612') + '"/></a>'+
	'		</div>'+
	'		<div class="close"><img src="' + url + 'img/delete.png" /></div>'+
	'		<div class="arrow_forvard"><img src="' + url + 'img/arrow_forvard.png" /></div>'+
	'		<div class="arrow_back"><img src="' + url + 'img/arrow_back.png" /></div>'+
	'	</div>');
		$('.gall_full').css({position:'fixed', width:((parseInt(tmp[1]) + 16)<629?(parseInt(tmp[1]) + 16):'628'), left:'50%', top:'216px', 'margin-left':'-' + (parseInt(tmp[1])/2) + 'px', zIndex:'2000'});
		$('.img_cont').css({height:'407px'});
		$('.close, .bg').click(function(){
			$('.gall_full').empty();
			$('.bg').hide();
		})
		$('.arrow_forvard').click(function(){
			if (parseInt(cImage)+1==size) next = 0;
			else next = parseInt(cImage) + 1;
			cImage = next;
			img = gal.find('img:eq(' + next + ')');
			tmp = img.attr('rel').split(',');
			if (tmp[1]>612) tmp[1] = 612;
			$('.gall_full').css({position:'fixed', width:((parseInt(tmp[1]) + 16)<629?(parseInt(tmp[1]) + 16):'628'), left:'50%', top:'216px', 'margin-left':'-' + (parseInt(tmp[1])/2) + 'px', zIndex:'2000'});
			$('.img_cont').empty().append('<a href="' + tmp[0] + '" title="В полный размер" target="_blank"><img src="' + tmp[0] + '" width="' + ((parseInt(tmp[1]) + 16)<613?tmp[1]:'612') + '"/></a>');
		})
		$('.arrow_back').click(function(){
			if (parseInt(cImage)-1<0) next = size;
			else next = parseInt(cImage) - 1;
			cImage = next;
			img = gal.find('img:eq(' + next + ')');
			tmp = img.attr('rel').split(',');
			if (tmp[1]>612) tmp[1] = 612;
			$('.gall_full').css({position:'fixed', width:((parseInt(tmp[1]) + 16)<629?(parseInt(tmp[1]) + 16):'628'), left:'50%', top:'216px', 'margin-left':'-' + (parseInt(tmp[1])/2) + 'px', zIndex:'2000'});
			$('.img_cont').empty().append('<a href="' + tmp[0] + '" title="В полный размер" target="_blank"><img src="' + tmp[0] + '" width="' + ((parseInt(tmp[1]) + 16)<613?tmp[1]:'612') + '"/></a>');
		})
	})
	
	/*  Фотогалерея  */
	
	/*  Свободные площади  */
	
	if (typeof page !=="undefined" && page=="free")
	{
		var free_arr = new Array();
		$('.free_area').each(function(){
			free_arr[$(this).attr('rel')]=$(this).children('.text').attr('rel');
		})
		for (i=0;i<12;i++)
		{
			rel = (parseInt(i) + 1) + ',3';
			flr = (parseInt(i) + 1);
			if (free_arr[rel])
			{
				$('.header').append('<div class="plate' + 3 + '" ><span>' + flr + ' этаж</span><font>свободно</font></div>');
			}
			else
			{
				$('.header').append('<div class="plate' + 3 + ' big" ><span>' + flr + '-й этаж</span><font>в настоящее время вакантных площадей нет</font></div>');
			}
			tmp = $('<div class="mark" rel="' + (parseInt(i) + 1) + ',3"/>')
			$('.header').append(tmp);
			tmp.css({left:'5px',width:'277px', bottom:i*9,'height':10})
		}
		for (i=0;i<13;i++)
		{
			rel = (parseInt(i) + 1) + ',2';
			flr = (parseInt(i) + 1);
			if (free_arr[rel])
			{
				$('.header').append('<div class="plate' + 2 + '" ><span>' + flr + ' этаж</span><font>свободно</font></div>');
			}
			else
			{
				$('.header').append('<div class="plate' + 2 + ' big" ><span>' + flr + '-й этаж</span><font>в настоящее время вакантных площадей нет</font></div>');
			}
			tmp = $('<div class="mark" rel="' + (parseInt(i) + 1) + ',2"/>')
			$('.header').append(tmp);
			tmp.css({left:'282px',width:'292px', bottom:i*9,'height':10})
		}
		for (i=0;i<26;i++)
		{
			rel = (parseInt(i) + 1) + ',1';
			flr = (parseInt(i) + 1);
			if (free_arr[rel])
			{
				if (flr>=4 && flr<=8) $('.header').append('<div class="plate' + 1 + '" ' + (i>10?'style="top:auto; bottom:' + (i*13+10) + 'px"':'') + ' ><span>' + flr + '-й этаж</span><font>паркинг</font></div>')
				else 
				$('.header').append('<div class="plate' + 1 + '" ' + (i>10?'style="top:auto; bottom:' + (i*13+10) + 'px"':'') + ' ><span>' + flr + ' этаж</span><font>свободно</font></div>');
			}
			else
			{
				if (flr>=4 && flr<=8) $('.header').append('<div class="plate' + 1 + '" ' + (i>10?'style="top:auto; bottom:' + (i*13+10) + 'px"':'') + ' ><span>' + flr + '-й этаж</span><font>паркинг</font></div>')
				else 
				$('.header').append('<div class="plate' + 1 + ' big"  ' + (i>10?'style="top:auto; bottom:' + (i*13+10) + 'px"':'') + ' ><span>' + flr + ' этаж</span><font>в настоящее время вакантных площадей нет</font></div>');
			}
			tmp = $('<div class="mark" rel="' + (parseInt(i) + 1) + ',1"/>')
			$('.header').append(tmp);
			if (i*1+1<3) w = '445px';
			if (i*1+1==3) w = '430px';
			if (i*1+1>3 && i*1+1<6) w = '419px';
			if (i*1+1>=6 && i*1+1<8) w = '369px';
			if (i*1+1==8) w = '355px';
			if (i*1+1>=9) w = '295px';
			if (i*1+1>=10) w = '285px';
			if (i*1+1>=11) w = '187px';
			tmp.css({left:'574px',width:w, bottom:i*13,'height':13})
		}
		$('.mark').hover(function(){
			$(this).css('opacity','0.7')
			tmp = $(this).attr('rel').split(',');
			$('.plate'+ tmp[1]).hide()
			$('.plate'+ tmp[1] +':eq(' + (tmp[0]-1) + ')').show()
		},function(){
			if ($(this).not('.active')) $(this).css('opacity','0')
			tmp = $(this).attr('rel').split(',');
			$('.plate'+ tmp[1] +':eq(' + (tmp[0]-1) + ')').hide();
		})
		$('.mark').click(function(){
			
			rel = $(this).attr('rel');
			if (free_arr[rel])
			{
				$('.mark').css('opacity','0');
				$(this).css('opacity','0.7');
				tmp = $(this).attr('rel').split(',');
				flr = tmp[0];
				stage = tmp[1];
				if (stage=='1') 
				{
					$('.s2,.s3').css('opacity','0.7');
					$('.s1').stop().fadeOut();
					$('.s2').stop().fadeIn();
					$('.s3').stop().fadeIn();
				}
				if (stage=='2') 
				{
					$('.s1,.s3').css('opacity','0.7');
					$('.s2').stop().fadeOut();
					$('.s1').stop().fadeIn();
					$('.s3').stop().fadeIn();
				}
				if (stage=='3')
				{
					$('.s2,.s1').css('opacity','0.7');
					$('.s3').stop().fadeOut();
					$('.s2').stop().fadeIn();
					$('.s1').stop().fadeIn();
				}
				$('.free_area').each(function(){
					if ($(this).attr('rel')==rel) $(this).show()
					else $(this).hide();
				})
				$('.mark').unbind('mouseenter mouseleave');
				setTimeout(function(){
					$('.mark').hover(function(){
						$(this).css('opacity','0.7')
						tmp = $(this).attr('rel').split(',');
						$('.plate'+ tmp[1]).hide()
						$('.plate'+ tmp[1] +':eq(' + (tmp[0]-1) + ')').show()
					},function(){
						if ($(this).not('.active')) $(this).css('opacity','0')
						tmp = $(this).attr('rel').split(',');
						$('.plate'+ tmp[1] +':eq(' + (tmp[0]-1) + ')').hide();
					})
				},1000)
			}
		})
	}
	
	$('.fr_link').click(function(){
		id = $(this).attr('rel');
		$('.fr_link').removeClass('active');
		$(this).addClass('active');
		$('.free_area').hide();
		cur = $('.free_area:eq(' + id + ')');
		cur.show();
		tmp = cur.attr('rel').split(',');
		flr = tmp[0];
		stage = tmp[1];
		if (stage=='1') 
		{
			$('.s2,.s3').css('opacity','0.7');
			$('.s1').stop().fadeOut();
			$('.s2').stop().fadeIn();
			$('.s3').stop().fadeIn();
		}
		if (stage=='2') 
		{
			$('.s1,.s3').css('opacity','0.7');
			$('.s2').stop().fadeOut();
			$('.s1').stop().fadeIn();
			$('.s3').stop().fadeIn();
		}
		if (stage=='3')
		{
			$('.s2,.s1').css('opacity','0.7');
			$('.s3').stop().fadeOut();
			$('.s2').stop().fadeIn();
			$('.s1').stop().fadeIn();
		}
		$('.mark').each(function(){
			if ($(this).attr('rel')==cur.attr('rel'))
			{
				$(this).css('opacity','0.7');
				tmp = $(this).attr('rel').split(',');
				$('.plate'+ tmp[1] +':eq(' + (tmp[0]-1) + ')').show()
			}
			else
			{
				$(this).css('opacity','0');
				tmp = $(this).attr('rel').split(',');
				$('.plate'+ tmp[1] +':eq(' + (tmp[0]-1) + ')').hide()
			}
		})
		return false;
	})
	
	/*  Свободные площади  */
	
	/*  Аренда  */
	
	if (typeof page !=="undefined" && page=="arenda")
	{
		var free_arr = new Array();
		$('.free').each(function(){
			free_arr[$(this).attr('rel')]=$(this).children('.text').attr('rel');
		})
		for (i=0;i<12;i++)
		{
			rel = (parseInt(i) + 1) + ',3';
			flr = (parseInt(i) + 1);
			if (free_arr[rel])
			{
				$('.header').append('<div class="plate' + 3 + '" ><span>' + flr + '-й этаж</span><font>свободно</font></div>');
			}
			else
			{
				$('.header').append('<div class="plate' + 3 + ' big" ><span>' + flr + '-й этаж</span><font>в настоящее время вакантных площадей нет</font></div>');
			}
			tmp = $('<div class="mark" rel="' + (parseInt(i) + 1) + ',3"/>')
			$('.header').append(tmp);
			tmp.css({left:'5px',width:'277px', bottom:i*9,'height':10})
		}
		for (i=0;i<13;i++)
		{
			rel = (parseInt(i) + 1) + ',2';
			flr = (parseInt(i) + 1);
			if (free_arr[rel])
			{
				$('.header').append('<div class="plate' + 2 + '" ><span>' + flr + '-й этаж</span><font>свободно</font></div>');
			}
			else
			{
				$('.header').append('<div class="plate' + 2 + ' big" ><span>' + flr + '-й этаж</span><font>в настоящее время вакантных площадей нет</font></div>');
			}
			tmp = $('<div class="mark" rel="' + (parseInt(i) + 1) + ',2"/>')
			$('.header').append(tmp);
			tmp.css({left:'282px',width:'292px', bottom:i*9,'height':10})
		}
		for (i=0;i<26;i++)
		{
			rel = (parseInt(i) + 1) + ',1';
			flr = (parseInt(i) + 1);
			if (free_arr[rel])
			{
				if (flr>=4 && flr<=8) $('.header').append('<div class="plate' + 1 + '" ' + (i>10?'style="top:auto; bottom:' + (i*13+10) + 'px"':'') + ' ><span>' + flr + '-й этаж</span><font>паркинг</font></div>')
				else $('.header').append('<div class="plate' + 1 + '" ' + (i>10?'style="top:auto; bottom:' + (i*13+10) + 'px"':'') + ' ><span>' + flr + '-й этаж</span><font>свободно</font></div>');
			}
			else
			{
				if (flr>=4 && flr<=8) $('.header').append('<div class="plate' + 1 + '" ' + (i>10?'style="top:auto; bottom:' + (i*13+10) + 'px"':'') + ' ><span>' + flr + '-й этаж</span><font>паркинг</font></div>')
				else $('.header').append('<div class="plate' + 1 + ' big"  ' + (i>10?'style="top:auto; bottom:' + (i*13+10) + 'px"':'') + ' ><span>' + flr + '-й этаж</span><font>в настоящее время вакантных площадей нет</font></div>');
			}
			tmp = $('<div class="mark" rel="' + (parseInt(i) + 1) + ',1"/>')
			$('.header').append(tmp);
			if (i*1+1<3) w = '445px';
			if (i*1+1==3) w = '430px';
			if (i*1+1>3 && i*1+1<6) w = '419px';
			if (i*1+1>=6 && i*1+1<8) w = '369px';
			if (i*1+1==8) w = '355px';
			if (i*1+1>=9) w = '295px';
			if (i*1+1>=10) w = '285px';
			if (i*1+1>=11) w = '187px';
			tmp.css({left:'574px',width:w, bottom:i*13,'height':13})
		}
		$('.mark').hover(function(){
			$(this).css('opacity','0.7')
			tmp = $(this).attr('rel').split(',');
			$('.plate'+ tmp[1]).hide()
			$('.plate'+ tmp[1] +':eq(' + (tmp[0]-1) + ')').show()
		},function(){
			if ($(this).not('.active')) $(this).css('opacity','0')
			tmp = $(this).attr('rel').split(',');
			$('.plate'+ tmp[1] +':eq(' + (tmp[0]-1) + ')').hide();
		})
		$('.mark').click(function(){
			
			rel = $(this).attr('rel');
			//if (free_arr[rel])
			{
				$('.mark').css('opacity','0');
				$(this).css('opacity','0.7');
				tmp = $(this).attr('rel').split(',');
				flr = tmp[0];
				stage = tmp[1];
				if (stage=='1') 
				{
					$('.s1').stop().fadeOut();
					$('.s2').stop().fadeIn();
					$('.s3').stop().fadeIn();
				}
				if (stage=='2') 
				{
					$('.s2').stop().fadeOut();
					$('.s1').stop().fadeIn();
					$('.s3').stop().fadeIn();
				}
				if (stage=='3')
				{
					$('.s3').stop().fadeOut();
					$('.s2').stop().fadeIn();
					$('.s1').stop().fadeIn();
				}
				$('.free_area').each(function(){
					if ($(this).attr('rel')==rel) $(this).show()
					else $(this).hide();
				})
				$('.mark').unbind('mouseenter mouseleave');
				setTimeout(function(){
					$('.mark').hover(function(){
						$(this).css('opacity','0.7')
						tmp = $(this).attr('rel').split(',');
						$('.plate'+ tmp[1]).hide()
						$('.plate'+ tmp[1] +':eq(' + (tmp[0]-1) + ')').show()
					},function(){
						if ($(this).not('.active')) $(this).css('opacity','0')
						tmp = $(this).attr('rel').split(',');
						$('.plate'+ tmp[1] +':eq(' + (tmp[0]-1) + ')').hide();
					})
				},1000)
			}
		})
	}
	
	if (typeof page !=="undefined" && page=="arenda")
	{
		if(typeof stage !=="undefined" && stage==1)
		{
			$('.links a.active').after(
					'<div class="a_links">'+
						'<a href="" class="arend_link" rel="1,1">этаж 1</a><a href="" class="arend_link" rel="11,1">этаж 11</a><a href="" class="arend_link" rel="21,1">этаж 21</a>'+
						'<a href="" class="arend_link" rel="2,1">этаж 2</a><a href="" class="arend_link" rel="12,1">этаж 12</a><a href="" class="arend_link" rel="22,1">этаж 22</a>'+
						'<a href="" class="arend_link" rel="3,1">этаж 3</a><a href="" class="arend_link" rel="13,1">этаж 13</a><a href="" class="arend_link" rel="23,1">этаж 23</a>'+
						'<a href="" class="arend_link" rel="4,1">этаж 4</a><a href="" class="arend_link" rel="14,1">этаж 14</a><a href="" class="arend_link" rel="24,1">этаж 24</a>'+
						'<a href="" class="arend_link" rel="5,1">этаж 5</a><a href="" class="arend_link" rel="15,1">этаж 15</a><a href="" class="arend_link" rel="25,1">этаж 25</a>'+
						'<a href="" class="arend_link" rel="6,1">этаж 6</a><a href="" class="arend_link" rel="16,1">этаж 16</a><a href="" class="arend_link" rel="26,1">этаж 26</a>'+
						'<a href="" class="arend_link" rel="7,1">этаж 7</a><a href="" class="arend_link" rel="17,1">этаж 17</a><div class="clear"></div>'+
						'<a href="" class="arend_link" rel="8,1">этаж 8</a><a href="" class="arend_link" rel="18,1">этаж 18</a><div class="clear"></div>'+
						'<a href="" class="arend_link" rel="9,1">этаж 9</a><a href="" class="arend_link" rel="19,1">этаж 19</a><div class="clear"></div>'+
						'<a href="" class="arend_link" rel="10,1">этаж 10</a><a href="" class="arend_link" rel="20,1">этаж 20</a>'+
						'<div class="clear"></div>'+
					'</div>'
				);

		}
		if(typeof stage !=="undefined" && stage==2)
		{
			$('.links a.active').after(
				'<div class="a_links">'+
						'<a href="" class="arend_link" rel="1,2">этаж 1</a><a href="" class="arend_link" rel="11,2">этаж 11</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />'+
						'<a href="" class="arend_link" rel="2,2">этаж 2</a><a href="" class="arend_link" rel="12,2">этаж 12</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />'+
						'<a href="" class="arend_link" rel="3,2">этаж 3</a><a href="" class="arend_link" rel="13,2">этаж 13</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />'+
						'<a href="" class="arend_link" rel="4,2">этаж 4</a><div class="clear"></div>'+
						'<a href="" class="arend_link" rel="5,2">этаж 5</a><div class="clear"></div>'+
						'<a href="" class="arend_link" rel="6,2">этаж 6</a><div class="clear"></div>'+
						'<a href="" class="arend_link" rel="7,2">этаж 7</a><div class="clear"></div>'+
						'<a href="" class="arend_link" rel="8,2">этаж 8</a><div class="clear"></div>'+
						'<a href="" class="arend_link" rel="9,2">этаж 9</a><div class="clear"></div>'+
						'<a href="" class="arend_link" rel="10,2">этаж 10</a>'+
						'<div class="clear"></div>'+
					'</div>'
				);
		}
		if(typeof stage !=="undefined" && stage==3)
		{
			$('.links a.active').after(
					'<div class="a_links">'+
						'<a href="" class="arend_link" rel="1,3">этаж 1</a><a href="" class="arend_link" rel="11,3">этаж 11</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />'+
						'<a href="" class="arend_link" rel="2,3">этаж 2</a><a href="" class="arend_link" rel="12,3">этаж 12</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />'+
						'<a href="" class="arend_link" rel="3,3">этаж 3</a><div class="clear"></div>'+
						'<a href="" class="arend_link" rel="4,3">этаж 4</a><div class="clear"></div>'+
						'<a href="" class="arend_link" rel="5,3">этаж 5</a><div class="clear"></div>'+
						'<a href="" class="arend_link" rel="6,3">этаж 6</a><div class="clear"></div>'+
						'<a href="" class="arend_link" rel="7,3">этаж 7</a><div class="clear"></div>'+
						'<a href="" class="arend_link" rel="8,3">этаж 8</a><div class="clear"></div>'+
						'<a href="" class="arend_link" rel="9,3">этаж 9</a><div class="clear"></div>'+
						'<a href="" class="arend_link" rel="10,3">этаж 10</a><div class="clear"></div>'+
						'<div class="clear"></div>'+
					'</div>'
				);
		}
	}
	
	$('.arend_link').click(function(){
		id = $(this).attr('rel');
		$('.arend_link').removeClass('active');
		$(this).addClass('active');
		$('.free_area').hide();
		var cur;
		$('.free_area').each(function(){
			if ($(this).attr('rel')==id) cur = $(this);
		})
		//cur = $('.free_area:eq(' + id + ')');
		cur.show();
		tmp = cur.attr('rel').split(',');
		flr = tmp[0];
		stage = tmp[1];
		if (stage=='1') 
		{
			$('.s1').stop().fadeOut();
			$('.s2').stop().fadeIn();
			$('.s3').stop().fadeIn();
		}
		if (stage=='2') 
		{
			$('.s2').stop().fadeOut();
			$('.s1').stop().fadeIn();
			$('.s3').stop().fadeIn();
		}
		if (stage=='3')
		{
			$('.s3').stop().fadeOut();
			$('.s2').stop().fadeIn();
			$('.s1').stop().fadeIn();
		}
		$('.mark').each(function(){
			if ($(this).attr('rel')==cur.attr('rel'))
			{
				$(this).css('opacity','0.7');
				tmp = $(this).attr('rel').split(',');
				$('.plate'+ tmp[1] +':eq(' + (tmp[0]-1) + ')').show()
			}
			else
			{
				$(this).css('opacity','0');
				tmp = $(this).attr('rel').split(',');
				$('.plate'+ tmp[1] +':eq(' + (tmp[0]-1) + ')').hide()
			}
		})
		return false;
	})
	
	/*  Аренда  */
	
	$('.order').find('a.order_link').click(function(){
		error = 0;
		$('.order').find('input, textarea').each(function(){
			if ($(this).attr('rel')=='default')
			{
				if ($(this).val()=='')
				{
					error = 1;
					$(this).css('border','1px solid #ff4c4c');
				}
				else $(this).css('border','1px solid #c5c4c4');
			}
		})
		if (error==0) document.order.submit();
		return false;
	})
	$('.login_link').click(function(){
		document.login_form.submit();
		return false;
	})
	/*  Конференц-зал  */
	setInterval(function(){
		var today = new Date()
		$('.time').html(startTime());
	},1000)
	$('.c_forward').click(function(){
		size = $('.c_item').size();
		par = $(this).parent().parent();
		current = $('.calendar').children('.c_item').index(par);
		if (parseInt(current)+1<size) 
		{
			par.hide();
			$('.calendar').children('.c_item:eq(' + (parseInt(current)+1) + ')').show();
		}
		else next = 0;
	})
	$('.c_back').click(function(){
		size = $('.c_item').size();
		par = $(this).parent().parent();
		current = $('.calendar').children('.c_item').index(par);
		if (current>0) 
		{
			par.hide();
			$('.calendar').children('.c_item:eq(' + (parseInt(current)-1) + ')').show();
		}
		else next = 0;
	})
	/*  Конференц-зал  */
	/* Заказы */
	$('#add_orders_link').click(function(){ $('#add_orders').toggle(); });
	$('#search_orders_link').click(function(){ $('#search_orders').toggle(); });
})

function startTime()
{
var tm=new Date();
var h=tm.getHours();
var m=tm.getMinutes();
var s=tm.getSeconds();
h=checkTime(h);
m=checkTime(m);
s=checkTime(s);
return h+" : "+m+" : "+s;
}
function checkTime(i)
{
if (i<10)
{
i="0" + i;
}
return i;
}
