var top = {};

var pre = [];
var loading_ = 0;
var loading_timer = [];

var slide_show_ = 0;
var slide_show_timer = 0;
var set_img = '';

$(document).ready(function()
{

	init();

	$(window).resize(function()
	{
		//resize();
	});

	$('a.menu_link').hover(function()
	{
		
	},function()
	{
		
	});
	
	$('span.menu').hover(function()
	{
		var obj = $(this).children('div.menu_down');
		var height = $(obj).stop().css({'height':'auto','opacity':'0'}).show().height()/4;
		$(this).children('div.menu_line').stop().animate({'width':'150px'},400);
		$(obj).stop().css({'height':'0px'}).animate({'height':(3*height)+'px','opacity':'0.7'},150,'linear',function()
		{
			$(obj).animate({'height':(4*height)+'px','opacity':'1.0'},350,'linear',function()
			{
				
			});
		});
	},function()
	{
		var obj = $(this).children('div.menu_down');
		var height = $(obj).height()/4;
		$(this).children('div.menu_line').stop().animate({'width':'0px'},400,function(){$(this).css({'left':'0px'});});
		$(obj).stop().animate({'height':(3*height)+'px','opacity':'0.7'},350,'linear',function()
		{
			$(obj).animate({'height':'0px','opacity':'0.0'},150,'linear',function()
			{
				$(obj).hide();
			});
		});
	});
	
	$('#admin_form').hover(function()
	{
		$(this).stop().animate({'height':'24px'},400);
		$('#autorization_form').stop().animate({'margin-top':'5px'},400);
	},function()
	{
		if(autorization_f)
		{
			$(this).stop().animate({'height':'24px'},100);
			$('#autorization_form').stop().animate({'margin-top':'5px'},100);
		}
		else
		{
			$(this).stop().animate({'height':'10px'},400);
			$('#autorization_form').stop().animate({'margin-top':'10px'},400);
		}
	});
	
	$('.window_close').live('click',function()
	{
		$('div#window').stop().animate({'opacity':'0'},400,function()
		{
			$(this).css({'display':'none'});
			$('div#loading').stop().animate({'opacity':'0'},400,function()
			{
				$(this).css({'display':'none'});
				$('div#hidden').stop().animate({'opacity':'0'},400,function()
				{
					$(this).css({'display':'none'});
					$('div.window').css({'display':'none','opacity':'0'});
					$('div#window').css({'width':'auto','height':'auto'});
				});
			});
		});
	});
	
	$('.reserve,#reserve').live('click',function()
	{
		//var href = $(this).attr('href');
		
		var win = new window.open('/module/reserve/','reserve');
		
		
		
		
		
		//win.focus();

		//reserve(href);
		return false;
	});
	$('#reserve_select').live('change',function()
	{
		var obj = this;
		$(obj).parent().children('.sub_1,.sub_2,.sub_3,.sub_4,.sub_5,.sub_6,.sub_7,.sub_8').stop().slideUp(400)
		$(obj).parent().children('.sub_0').stop().slideUp(400,function()
		{
			$(obj).parent().children('.sub_'+$(obj).attr('value')).stop().slideDown(400,function()
			{
				var valign_obj = 'div#window';
				var align_obj = $(valign_obj).parent();
				if($(valign_obj).height() < $(align_obj).height())
				{
					top[valign_obj] = (($(align_obj).height() - $(valign_obj).height())/2) + 'px';
					$(valign_obj).animate({'top':top[valign_obj]});
				}
				else
				{
					$(valign_obj).animate({'top':'0px'});
				}
			});
		});
	});
	$('.date_in,.date_out,.mr_date_in,.mr_date_out').live('click',function()
	{
		$('.calendar_in,.calendar_out').css({'display':'none'});
		var element = this;
		$.post('/module/calendar/',{},function(data)
		{
			if($(element).attr('val') == 1) left = 136 +'px';
			if($(element).attr('val') == 2) left = 468 +'px';
			$(element).next().next().html(data).css({'left':left,'display':'block'});
		});
	});
	$('.calendar_in a.c_left,.calendar_in a.c_right,.calendar_out a.c_left,.calendar_out a.c_right').live('click',function()
	{
		var my = '' + $(this).parent().children('span').html();
		my = my.split('\/');
		if($(this).attr('class') == 'c_left')
		{
			my[0] = 1*my[0] - 1;
			if(1*my[0]<1)
			{
				my[0] = '12'
				my[1] = 1*my[1] - 1;
			}
		}
		if($(this).attr('class') == 'c_right')
		{
			my[0] = 1*my[0] + 1;
			if(1*my[0]>12)
			{
				my[0] = '01';
				my[1] = 1*my[1] + 1;
			}
		}
		var element = $(this).parent();
		$.post('/module/calendar/',{'date':'01/'+ my[0] +'/'+my[1]},function(data)
		{
			$(element).html(data);
		});
	});
	$('.calendar_in div.row div,.calendar_out div.row div').live('click',function()
	{
		if($(this).html() != '&nbsp;')
		{
			var element = $(this).parent().parent();
			var my = $(this).parent().parent().children('span').html();
			var d = $(this).html();
			my = my.split('/');
			$(this).parent().parent().prev().prev().attr({'value':d+'.'+my[0]+'.'+my[1]});
			$('.calendar_in,.calendar_out').css({'display':'none'});
		}
		else
		{
			$(this).parent().parent().prev().prev().attr({'value':''});
			$('.calendar_in,.calendar_out').css({'display':'none'});
		}
	});
	$('.res_date,.ev_date').live('click',function()
	{
		$('.res_calendar,ev_calendar').css({'display':'none'});
		var element = this;
		$.post('/module/calendar/',{},function(data)
		{
			left = 136 +'px';
			$(element).next().html(data).css({'left':left,'display':'block'});
		});
	});
	$('.res_calendar a.c_left,.res_calendar a.c_right,.ev_calendar a.c_left,.ev_calendar a.c_right').live('click',function()
	{
		var my = '' + $(this).parent().children('span').html();
		my = my.split('\/');
		if($(this).attr('class') == 'c_left')
		{
			my[0] = 1*my[0] - 1;
			if(1*my[0]<1)
			{
				my[0] = '12'
				my[1] = 1*my[1] - 1;
			}
		}
		if($(this).attr('class') == 'c_right')
		{
			my[0] = 1*my[0] + 1;
			if(1*my[0]>12)
			{
				my[0] = '01';
				my[1] = 1*my[1] + 1;
			}
		}
		var element = $(this).parent();
		$.post('/module/calendar/',{'date':'01/'+ my[0] +'/'+my[1]},function(data)
		{
			$(element).html(data);
		});
	});
	$('.res_calendar div.row div,.ev_calendar div.row div').live('click',function()
	{
		if($(this).html() != '&nbsp;')
		{
			var element = $(this).parent().parent();
			var my = $(this).parent().parent().children('span').html();
			var d = $(this).html();
			my = my.split('/');
			$(this).parent().parent().prev().attr({'value':d+'.'+my[0]+'.'+my[1]});
			$('.res_calendar,.ev_calendar').css({'display':'none'});
		}
		else
		{
			$(this).parent().parent().prev().attr({'value':''});
			$('.res_calendar,.ev_calendar').css({'display':'none'});
		}
	});
	
	$('.calendar_in a.c_close,.calendar_out a.c_close,.res_calendar a.c_close,.ev_calendar a.c_close').live('click',function()
	{
		$('.calendar_in,.calendar_out,.res_calendar,.ev_calendar').css({'display':'none'});
	});
	
	$('#garant, #nogarant').live('click',function()
	{
		$('#garant, #nogarant').attr({'checked':false});
		$(this).attr({'checked':true});
		if($(this).attr('id') == 'garant')
		{
			$('#card_name').attr({'disabled':false});
			$('#card_n').attr({'disabled':false});
			$('#card_date').attr({'disabled':false});
		}
		else
		{
			$('#card_name').attr({'disabled':true});
			$('#card_n').attr({'disabled':true});
			$('#card_date').attr({'disabled':true});
		}
	});
	$('.send').live('click',function()
	{
		var name2,name1,tel,mail,pay,reserve_select,comments;
		var room1,date_in1,date_out1,count_men1,count_children_11,count_children_21,count_children_31,room2,date_in2,date_out2,count_men2,count_children_12,count_children_22,count_children_32,garant,card_name,card_n,card_date;
		var res_date,res_zal,res_count,res_event;
		var mr_zal,mr_count,mr_date_in,mr_date_out,mr_time_in,mr_time_out,mr_date11,mr_time11,mr_count11,mr_menu11,mr_date12,mr_time12,mr_count12,mr_menu12,mr_date21,mr_time21,mr_count21,mr_menu21,mr_date22,mr_time22,mr_count22,mr_menu22;
		var ev_event,ev_count,ev_date,ev_time;
		
		if($('#reserve_select').attr('value') == 1)
		{
			reserve_select = 1;
			if($('#room1').attr('value') || $('#room2').attr('value'))
			{
				if($('#room1').attr('value'))
				{
					room1 = $('#room1').attr('value');
					if($('#date_in1').attr('value'))
					{
						date_in1 = $('#date_in1').attr('value');
					}
					else
					{
						alert($('#date_in1').attr('title'));
						return false;
					}
					if($('#date_out1').attr('value'))
					{
						date_out1 = $('#date_out1').attr('value');
					}
					else
					{
						alert($('#date_out1').attr('title'));
						return false;
					}
					if($('#count_men1').attr('value'))
					{
						count_men1 = $('#count_men1').attr('value');
					}
					else
					{
						alert($('#count_men1').attr('title'));
						return false;
					}
					
				}
				if($('#room2').attr('value'))
				{
					room2 = $('#room2').attr('value');
					if($('#date_in2').attr('value'))
					{
						date_in2 = $('#date_in2').attr('value');
					}
					else
					{
						alert($('#date_in2').attr('title'));
						return false;
					}
					if($('#date_out2').attr('value'))
					{
						date_out2 = $('#date_out2').attr('value');
					}
					else
					{
						alert($('#date_out2').attr('title'));
						return false;
					}
					if($('#count_men2').attr('value'))
					{
						count_men2 = $('#count_men2').attr('value');
					}
					else
					{
						alert($('#count_men2').attr('title'));
						return false;
					}
				}
				if($('#garant').attr('checked') == true)
				{
					garant = $('#garant').attr('value');
					if($('#card_name').attr('value'))
					{
						card_name = $('#card_name').attr('value');
					}
					else
					{
						alert($('#card_name').attr('title'));
						return false;
					}
					if($('#card_n').attr('value'))
					{
						card_n = $('#card_n').attr('value');
					}
					else
					{
						alert($('#card_n').attr('title'));
						return false;
					}
					if($('#card_date').attr('value'))
					{
						card_date = $('#card_date').attr('value');
					}
					else
					{
						alert($('#card_date').attr('title'));
						return false;
					}
				}
			}
			else
			{
				alert($('#room1').attr('title'));
				return false;
			}
		}
		else if($('#reserve_select').attr('value') == 2)
		{
			reserve_select = 2;
			if($('#res_date').attr('value'))
			{
				res_date = $('#res_date').attr('value');
			}
			else
			{
				alert($('#res_date').attr('title'));
			}
			if($('#res_zal').attr('value'))
			{
				res_zal = $('#res_zal').attr('value');
			}
			else
			{
				alert($('#res_zal').attr('title'));
			}
			if($('#res_count').attr('value'))
			{
				res_count = $('#res_count').attr('value');
			}
			else
			{
				alert($('#res_count').attr('title'));
			}
			if($('#res_event').attr('value'))
			{
				res_event = $('#res_event').attr('value');
			}
			else
			{
				alert($('#res_event').attr('title'));
			}
		}
		else if($('#reserve_select').attr('value') == 3)
		{
			reserve_select = 3;
			if($('#mr_zal').attr('value'))
			{
				mr_zal = $('#mr_zal').attr('value');
			}
			else
			{
				alert($('#mr_zal').attr('title'));
			}
			if($('#mr_count').attr('value'))
			{
				mr_count = $('#mr_count').attr('value');
			}
			else
			{
				alert($('#mr_count').attr('title'));
			}
		}
		else if($('#reserve_select').attr('value') == 4)
		{
			reserve_select = 4;
			if($('#ev_event').attr('value'))
			{
				ev_event = $('#ev_event').attr('value');
			}
			else
			{
				alert($('#ev_event').attr('title'));
			}
			if($('#ev_count').attr('value'))
			{
				ev_count = $('#ev_count').attr('value');
			}
			else
			{
				alert($('#ev_count').attr('title'));
			}
			if($('#ev_date').attr('value'))
			{
				ev_date = $('#ev_date').attr('value');
			}
			else
			{
				alert($('#ev_date').attr('title'));
			}
			if($('#ev_time').attr('value'))
			{
				ev_time = $('#ev_time').attr('value');
			}
			else
			{
				alert($('#ev_time').attr('title'));
			}
		}
		else
		{
			alert($('#reserve_select').attr('title'));
			return false;
		}
		if($('#pay').attr('value'))
		{
			pay = $('#pay').attr('value');
		}
		else
		{
			alert($('#pay').attr('title'));
			return false;
		}
		if($('#name2').attr('value'))
		{
			name2 = $('#name2').attr('value');
		}
		else
		{
			alert($('#name2').attr('title'));
			return false;
		}
		if($('#name1').attr('value'))
		{
			name1 = $('#name1').attr('value');
		}
		else
		{
			alert($('#name1').attr('title'));
			return false;
		}
		if($('#tel').attr('value'))
		{
			tel = $('#tel').attr('value');
		}
		else
		{
			alert($('#tel').attr('title'));
			return false;
		}
		if($('#mail').attr('value'))
		{
			mail = $('#mail').attr('value');
		}
		else
		{
			alert($('#mail').attr('title'));
			return false;
		}
		comments = $('#comments').attr('value');
		$.post('/function/reserve/',{'name2':name2,'name1':name1,'tel':tel,'mail':mail,'pay':pay,'reserve_select':reserve_select,'comments':comments},function(data)
		{
			$('.window_close').click();
		});
	});
	//'room1':room1,'date_in1':date_in1,'date_out1':date_out1,'count_men1':count_men1,'room2':room2,'date_in2':date_in2,'date_out2':date_out2,'count_men2':count_men2,'garant':garant,'card_name':card_name,'card_n':card_n,'card_date':card_date,
	
	$('a.map').live('click',function()
	{
		$('div.window').css({'display':'block','opacity':'1.0'});
		$('div#hidden').stop().css({'display':'block','opacity':'0'}).animate({'opacity':'0.5'},400);
		$('div#loading').stop().css({'display':'block','opacity':'1'}).animate({'opacity':'1.0'},400);
		$.post('/module/location_map/',{},function(data)
		{
			$('#window').html(data);
			var width = $('div.window').width();
			var height = $('div.window').height();
			$('div#window').css({'width':(width-200)+'px','height':(height-200)+'px'});
			$('div#window').valign();
			$('div#loading').stop().animate({'opacity':'1.0'},400,function()
			{
				$(this).css({'display':'none'});
				$('div#window').stop().css({'display':'block','opacity':'0'}).animate({'opacity':'1.0'},400);
			});
			
		});
		return false;
	});
	
	$('a.open1').live('click',function()
	{
		var a_link = $(this).blur().attr('href').substr(4,$(this).blur().attr('href').length-4);
		$('#content').stop().animate({'opacity':'0'},400,function()
		{
			window.location.replace('#'+a_link);
			$.post('/page/'+a_link,{},function(data)
			{
				set_url();
				$('#content').html(data);
				$('#content').animate({'opacity':'1.0'},400);
			});
		});
		return false;
	});
	
	
	
	
	$('a.menu_link1,a.menu_top1').live('click',function()
	{
		if($(this).attr('href'))
		{
			var a_link = $(this).blur().attr('href').substr(4,$(this).blur().attr('href').length-4);
			$('#content').animate({'opacity':'0.0'},400,function()
			{
				window.location.replace('#'+a_link);
				$.post('/page/'+a_link,{},function(data)
				{
					set_url();
					$('#content').html(data);
					$('#content').animate({'opacity':'1.0'},400);
				});
			});
		}
		return false;
	});
	$('.r_menu a.sub').live('click',function()
	{
		if($(this).next().next().css('display') == 'none')
		{
			$(this).parent().children('div.sub').stop().slideUp(400);
			$(this).next().next().stop().slideDown(400);
		}
		else
		{
			$(this).parent().children('div.sub').stop().slideUp(400);
		}
		return false;
	});
	$('.r_menu a.sub_open1').live('click',function()
	{
		var a_link = $(this).blur().attr('href').substr(4,$(this).blur().attr('href').length-4);
		$(this).parent().parent().parent().stop().animate({'opacity':'0'},200,function()
		{
			$(this).hide();
			$('.razdel').stop().animate({'width':'0px'},400);
			$(this).parent().stop().animate({'width':'1500px'},400);
			$(this).parent().children('a.r_img').stop().animate({'width':'0px'},400,function()
			{
				$(this).hide();
				window.location.replace('#'+a_link);
				set_url();
				$.post('/page/'+a_link,{},function(data)
				{
					$('#content').html(data);
					$('#content').animate({'opacity':'1.0'},400);
				});
			});
			
		});
		return false;
	});
	$('.r_menu a.open_1').live('click',function()
	{
		var a_link = $(this).blur().attr('href').substr(4,$(this).blur().attr('href').length-4);
		$(this).parent().parent().parent().parent().stop().animate({'opacity':'0'},200,function()
		{
			$(this).hide();
			$('.razdel').stop().animate({'width':'0px'},400);
			$(this).parent().stop().animate({'width':'1500px'},400);
			$(this).parent().children('a.r_img').stop().animate({'width':'0px'},400,function()
			{
				$(this).hide();
				window.location.replace('#'+a_link);
				set_url();
				$.post('/page/'+a_link,{},function(data)
				{
					$('#content').html(data);
					$('#content').animate({'opacity':'1.0'},400);
				});
			});
			
		});
		return false;
	});
	$('a.l_open1,div.l_bottom a.left1,div.l_bottom a.right1').live('click',function()
	{
		var a_link = $(this).blur().attr('href').substr(4,$(this).blur().attr('href').length-4);
		window.location.replace('#'+a_link);
		set_url();
		$('div.list').stop().animate({'opacity':'0'},800,function()
		{
			$.post('/page/'+a_link,{},function(data)
			{
				$('div.img_show').stop().animate({'opacity':'0'},800,function()
				{
					$('#content').html(data);
					$('#content').animate({'opacity':'1'},400);
				});
			});
		});
		return false;
	});
	
	$('.razdel_close').live('click',function()
	{
		var ln = url0.split('/');
		window.location.replace('#'+ln[4]+'/');
		$('.razdel').stop().each(function(n,razdel)
		{
			var width = $(this).attr('width');
			$(this).children('span').stop().animate({'opacity':'0'},400,function()
			{
				$(this).parent().children('.r_img').stop().animate({'left':'0px'},800);
				$(this).parent().children('.r_img').children('.r_img_2').stop().animate({'opacity':'0'},800)
				$(this).parent().stop().animate({'width':width+'px'},800);
			});
		});
	});
	
	
	
	$('div.img_show img.thumb').live('click',function()
	{
		$('div.img_show img.thumb').css({'border':'3px #fff solid'});
		$(this).css({'border':'3px #555 solid'});
		set_img = this;
	});
	$('.img_del').live('click',function()
	{
		if($(set_img).attr('src'))
		{
			$.post('/function/edit/del/',{'url':$(set_img).attr('src')},function(data)
			{
				if(data == 1)
				{
					var str_url = '';
					var ln = url0.split('/');
					if(url1.length > 0)
					{
						str_url = url1;
					}
					else
					{
						for(n=4;n<ln.length;n++)
						{
							if(ln[n].length > 0) str_url = str_url + ln[n] +'/';
						}
					}
					a_link = str_url;
					window.location.href = '/'+ln[3]+'/'+a_link;
				}
				else
				{
					alert('Ошибка');
				}
			});
		}
		else alert('Выберите файл для удаления');
	});
	$('#file').live('change',function()
	{
		$('#img_form').attr({'action':'/function/edit/add/'});
		var str_url ='';
		if(url1.length > 0)
		{
			str_url = url1;
		}
		else
		{
			var ln = url0.split('/');
			for(n=4;n<ln.length;n++)
			{
				if(ln[n].length > 0) str_url = str_url + ln[n] +'/';
			}
		}
		$('#img_form #url').attr({'value':str_url});
		document.getElementById('img_form').submit();
	});
	$('.edit').live('click',function()
	{
		set_url();
		
		var str_url = '';
		if(url1.length > 0)
		{
			str_url = url1;
			$(this).attr({'href':'#'+url1});
			var ln = url1.split('/');
		}
		else
		{
			var ln = url0.split('/');
			for(n=3;n<ln.length;n++)
			{
				if(ln[n].length > 0) str_url = str_url + ln[n] +'/';
			}
		}
		var ln = str_url.split('/');
		if(ln.length > 3) a_link = str_url+'edit/';
		else a_link = str_url+'home/edit/';
		if(url1.length > 0) a_link = a_link;
		else a_link = '/'+a_link;
		window.location.replace(a_link);
		return false;
	});
	$('#add_link').live('click',function()
	{
		var href = $('#href').attr('value');
		var link = $('#link').attr('value');
		$(this).parent().next().append('<span class="href">'+ href +'</span><span class="link">'+ link +'</span><a class="del_link">Удалить</a><div class="line" style="height:0px;"></div>\n');
	});
	$('.del_link').live('click',function()
	{
		$(this).prev().remove();
		$(this).prev().remove();
		$(this).next().remove();
		$(this).remove();
	});
	$('.save').live('click',function()
	{
		var href = [];
		var link = [];
		var str_url = '';
		var ln = url0.split('/');
		for(n=4;n<ln.length;n++)
		{
			if(ln[n].length > 0) str_url = str_url + ln[n] +'/';
		}
		var title = $('#title').attr('value');
		var keywords = $('#keywords').attr('value');
		var description = $('#description').attr('value');
		var head = $('#head').attr('value');
		var str = $('textarea.l_center').attr('value');
		var booking = $('#booking').attr('value');
		var explorer = $('#explorer').attr('value');
		$('.href').each(function(n,element)
		{
			href[n] = $(this).text();
			link[n] = $(this).next().text();
		});
		
		$.post('/function/edit/text/',{'url':str_url,'title':title,'keywords':keywords,'description':description,'head':head,'str':str,'booking':booking,'explorer':explorer,'href':href,'link':link},function(data)
		{
			if(data == '11')
			{
				alert('Данные сохранены');
			}
			else
			{
				alert('Ошибка!')
			}
		});
	});
	
	$('.back').live('click',function()
	{
		var str_url = '';
		var ln = url0.split('/');
		for(n=4;n<ln.length-2;n++)
		{
			if(ln[n].length > 0) str_url = str_url + ln[n] +'/';
		}
		a_link = str_url;
		window.location.replace('/'+a_link);
		$.post('/page/'+a_link,{},function(data)
		{
			$('div.img_show').stop().animate({'opacity':'0'},800,function()
			{
				$('#content').html(data);
				$('#content').animate({'opacity':'1'},400);
			});
		});
	});
	
	$('#ru,#en').live('click',function()
	{
		if(url1.length > 0)
		{
			window.location.replace($(this).attr('href')+url1);
		}
		else
		{
			var str = '';
			var ln = url0.split('/');
			for(n=4;n<ln.length;n++)
			{
				if(ln[n].length > 0) str = str + ln[n] +'/';
			}
			window.location.replace($(this).attr('href')+str);
		}
		return false
	});
	
	$('#admin_save').live('click',function()
	{
		$.post('/function/panel/admin_save/',{'new_login':$('#new_login').attr('value'),'new_pas':$('#new_pas').attr('value'),'new_email':$('#new_email').attr('value')},function(data)
		{
			if(data == '1')
			{
				alert('Данные сохранены');
			}
			else
			{
				alert('Данные не сохранены');
			}
		});
	});
	$('#file_').live('change',function()
	{
		document.getElementById('file_form').submit();
	});
	$('#file_del').live('click',function()
	{
		var file_path = $('#file_path').attr('value');
		if(file_path.length)
		{
			$.post('/function/panel/file_del/',{'file_path':file_path},function(data)
			{
				$('#file_path').attr({'value':''});
				if(data == '1') window.location.replace(window.location.href);
				else alert('Файл не удалён');
			});
		}
		else
		{
			alert('Выберите файл из списка ниже для удаления');
		}
	});
	$('.file').live('click',function()
	{
		$('#file_path').attr({'value':'/file/'+$(this).html()});
	});
	
	
	
	
	
	
	
	
	
	
	
	
});



