$(document).ready(function(){

	$('.cansw').click(function() {
		$("#feed_"+$(this).attr('id')).insertAfter($(this).parent());
		$('.cansw').fadeIn();
	
		$("#feed_"+$(this).attr('id')).find('input[name="parent_id"]').val($(this).parent().parent().parent().attr('cid'));
		
		$(this).fadeOut();
		return false;
		
		
	});

	$('.comments input[name="name"]').focus(function()
	{
		$(this).css('border','1px solid #cccccc');
		$("#name_fld").text('*');
	});
	$('.comments input[name="email"]').focus(function()
	{
		$(this).css('border','1px solid #cccccc');
		$("#email_fld").text('*');
	});
	$('.comments input[name="captcha"]').focus(function()
	{
		$(this).css('border','1px solid #cccccc');
		$("#captcha_fld").text('*');
	});
	
	
	$('.tab_add_review input[name="name"]').focus(function()
	{
		$(this).css('border','1px solid #999999');
		$("#name_fld").text('*');
	});
	$('.tab_add_review input[name="email"]').focus(function()
	{
		$(this).css('border','1px solid #999999');
		$("#email_fld").text('*');
	});
	$('.tab_add_review input[name="captcha"]').focus(function()
	{
		$(this).css('border','1px solid #999999');
		$("#captcha_fld").text('*');
	});
	
	$('div.inabout').each(function() {
		$(this).data('height',$(this).height());
		$(this).height(127);
	});
	
	$('.showmoreabout').click(function() {
	
		var ina = $(this).parents('div.about').find('div.inabout');
		var href = this;
		
		if (ina.height() == 127)
		{
			ina.animate({"height": ina.data('height')},500,function () {$(href).text('Свернуть...')});
		}
		else
		{
			ina.animate({"height": "127px"},300,function () {$(href).text('Подробнее...')});
		}
		return false;
	});
	
	
	
	$('#search_submit').click(function() {
		$('form[name="search"]').submit();			
	});
	
	$('a.tohide').click(function() {
		$('.hider').slideToggle();
		if ($(this).text() == 'Свернуть')
		{
			$(this).text('Все авторы');
		}
		else
		{
			$(this).text('Свернуть');
		}
		 
		return false;
		
	});
	

	
	$("#hotelnums").mouseenter(function()
	{
		$('#insidehotelnums').fadeIn("fast");
		
	}).mouseleave(function()
	{
		$('#insidehotelnums').fadeOut("fast");
	});
	
	$('a.maptrigget').click(function () {
		
		var c = new Array();
		var z = new Array();
		for (i = 0; i < gmaps.length; i++)
		{
			c[i] = gmaps[i].getCenter();
			z[i] = gmaps[i].getZoom();
		}
		
		$('div.hotelmap[id=G_'+$(this).attr('id')+']').slideToggle(function() {	});
		
		
		for (i = 0; i < gmaps.length; i++)
		{
			google.maps.event.trigger(gmaps[i], 'resize');
			gmaps[i].setCenter(c[i]);
			gmaps[i].setZoom(z[i]);
		}
			
		if ($(this).text() == 'Показать на карте')
		{
			$(this).text('Скрыть карту');
		}
		else
		{
			$(this).text('Показать на карте');
		}
		return false;
	});
	
	$('#but_calen_block').outerClick(function() {

		$(this).hide();
	});
	
	$('a.showcomments').click(function() {
		$("#a"+$(this).attr('id')).slideToggle();
		if ($(this).text() == 'Комментировать')
		{
			$(this).text('Скрыть комментирование');
		}
		else
		{
			$(this).text('Комментировать');
		}
		
		return false;
		
	});
	
	$('a.showcommentslist').click(function() {
		$("#a"+$(this).attr('id')).slideToggle();
		if ($(this).text() == 'Скрыть комментарии')
		{
			
			$(this).text($(this).data('txt'));
		}
		else
		{
			$(this).data('txt',$(this).text());
			$(this).text('Скрыть комментарии');
		}
		
		return false;
		
	});
	
	$('a.review_yes').click(function() {
		reviewrate(this,1);
		return false;
	});
	
	$('a.review_no').click(function() {
		reviewrate(this,-1);
		return false;
	});
	
	$('ul.main_menu > li > a').hover(function() {
		$(this).parent().find('div.main_submenu').fadeIn('fast');
	});
	
	$('ul.main_menu > li > div.main_submenu').mouseleave(function () {
		$(this).fadeOut('fast');
	});
	
	$('ul.main_menu > li > div.main_submenu .msm_closer').mouseenter(function () {
		$(this).parent().parent().fadeOut('fast');
	});
	
	$('.broneform .gobutton').click(function() {
		var fparams = {
			hotel: $('#brone_sel').val(),
			persons: $('#bf_persons').val(),
			datein: $('#bf_datein').val(),
			dateout: $('#bf_dateout').val()
		};
		openform(fparams);
		
	});
	
	$('.backcall').click(function() {
		recall();
		return false;
	});
	
		
	$('a.bossmail').click(function() {
		bossmail();
		return false;
	});
	
	
	$('div.sideblock div.authors a.other').click(function() {
		$('div.sideblock div.authors div.otherauthors').slideToggle(600);
		return false;
	});
	
	
	
	$('.testimonial .comm, .testimonial .plus, .testimonial .minus').each(function() {
		if (parseInt($(this).height()) > 68)
		{
			$(this).height(68);
			$(this).css('overflow','hidden');
			$(this).after('<a href="#" style="text-decoration: none; border-bottom: 1px dashed #3366cc;position: relative; top: -8px;" onclick="if ($(this).text() == \'Развернуть\') {$(this).prev().height(\'auto\');$(this).text(\'Свернуть\');}else{$(this).prev().height(68);$(this).text(\'Развернуть\');}  return false;">Развернуть</a>');
		}
	});
	
	
	$('div.way_tabs div.way_tab a').click(function() {
		$('div.way_tabs div.way_tab.cur').removeClass('cur');
		$(this).parent().addClass('cur');
		
		$('div.way_blocks div.block').hide();
		$('#box'+$(this).attr('id')).show();
		return false;
	});
	
	scroll_max_count = $('.image_carousel > div > div.image_carousel_holder').length;
	
	
	addcss();

	
});

