/* Author: 

*/

		function Submit() {

                  document.book.submit();

		}	

		function ClicktoCall() {


		var phone = $('#phone').val();

		$.post("/call.php",{tel: phone}, function(data){$("#info").text(data)});


		}


		(function($) {
			$.fn.inputDefualts = function(options) {
			// дефолтные значения
			var defaults = {
	 			cl: 'inactive', // имя класса для неактивного состояния
	 			text: this.val()   // значение берется из самого инпута
	  		}, 	opts = $.extend(defaults, options);	
	  		
	  		this.addClass(opts['cl']); 	// добавляем класс к инпуту
	  		this.val(opts['text']);			// ставим значение по умолчанию
	  		
	  		// обрабатываем события фокуса на поле
	  		this.focus(function() {
	  			if($(this).val() == opts['text']) $(this).val(''); // обнуляем его, если надо
	  			$(this).removeClass(opts['cl']); // убираем класс
	  		});
	  		
	  		// теперь очередь блюра
	  		this.blur(function() {
	  			if($(this).val() == '') {
	  				$(this).val(opts['text']); 			// возвращаем значение
	  				$(this).addClass(opts['cl']); 	// и класс, если надо
	  			}
	  		});
		};
		
		})(jQuery);



		snow_intensive=300; 
		snow_speed=15000; 
		snow_src=new Array('/NY/sneg4.png', '/NY/snow.gif', '/NY/sneg1.gif', '/NY/sneg2.gif', '/NY/sneg3.gif', '/NY/snow21.gif'); 


		function snow_start() { 
			snow_id=1; 

			snow_y=document.body.clientHeight-35;


			setInterval(function() { 
				snow_x=Math.random()*document.body.offsetWidth-100; 
				snow_img=(snow_src instanceof Array ? snow_src[Math.floor(Math.random()*snow_src.length)] : snow_src); 
				snow_elem='<img class="png" id="snow'+snow_id+'" style="position:absolute; left:'+snow_x+'px; top:0;z-index:10000" src="'+snow_img+'">'; 
				$("body").append(snow_elem); 
				snow_move(snow_id); 
				snow_id++; 
			},snow_intensive);
		} 
		
		function snow_move(id) { 
			$('#snow'+id).animate({top:snow_y,left:"+="+Math.random()*100},snow_speed,function() { 
			$(this).empty().remove(); 
		});} 


		$(window).load(function() {


//		        snow_start();

		        $('#slider').nivoSlider();


						var hidden=true;
						var $first=true;

                                                    setInterval(function() {
			

							if ($first==true) {

								$('.welcome2')
									.animate({top: "465px",height: "100px"}, 1000);

							}


							$first=false;

						      }, 2000 );
				


					$("#capt").click(function(){

						if (hidden==true) {
		                                            $('.welcome2')
								.animate({top: "275px",height: "300px"}, 1000);
							  	hidden=false;
						}  else {

							$('.welcome2')
								.animate({top: "465px",height: "100px"}, 1000);
							  	hidden=true;

						}


					});


							



			   var first = 0;
			   var speed = 700;
			   var pause = 3500;
	     
			   function removeFirst(){

				   first = $('ul#listticker li:first').html();
				   $('ul#listticker li:first')
				   .animate({opacity: 0}, speed)
				   .fadeOut('fast', function() {$(this).remove();});
				   addLast(first);



			   }
     
			   function addLast(first){

				   last = '<li style="display:none">'+first+'</li>';
				   $('ul#listticker').append(last);
				   $('ul#listticker li:last')
				   .animate({opacity: 1}, speed)
				   .fadeIn('fast');


			   }
     


			   function removeFirst2(){


				   first = $('ul#listticker2 li:first').html();
				   $('ul#listticker2 li:first')
				   .animate({opacity: 0}, speed)
				   .fadeOut('fast', function() {$(this).remove();});
				   addLast2(first);
				          

			   }
     
			   function addLast2(first){


				   last = '<li style="display:none">'+first+'</li>';
				   $('ul#listticker2').append(last);
				   $('ul#listticker2 li:last')
				   .animate({opacity: 1}, 1000)
				   .fadeIn('fast');

			   }

			   interval = setInterval(removeFirst, pause);
			   interval2 = setInterval(removeFirst2, 5000);





			jQuery(".read-more").click(function(){
				var welcome=jQuery(this).parent().parent();
				var divWelcomeHeight=welcome.innerHeight();
				var headerHeight=jQuery(this).parent().innerHeight();
				var animateHeight=(divWelcomeHeight-headerHeight);
				var animate="";
				var up=false;
				if(welcome.hasClass("up")){
					animate="+="+animateHeight+"px";
					up=true;
				}else{
					animate="-="+animateHeight+"px";
					up=false;
				}
				
				welcome.stop().animate({
					"top":animate
				},600,function(){
					(up) ? welcome.removeClass("up") : welcome.addClass("up");
				});
				weatherWidget.stop().animate({
					"top":animate
				},600);
				
				
				return false;
			});	
		
	        });
		
	        $(function(){


				// Accordion
				$("#accordion").accordion({ header: "h3" });


				// Datepicker
				$('#check-in').datepicker({


					dateFormat: 'dd/mm/yy',
				        minDate: 0,
					hideIfNoPrevNext: true,
					showOn: "button",
					buttonImage: "/images/cal.gif",
					buttonImageOnly: true


				});
				$('#check-out').datepicker({
					dateFormat: 'dd/mm/yy',
				        minDate: 0,
					hideIfNoPrevNext: true,
					showOn: "button",
					buttonImage: "/images/cal.gif",
					buttonImageOnly: true

				});

				
				$('#check-in').change(function () {

                                      $('#check-out').datepicker("option", "minDate",$('#check-in').val());

				 });


				$('#check-out').change(function () {

                                      $('#check-in').datepicker("option", "maxDate",$('#check-out').val());

				 });


				$(".gallery:first a[rel^='prettyPhoto']").prettyPhoto({animation_speed:'normal',theme:'facebook',slideshow:3000, autoplay_slideshow: false});
				$(".gallery:gt(0) a[rel^='prettyPhoto']").prettyPhoto({animation_speed:'fast',slideshow:10000, hideflash: true});


				// Dialog			
				$('#dialog').dialog({
					autoOpen: false,
					width: 450,
				});
				
				// Dialog Link
				$('#dialog_link').click(function(){
					$('#dialog').dialog('open');
					return false;
				});

				$('#login-input').inputDefualts({
					cl: 'inactive',
					text: 'Логин'
				});
				$('#pass-input').inputDefualts({
					cl: 'inactive',
					text: 'Пароль'
				});

				
		});
     