//general function
function init()
{
	jQuery.fn.extend(
	{
	    disableSelection:function()
		{
			this.each(function()
			{
				this.onselectstart = function() { return false; };
				this.unselectable = "on";
				jQuery(this).css('-moz-user-select', 'none');
			});
	    },
	    enableSelection:function()
		{
			this.each(function()
			{
				this.onselectstart = function(){};
				this.unselectable = "off";
				jQuery(this).css('-moz-user-select', 'auto');
			});
	    },
		
		onload:function(call)
		{
			var obj = this;
			obj.onload = function(){call};
			//obj.load(function(){call});
		},
		
		valign:function()
		{
			var valign_obj = this;
			var align_obj = $(valign_obj).parent();
			
			vertical_align(valign_obj,align_obj);
			function vertical_align(valign_obj,parent_obj)
			{alert($(valign_obj).height() +' '+ $(align_obj).height());
				if($(valign_obj).height() < $(align_obj).height())
				{
					top[valign_obj] = (($(align_obj).height() - $(valign_obj).height())/2) + 'px';
					$(valign_obj).css({'top':top[valign_obj]});
				}
				else
				{
					$(valign_obj).css({'top':'0px'});
				}
			}
		}
		
	});
	
	if(flashversion >= 10 || ie)
	{
		var urlHTML = '';
		var ln = url0.split('/');
		if(ln[4] == 'panel') $('#html').show();
		else if(ln[ln.length-1] == 'edit' || ln[ln.length-2] == 'edit') $('#html').show(); 
		else $('#swf').show();
		//$('#html').show();
		if(ln[3] == 'ru' || ln[3] == 'en')
		{
			for(lns in ln)
			{
				if(lns > 2 && ln[lns].length > 0) urlHTML += '/'+ ln[lns];
			}
		}
		else urlHTML = '/ru';
		urlHTML += '/';
		if(ie)
		{
			//$('#swf_in').html('');
		}
		else
		{
			var flashvars = {'urlHTML':urlHTML,'timeHTML':date,'bg_ie_enter':true};
			var params = {};
			var attributes = {quality:'high',bgcolor:'#283629',loop:'false',menu:'false',allowScriptAccess:'sameDomain',wmode:'opaque'};
			swfobject.embedSWF('/pages/site.swf?urlHTML='+ urlHTML +'&timeHTML='+ date +'&bg_ie_enter=true', 'swf_in', '960', '620', '9.0.0', '/pages/expressInstall.swf', flashvars, params, attributes);
		}
		//resize();
	}
	else
	{
		$('#html').show();
		//resize();
	}
	
	$('opacity').css({'opacity':'0.8'});
	$('.menu_down').css({'height':'0px','opacity':'0'}).hide();
	
	$('#weather').html('<img class="line_v" src="/img/line_v.png" style="margin-top:13px;"><img class="pre" src="/img/p1.png" style="width:20px; margin:15px 10px 0px 30px;"><span></span>');
	$.post('/module/weather/',{},function(data)
	{
		if(data.substr(0,4) == "<img") $('#weather').html(data);
		else $('#weather span').html(text_weather);
		
		$('#time').html('<img class="line_v" src="/img/line_v.png" style="margin-top:13px;"><img class="pre" src="/img/clock.png" style="width:20px; margin:15px 30px 0px 10px;"><span></span>');
		setInterval(function()
		{
			date_ = date.split(':');
			var h = date_[0];
			var m = date_[1];
			var s = 0;
			
			var date_new = new Date();
			var h_new = date_new.getHours() +'';
			var m_new = date_new.getMinutes() +'';
			var s_new = date_new.getSeconds() +'';
			
			var h_old = date_old.getHours() +'';
			var m_old = date_old.getMinutes() +'';
			date_old = date_new;
			
			s = s_new;
			if(m_new != m_old)
			{
				if(++m == 60)
				{
					m = '00';
					if(++h == 24)
					{
						h == '00';
					}
				}
			}
			
			date = h +':'+ m;
			h_ = (1*h+6)-24;
			if(h_ < 0)
			{
				h = 1*h+6;
			}
			else
			{
				h = h_;
			}
			if(h.length == 1) h = '0'+h;
			if(m.length == 1) m = '0'+m;
			if(s.length == 1) s = '0'+s;
			$('#time span').html(text_time +' '+ h +':'+ m +':'+ s);
		},300);
	});
}