function roomload(that) 
{
	ajaloadroom($(that).val(),false)
}

function ajaloadroom(hotel_id, room_id)
{

	$.post("/ajax_hotelrooms/",
	{
		hid: hotel_id
	}, 

	function(data) {
	
		if (data.result == 'ok')
		{
			var coms = '';
			if (room_id == false)
			{
				  coms = '<span val="0" class="cuselActive">Любой номер</span>';
			}
			else
			{
				  coms = '<span val="0">Любой номер</span>';
			}
			$("brone_room_sel").val("0");
			var selac = 'Любой номер';
			for (var key in data.hotels) 
			{	
				if (parseInt(room_id) == parseInt(data.hotels[key].id))
				{
					coms = coms+'<span val="'+data.hotels[key].id+'" class="cuselActive" >'+data.hotels[key].name+'</span>';	
					selac = data.hotels[key].name;
					$("brone_room_sel").val(data.hotels[key].id);
				}
				else
				{
					coms = coms+'<span val="'+data.hotels[key].id+'">'+data.hotels[key].name+'</span>';	
				}
			
			}		

					
			 $("#cuselFrame-brone_room_sel .cuselText").text(selac);
			 
			
			$("#cusel-scroll-brone_room_sel").html(coms);
			
			var params = {
				refreshEl: "#brone_room_sel",
				visRows: 6
			}
			cuSelRefresh(params);
		}
	}, 'json');

}


function openform(fparams)
{

	if ($('#bb_brone').length == 0)
	{
		appender_gal = '<div class="big_black" id="bb_brone" style="display:none;"></div><div class="up_black" id="ub_brone" style="display:none;">'+
		'<div class="formbom">'+
		'<div class="holes"></div>'+
		'<div class="closeb">Закрыть окно</div>'+
		'<input type="text" id="dsin" class="dateb fl1 imp">'+
		'<input type="text" id="dsout" class="dateb fl2 imp">'+
		'<input type="text" id="dstime" class="timeb fl3 imp" value="12:00">'+
		'<input type="text" id="dpersons" class="dlyab fl4 imp">'+
		'<input type="text" id="dsphone" class="phoneb fl5 imp">'+
		'<input type="text" id="dsemail" class="emailb fl6 imp">'+
		'<input type="text" id="dsname" class="nameb fl7 imp">'+
		'<input type="text" id="dssername" class="sernameb fl8 imp">'+	
		
		'<div class="hotel_place">'+
		'<select name="hotele" id="brone_full_sel"  onChange="roomload(this);">'+				
		'</select>'+	
		'</div>'+
		
		'<div class="room_place">'+
		'<select name="hotele" id="brone_room_sel">'+		
		'<option value="0">Выберите номер</option>'+		
		'</select>'+	
		'</div>'+
		
		'<textarea id="comment" class="flta"></textarea>'+
		'<input type="checkbox" id="dscheckform" class="checkform fl9 imp">'+	
		'<a href="/rules/" class="ruleshref" target="_blank"></a>'+
		'<div class="flneed" id="flneed">Необходимо ознакомиться и согласиться с правилами проживания.</div>'+
		
		'<div class="flashformsubmin" id="flashformsubmin"></div>'+
		'</div>'+	
		'<div class="afterformbone"><img src="/public/images/design/afterform.jpg" alt="" border="" style="padding: 6px;"></div>'+
		'</div>';		
		
				
	
		$("body").append(appender_gal);
		
		$("#dsin").datePicker({clickInput:true});				
		$("#dsout").datePicker({clickInput:true});	
		
		
		$("#flashformsubmin").click(function() {
			var err = false;
			if( $('#dsphone').val().length < 5)
			{
				$('#dsphone').addClass('errfld');
				err = true;
			}
			if( $('#dsemail').val().length < 4)
			{
				$('#dsemail').addClass('errfld');
				err = true;
			}
			if( $('#dsname').val().length < 2)
			{
				$('#dsname').addClass('errfld');
				err = true;
			}			
			
				
			if ($('#dscheckform').attr('checked') != 'checked')
			{
			
				$('#flneed').fadeIn();
				err = true;
			}
			
			if (!err)
			{
				
				$.post("/ajax_sendform/",
				{
					hotel_id: $('#brone_full_sel').val(),
					room_id: $('#brone_room_sel').val(),
					date_in: $('#dsin').val(),
					time_in: $('#dstime').val(),
					date_out: $('#dsout').val(),
					persons: $('#dpersons').val(),
					name: $('#dsname').val(),
					sername: $('#dssername').val(),
					comment: $('#comment').val(),
					phone: $('#dsphone').val(),
					email: $('#dsemail').val()
				}, 

				function(data) {
					
					if (data.result == 'ok')
					{
						$(".formbom").fadeOut();
						$(".afterformbone").fadeIn(200).delay(1500).fadeIn(200, function() {
						
							$("#bb_brone").fadeOut(200);
							$('#ub_brone').fadeOut(200,function () {					
								$(".videobox").css("visibility","visible");
								$(".afterformbone").hide();
							});
							
							
							$("body").css('overflow-y','scroll');
							$("#ub_call").css('overflow-y','hidden');
						});
					}
			
				},
				'json');
			}
		});
		
		$('#dsphone').focus(function() {
			$(this).removeClass('errfld');
		});
		$('#dsemail').focus(function() {
			$(this).removeClass('errfld');
		});
		$('#dsname').focus(function() {
			$(this).removeClass('errfld');
		});
		
		$('#dscheckform').click(function() {
			$('#flneed').fadeOut();
		});
		
		var  coms = '<option value="0">Любой отель</option>';
		$('#allhotels div').each(function () {
			
			coms = coms+'<option value="'+$(this).attr('hid')+'" >'+$(this).text()+'</option>';
		});
		
		
		$('#brone_full_sel').html(coms);
		
		$("#bb_brone").click(function() {
			$(".big_black").fadeOut(200);
			
			$("body").css('overflow-y','scroll');
			$("#ub_brone").css('overflow-y','hidden');
		
			$('#ub_brone').fadeOut(200,function () {					
				$(".videobox").css("visibility","visible");
			});
		});
		
		$(".formbom .closeb").click(function() {
			$(".big_black").fadeOut(200);
			
			$("body").css('overflow-y','scroll');
			$("#ub_brone").css('overflow-y','hidden');
			
			$('#ub_brone').fadeOut(200,function () {					
				$(".videobox").css("visibility","visible");
			});
		});
		
		var params = {
			changedEl: "#brone_full_sel",
			visRows: 6,
			scrollArrows: false
		};
		cuSel(params);
		
			var params = {
			changedEl: "#brone_room_sel",
			visRows: 6,
			scrollArrows: false
		};
		cuSel(params);
		
	}

	
	$("body").css('overflow-y','hidden');
	$("#ub_brone").css('overflow-y','scroll');
	$(".formbom").show();
	
	
	if(typeof fparams['persons'] !== "undefined") 
	{
		$('#dpersons').val(fparams['persons']);
	}
	if(typeof fparams['datein'] !== "undefined") 
	{
		$('#dsin').val(fparams['datein']);
	}
	if(typeof fparams['dateout'] !== "undefined") 
	{
		$('#dsout').val(fparams['dateout']);
	}

	
	
	if(typeof fparams['hotel'] !== "undefined") 
	{

		var cu = $('#cuselFrame-brone_full_sel span[val="'+fparams['hotel']+'"]');	
			
		$("#cuselFrame-brone_full_sel .cuselText").text(cu.text());
		$("#cuselFrame-brone_full_sel span").removeClass('cuselActive');
		$("#brone_full_sel").val(fparams['hotel']);
		cu.addClass('cuselActive');
					
		var params = {
			refreshEl: "#brone_full_sel",
			visRows: 6
		}
		cuSelRefresh(params);
		ajaloadroom(fparams['hotel'],fparams['room']);
		
	}
	
	
	$("#ub_brone").fadeIn(200);
	$("#bb_brone").fadeTo(200,0.90);
	$(".videobox").css("visibility","hidden");
	
	var ubel = $("#ub_brone");
	var allwidths = ubel.width();				
	var allheigths = ubel.height();	
	
	var lefts = (allwidths - parseInt($('.formbom').width())) / 2;
	var tops = (allheigths - parseInt($('.formbom').height())) / 2;
	
	if (tops < 0 ) tops = 10;
										
	$(".formbom").css("top",tops).css("left",lefts);
	
	var flefts = (allwidths - parseInt($('.afterformbone').width())) / 2;
	var ftops = (allheigths - parseInt($('.afterformbone').height())) / 2;
	
	$(".afterformbone").css("top",ftops).css("left",flefts);

}