function reserve(reserv)
{
	
	
	var win = new window('/pages/reserve/','reserve');
	
	/*
	$('div.window').css({'display':'block','opacity':'1'});
	$('div#window').css({'display':'block','opacity':'0'});
	$('div#hidden').stop().css({'display':'block','opacity':'0'}).animate({'opacity':'0.7'},400);
	$('div#loading').stop().css({'display':'block','opacity':'1'}).animate({'opacity':'1.0'},400);
	$.post('/module/reserve/',{'value':reserv},function(data)
	{
		$('#window').html(data);
		var left = ($('div.window').width()-$('div#window').width())/2;
		var top = ($('div.window').height()-$('div#window').height())/2;
		if(left < 0) left = 0;
		if(top < 0) top = 0;
		$('#window').css({'top':top +'px','left':left +'px'});
		$('div#loading').stop().animate({'opacity':'1.0'},400,function()
		{
			$(this).css({'display':'none'});
			$('div#window').stop().css({'opacity':'0'}).show().animate({'opacity':'1.0'},400);
		});
	});
	*/
}

function resize()
{
	$('#body').css({'height':'100%'});
	$('#body').css({'width':'100%'});
	if(document.getElementById('body').offsetHeight < document.getElementById('site').offsetHeight)
	{
		$('#body').css({'height':document.getElementById('site').offsetHeight+'px'});
	}
	if(document.getElementById('body').offsetWidth < document.getElementById('site').offsetWidth)
	{
		$('#body').css({'width':document.getElementById('site').offsetWidth+'px'});
	}
}