function recall()
{

	if ($('#bb_call').length == 0)
	{
	
		var d = new Date();
		var day = d.getDate();
		var month = d.getMonth() + 1;
		var year = d.getFullYear();


		appender_gal = '<div class="big_black" id="bb_call" style="display:none;"></div><div class="up_black" id="ub_call" style="display:none;">'+
		'<div class="formcal">'+
		
		'<div class="closeb">Закрыть окно</div>'+

		'<div class="fzak">Заказать звонок</div>'+
		
		'<div class="fzname">Имя</div>'+
		'<div class="fzphone">Телефон</div>'+
		'<div class="fzdarerime">Дата и время звонка</div>'+
		'<div class="fzcomment">Комментарий</div>'+
		


		'<input type="text" id="datetocall" class="dateb imp" value="'+day + "." + month + "." + year+'">'+
		
		
		'<input type="text" id="callname" class="fziname imp">'+		
		'<input type="text" id="callphone" class="fziphone imp">'+
		'<textarea id="comment" class="fzta"></textarea>'+
		
		'<div class="tosend" id="sendcallb"></div>'+
		
		'<div class="ftime">'+
		'<select name="hotele" id="call_time_sel" style="width: 100px;">'+		
		'</select>'+	
		'</div>'+
		'</div>'+ 
		'<div class="afterformcal"><img src="/public/images/design/callsend.jpg" alt="" border="" style="padding: 6px;"></div>'+
		'</div>';		
		
				
	
		$("body").append(appender_gal);
		
		
		$("#datetocall").datePicker({clickInput:true});	
		
		
		$("#sendcallb").click(function() {
			var err = false;
			
			if( $('#callphone').val().length < 5)
			{
				$('#callphone').addClass('errfld');
				err = true;
			}
			if( $('#callname').val().length < 2)
			{
				$('#callname').addClass('errfld');
				err = true;
			}
			
			
			if (!err)
			{
				
				$.post("/ajax_sendcall/",
				{
					
					phone: $('#callphone').val(),
					date_in: $('#datetocall').val(),
					time_in: $('#call_time_sel').val(),
					comment: $('#comment').val(),
					name: $('#callname').val()
				}, 

				function(data) {
					
					if (data.result == 'ok')
					{
						$(".formcal").fadeOut();
						$(".afterformcal").fadeIn(200).delay(1500).fadeIn(200, function() {
						
							$("#bb_call").fadeOut(200);
							$('#ub_call').fadeOut(200,function () {					
								$(".videobox").css("visibility","visible");
								$(".afterformcal").hide();
							});
							
							
							$("body").css('overflow-y','scroll');
							$("#ub_call").css('overflow-y','hidden');
						});
						
					}
			
				},
				'json');
			}
		});
		
		$('#callphone').focus(function() {
			$(this).removeClass('errfld');
		});
		$('#callname').focus(function() {
			$(this).removeClass('errfld');
		});
		
		var  coms = '<option value="0">Любое время</option>';
		coms = coms+'<option value="9ч - 12ч" >9ч - 12ч</option>';
		coms = coms+'<option value="12ч - 15ч" >12ч - 15ч</option>';
		coms = coms+'<option value="15ч - 17ч" >15ч - 17ч</option>';
		coms = coms+'<option value="17ч - 20ч" >17ч - 20ч</option>';
		
		
		
		$('#call_time_sel').html(coms);
		
		$("#bb_call").click(function() {
			$("#bb_call").fadeOut(200);
			
			$("body").css('overflow-y','scroll');
			$("#ub_call").css('overflow-y','hidden');
		
			$('#ub_call').fadeOut(200,function () {					
				$(".videobox").css("visibility","visible"); 
			});
		});
		
		$(".formcal .closeb").click(function() {
			$("#bb_call").fadeOut(200);
			
			$("body").css('overflow-y','scroll');
			$("#ub_call").css('overflow-y','hidden');
			
			$('#ub_call').fadeOut(200,function () {					
				$(".videobox").css("visibility","visible");
			});
		});
		
		var params = {
			changedEl: "#call_time_sel",
			visRows: 6,
			scrollArrows: false
		};
		cuSel(params);
		

		
	}

	
	$("body").css('overflow-y','hidden');
	$("#ub_call").css('overflow-y','scroll');
	$(".formcal").show();
	
	
	
	
	
	
	$("#ub_call").fadeIn(200);
	$("#bb_call").fadeTo(200,0.90);
	$(".videobox").css("visibility","hidden");
	
	var ubel = $("#ub_call");
	var allwidths = ubel.width();				
	var allheigths = ubel.height();	
	
	var lefts = (allwidths - parseInt($('.formcal').width())) / 2;
	var tops = (allheigths - parseInt($('.formcal').height())) / 2;
	
	if (tops < 0 ) tops = 10;
										
	$(".formcal").css("top",tops).css("left",lefts);
	
	var flefts = (allwidths - parseInt($('.afterformcal').width())) / 2;
	var ftops = (allheigths - parseInt($('.afterformcal').height())) / 2;
	
	$(".afterformcal").css("top",ftops).css("left",flefts);

}