function loading()
{
	var pics = get_load();
	set_load(0,0);
}
function get_load()
{
	var k = 0;
	$('.pre').each(function(n,img)
	{
		pre[n] = img;
		$(img).removeClass('pre');
		k++;
	});
	return k;
}
function set_load(pics,error)
{
	if(pics<50)
	{
		var src = $(pre[pics]).attr('src');
		$(pre[pics]).attr({'src':'/img/bga.png'});
		//может быть просчёт и анимация загрузки
		loading_timer[pics] = window.setTimeout(function()
		{
			
			error++;
			if(error > 3)
			{
				end_load();
			}
			else
			{
				if(pre[pics])
				{
					delete pre[pics];
					pics++;
					set_load(pics,error);
				}
				else if(pre.length == pics) end_load();
			}
		},3000);
		$(pre[pics]).attr({'src':src}).load(function()
		{
			clearTimeout(loading_timer[pics]);
			
			if(pre[pics])
			{
				delete pre[pics];
				pics++;
				set_load(pics,error);
			}
			else if(pre.length == pics) end_load();
		});
	}
	else
	{
		end_load();
	}
}
function end_load()
{
	//анимация загрузки в исходное положение
	if(!loading_)
	{
		$('div.window').stop().animate({'opacity':'0'},400,function()
		{
			$(this).css({'display':'none'});
			$('#loading').css({'display':'none'});
			if($('div#site').css('display') != 'block')
			{
				$('img#bg').css({'display':'block'});
				$('img#bg_line').css({'display':'block'});
				$('div#site').css({'display':'block'});
				show_page();
				var ln = url0.split('/');
				if(ln[4] == 'visiting')
				{
					//show_razdel();
				}
				else
				{
					//show_page();
				}
				loading_ = 1;
			}
			//resize();
		});
	}
	else
	{
		//загрузка контента с анимацией
	}
}

function file()
{
	$.post('/module/file/',{},function(data)
	{
		
	});
}