function bossmail()
{

	if ($('#bb_boss').length == 0)
	{
	


		appender_gal = '<div class="big_black" id="bb_boss" style="display:none;"></div><div class="up_black" id="ub_boss" style="display:none;">'+
		'<div class="formboss">'+
		
		'<div class="closeb">Закрыть окно</div>'+

		'<div class="fbak">Письмо директору</div>'+
		
		'<div class="fbname">Имя</div>'+
		'<div class="fbemail">email</div>'+
		'<div class="fbcomment">вотсап?</div>'+
		


				
		'<input type="text" id="bossname" class="fbiname imp">'+		
		'<input type="text" id="bossemail" class="fbiemail imp">'+
		'<textarea id="commentboss" class="fbta"></textarea>'+
		
		'<div class="tosend" id="sendbossb"></div>'+
		
		'<div class="textos"><p>Демонстрируя редкий для недорогих отелей Петербурга пример открытости, "Друзья" предлагают вам написать все, что вы о нас думаете. И не просто написать "в никуда", а отправить непосредственно нашему генеральному директору - Сергею Владимировичу! </p>' +
		'<p>Обещаем вовсю стараться быть для вас самыми лучшими хостелами Петербурга, чтобы в расположенную чуть выше форму вы могли написать только хорошее. </p>' +
		'<p>А если мы натворили чего - пишите и об этом. Получим по шапке, чтобы не повадно было! :) </p></div>'+
		
		'</div>'+ 
		'<div class="afterformboss"><img src="/public/images/design/afterboss.jpg" alt="" border="" style="padding: 10px 0px 0px 130px;"></div>'+
		'</div>';		
		
				
	
		$("body").append(appender_gal);
		
		
		
		$("#sendbossb").click(function() {
			var err = false;
			
			if( $('#bossemail').val().length < 5)
			{
				$('#bossemail').addClass('errfld');
				err = true;
			}
			if( $('#bossname').val().length < 2)
			{
				$('#bossname').addClass('errfld');
				err = true;
			}
			
			
			if (!err)
			{
				
				$.post("/ajax_sendboss/",
				{
					
					name: $('#bossname').val(),
					email: $('#bossemail').val(),
					
					comment: $('#commentboss').val()
				}, 

				function(data) {
					
					if (data.result == 'ok')
					{
						$(".formboss").fadeOut();
						$(".afterformboss").fadeIn(200).delay(1500).fadeIn(200, function() {
						
							$("#bb_boss").fadeOut(200);
							$('#ub_boss').fadeOut(200,function () {					
								$(".videobox").css("visibility","visible");
								$(".afterformboss").hide();
							});
							
							$("body").css('overflow-y','scroll');
							$("#ub_boss").css('overflow-y','hidden');
			
						});
						
					}
			
				},
				'json');
			}
		});
		
		$('#bossemail').focus(function() {
			$(this).removeClass('errfld');
		});
		$('#bossname').focus(function() {
			$(this).removeClass('errfld');
		});
		
	
		
		$("#bb_boss").click(function() {
			$("#bb_boss").fadeOut(200);
			
			$("body").css('overflow-y','scroll');
			$("#ub_boss").css('overflow-y','hidden');
		
			$('#ub_boss').fadeOut(200,function () {					
				$(".videobox").css("visibility","visible"); 
			});
		});
		
		$(".formboss .closeb").click(function() {
			$("#bb_boss").fadeOut(200);
			
			$("body").css('overflow-y','scroll');
			$("#ub_boss").css('overflow-y','hidden');
			
			$('#ub_boss').fadeOut(200,function () {					
				$(".videobox").css("visibility","visible");
			});
		});
		
				
	}

	
	$("body").css('overflow-y','hidden');
	$("#ub_boss").css('overflow-y','scroll');
	$(".formboss").show();
	
	
	
	
	
	
	$("#ub_boss").fadeIn(200);
	$("#bb_boss").fadeTo(200,0.90);
	$(".videobox").css("visibility","hidden");
	
	var ubel = $("#ub_boss");
	var allwidths = ubel.width();				
	var allheigths = ubel.height();	
	
	var lefts = (allwidths - parseInt($('.formboss').width())) / 2;
	var tops = (allheigths - parseInt($('.formboss').height())) / 2;
	
	if (tops < 0 ) tops = 10;
										
	$(".formboss").css("top",tops).css("left",lefts);
	
	var flefts = (allwidths - parseInt($('.afterformboss').width())) / 2;
	var ftops = (allheigths - parseInt($('.afterformboss').height())) / 2;
	
	$(".afterformboss").css("top",ftops).css("left",flefts);

}



function locationbig(image)
{
	if ($('#bb_biggal').length == 0)
	{
		appender_gal = '<div class="big_black" id="bb_biggal" style="display:none;"></div><div class="up_black" id="ub_biggal" style="display:none;">'+
		'<div class="formbigloc">'+
		
		'<div class="closeb">Закрыть окно</div>'+
		'<div><img src="'+image+'"></div>'+
		
		'</div>'+ 
		
		'</div>';		
				
				
	
		$("body").append(appender_gal);
		
		
		
		$("#ub_biggal").click(function() {
			$("#bb_biggal").fadeOut(200);
			
			$("body").css('overflow-y','scroll');
			$("#ub_biggal").css('overflow-y','hidden');
		
			$('#ub_biggal').fadeOut(200,function () {					
				$(".videobox").css("visibility","visible"); 
			});
		});
		
		$(".formbigloc .closeb").click(function() {
			$("#bb_biggal").fadeOut(200);
			
			$("body").css('overflow-y','scroll');
			$("#ub_biggal").css('overflow-y','hidden');
			
			$('#ub_biggal').fadeOut(200,function () {					
				$(".videobox").css("visibility","visible");
			});
		});
	}

	
	
	
	$("body").css('overflow-y','hidden');
	$("#ub_biggal").css('overflow-y','scroll');
	$(".formbigloc").show();
	
	
	
	$("#ub_biggal").fadeIn(200);
	$("#bb_biggal").fadeTo(200,0.90);
	$(".videobox").css("visibility","hidden");
	
	var ubel = $("#ub_biggal");
	var allwidths = ubel.width();				
	var allheigths = ubel.height();	
	
	var lefts = (allwidths - parseInt($('.formbigloc').width())) / 2;
	var tops = (allheigths - parseInt($('.formbigloc').height())) / 2;
	
	$("#ub_biggal .formbigloc img").attr('src',image);
	
	var hehe = $("#ub_biggal .formbigloc img").height();
	$("#ub_biggal .formbigloc img").css('margin-top', ($('.formbigloc').height() - hehe) /2);

	
	if (tops < 0 ) tops = 10;
										
	$(".formbigloc").css("top",tops).css("left",lefts);
}


function checkcom(e)
{	

	$.post("/commentchek/",
			{
				name: $(e).find('input[name="name"]').val(),
				email: $(e).find('input[name="email"]').val(),
				captcha: $(e).find('input[name="captcha"]').val()
			}, 
		
			function(data) {
				if (data.result == 'ok')
				{
					e.submit();
				}
				else
				{
					if (data.email_err)
					{
						$(e).find('input[name="email"]').css('border','1px solid #cc0000');
						$(e).find("#email_fld").text('Неверный email');
						
					}
					else
					{
						$(e).find('input[name="email"]').css('border','1px solid #cccccc');
					}
					
					if (data.name_len_err)
					{
						$(e).find('input[name="name"]').css('border','1px solid #cc0000');
						$(e).find("#name_fld").text('Не введено имя');
					}
					else
					{
						$(e).find('input[name="name"]').css('border','1px solid #cccccc');
					}
					if (data.captcha_err)
					{
						$(e).find('input[name="captcha"]').css('border','1px solid #cc0000');
						$(e).find("#captcha_fld").text('Неверный код с картинки');
					}
					else
					{
						$(e).find('input[name="captcha"]').css('border','1px solid #cccccc');
					}
				}
			}
		,"json"); 
	return false;
}




function reviewrate(e,mark)
{	
	$.post("/reviewrate/",
			{ 
				id: $(e).attr('name'),
				mark: mark
			}, 
		
			function(data) {
				if (data.result == 'ok')
				{
					$(e).parent().text('Спасибо, Ваш голос учтен.');	
				}
				else
				{
					if (data.session_error)
					{
						$(e).parent().text('Вы уже голосовали');		
					}					
				}
			}
		,"json");
	return false;
}

function showday(item)
{

	var day = $(item).attr('id');
	$('#but_calen_block .addinline').html(
			$('#cd_'+day).html()
	);	

	if ($('#but_calen_block').data('day') != day)
	{
		$('#but_calen_block').fadeIn(300).offset({top:$(item).offset().top+16}).css('left','10px');
		$('#but_calen_block').data('day',day);
		$('#but_calen_block .addtop').html('События:');
		return false;
	}
	else
	{
		return true;
	}
}



function movecalen(year,month)
{
	if (month<1)
	{
		month = 12;
		year = year-1;
	}
	if (month>12)
	{
		month = 1;
		year = year+1;
	}
	
	$('#calendarbox').load('/event/calendar/'+year+'/'+month+'/');
	
}


function nl2br(str, is_xhtml){
	var breakTag = '';
	breakTag = '<br />';
	if (typeof is_xhtml != 'undefined' && !is_xhtml) {
		breakTag = '<br>';
	}
	return (str + '').replace(/([^>]?)\n/g, '$1'+ breakTag +'\n');
}
   
function dontsel(e) { 
    e.onselectstart = function() { return false; }; 
    e.unselectable = "on"; 
    $(e).css('-moz-user-select', 'none').css('-khtml-user-select', 'none').css('user-select', 'auto'); 
};

function doselet(e) { 
    e.onselectstart = function() {}; 
    e.unselectable = "off"; 
    $(e).css('-moz-user-select', 'auto').css('-khtml-user-select', 'auto').css('user-select', 'auto'); 
};


// small gallery //

$(document).ready(function(){
	$("div.in_h_accord").data('inmotion',false);

	$('div.h_navig div.but_r').mouseenter(function() {
		$(this).css("background-position", "-30px 50%");
	});
	
	$('div.h_navig div.but_r').mouseleave(function() {
		$(this).css("background-position", "-10px 50%");
	});
	
	$('div.h_navig div.but_l').mouseenter(function() {
		$(this).css("background-position", "-20px 50%");
	});
	
	$('div.h_navig div.but_l').mouseleave(function() {
		$(this).css("background-position", "0px 50%");
	});
	
	
	$('div.h_navig div.but_r').click(function() {		
		var accorder = $(this).parent().find("div.in_h_accord");
		
		if (!accorder.data('inmotion') && (parseInt(accorder.css('left')) > (- parseInt(accorder.css('width')) + (58 * 5))))
		{
			accorder.animate({ left: '-=58px'}, 300, function () {
				if (parseInt(accorder.css('left')) <= -parseInt(accorder.css('width'))+(58*5)+'px')
				{
					accorder.stop().animate({ left: -parseInt(accorder.css('width'))+(58*5)+'px'}, 300, function () {
					} );
				}
			} );
		}
		
		if ($(this).parent().find(".h_cur").next().length)
		{
			$(this).parent().find(".h_cur").next().click();
			
		}
		else
		{
			$(this).parent().find('.h_pic').first().click();
			accorder.animate({ left: '0px'}, 300, function () {
				if (accorder.css('left') < '0px')
				{
					accorder.animate({ left: '+=58px'}, 300, function () {
					});
				}
			});
		}
	});
	
	$('div.h_navig div.but_l').click(function() {
		var accorder = $(this).parent().find("div.in_h_accord");
		if (!accorder.data('inmotion') && (parseInt(accorder.css('left')) < 0))
		{	
			accorder.animate({ left: '+=58px'}, 300, function () {
				if (parseInt(accorder.css('left')) >= 0)
				{
					accorder.stop().animate({ left: '0px'}, 300, function () {
					});
				} 
									
			});
		}
		if ($(this).parent().find(".h_cur").prev().length)
		{
			$(this).parent().find(".h_cur").prev().click();
		}
		else
		{
			$(this).parent().find('.h_pic').last().click();
			accorder.animate({ left: - parseInt(accorder.css('width'))+(58*5)+'px'}, 300, function () {
				
			} );
		}
	});
	
	$('div.h_photo').click(function() {
		$(this).parents('div.small_gallery').find(".h_cur").next().click();
	});
	
	$('div.h_navig div.h_pic').mouseenter(function() {
		$(this).addClass('h_hov');
	});
	
	$('div.h_navig div.h_pic').mouseleave(function() {
		$(this).removeClass('h_hov');
	});
	
	$('div.h_navig div.h_pic').click(function() {
		var photo = $(this).parents('div.small_gallery').find('div.h_photo img');
		photo.hide();
		photo.parent().find('img').attr("src",$(this).attr('id')).each(function() {
			if (this.complete && !$.browser.mozilla)
			{
				photo.stop(true,true).hide().delay(0).fadeIn(400);
			}
			else
			{
				photo.load(
					function()
					{
						photo.stop(true,true).hide().delay(0).fadeIn(400);
					}
				);
			}
		});
		photo.attr('alt',$(this).attr('alt'));
		//photo.find('img').stop(true, true).parent().fadeIn(600);
		
		$('div.h_navig div.h_pic').removeClass('h_cur');
		$(this).addClass('h_cur');
	});	
	
});



// index top scroll //
var scroll_maxime = 5000;
var scroll_duration = 0000;
var scroll_count = 2;
var scroll_load_count = 2;
var scroll_max_count = 0;
function slide()
{
	setTimeout(function() 
	{

		if (scroll_duration >= scroll_maxime)
        {
			if (scroll_max_count < scroll_count)
			{
				scroll_count = 1;
			}
			show_new(scroll_count);         
		}
		else
		{
			scroll_duration += 10;
		}
		slide();
	}, 10);
}

function addcss()
{
	if (scroll_load_count <= scroll_max_count)
	{
		setTimeout(function() 
		{
			var box = $('.image_carousel');
			var elem = box.find('#ich_'+scroll_load_count).find('div.image_carousel_holder');
			
			elem.css("background-image", "url('/public/images/headers/"+elem.attr('id')+".jpg')");			
			scroll_load_count++;
			addcss();
		}, 2000);
	}
}

function addheadboubles() 
{
	for (var i = 0; i < scroll_max_count; i++)
	{
		var bbl = $('<div class="bouble" id="baabid_'+(i+1)+'"></div>');
		bbl.data('vid',i+1);
		$('#head_boubles').append(bbl);
	}
	$('#head_boubles .bouble').first().addClass('cur');
	$('#head_boubles .bouble').click(function() {
		show_new($(this).data('vid'));
	});
	
	
}

function show_new(count)
{
	var box = $('.image_carousel');
	var elem = box.find('#ich_'+count);
	if (!elem.hasClass('cur'))
	{
		scroll_duration = 0;  
		
		
		$(".image_carousel_abs").removeClass('cur');
			$('#head_boubles .bouble').removeClass('cur');
		
		elem.addClass('cur');
		$('#baabid_'+count).addClass('cur');
		
		elem.hide();
		box.append(elem);
		elem.fadeIn(800);	
		scroll_count++; 
	}
}
