﻿$(function(){
  $("select#country").change(function(){
      $.get("/search/getcurortsbycountry/" + $(this).val(), function(data) {
	  $('select#curort').html(data);
	  
	  })
})

})

$(function(){
  $("select#curort").change(function(){
      $.get("/search/gethotelsbycurort/" + $(this).val(), function(data) {
	  $('select#hotel').html(data);
	  
	  })
})

})

$(function(){
  $("select#tourtype").change(function(){
      $.get("/search/gettoursbytourstype/" + $(this).val(), function(data) {
	  $('select#tour').html(data);
	  
	  })
})

})

$(function(){
  $("select#type").change(function(){
      if ($(this).val() == "country")
	  {
	  	$("span#country").css("visibility", "visible");
		$("span#curort").css("visibility", "hidden");
		$("span#hotel").css("visibility", "hidden");
		$("span#tour").css("visibility", "hidden");
	  }
	  if ($(this).val() == "curort")
	  {
	  	$("span#country").css("visibility", "visible");
		$("span#curort").css("visibility", "visible");
		$("span#hotel").css("visibility", "hidden");
		$("span#tour").css("visibility", "hidden");
	  }
	  if ($(this).val() == "hotel")
	  {
	  	$("span#country").css("visibility", "visible");
		$("span#curort").css("visibility", "visible");
		$("span#hotel").css("visibility", "visible");
		$("span#tour").css("visibility", "hidden");
	  }
	  if ($(this).val() == "tour")
	  {
	  	$("span#country").css("visibility", "hidden");
		$("span#curort").css("visibility", "hidden");
		$("span#hotel").css("visibility", "hidden");
		$("span#tour").css("visibility", "visible");
	  }
})

})


$(document).ready(function(){
 
 	currentImg = "";
	$("#spec1").html( $(".thumbs:eq(1)").attr("spec1") );
	$("#spec2").html( $(".thumbs:eq(1)").attr("spec2") );
	$("#spec3").html( $(".thumbs:eq(1)").attr("spec3") );
	$("#spec4").html( $(".thumbs:eq(1)").attr("spec4") );
	$("#spec5").html( $(".thumbs:eq(1)").attr("spec5") );
	
	$("#largeImg").attr({ src: $(".thumbs:eq(1)").attr("name"), alt: $(".thumbs:eq(1)").attr("title") });
	
	$("#spec1").css("color", $(".thumbs:eq(1)").attr("spec1color")) ;
	$("#spec2").css("color", $(".thumbs:eq(1)").attr("spec2color")) ;
	$("#spec3").css("color", $(".thumbs:eq(1)").attr("spec3color")) ;
	$("#spec4").css("color", $(".thumbs:eq(1)").attr("spec4color")) ;
	$("#spec5").css("color", $(".thumbs:eq(1)").attr("spec5color")) ;
	
			
			$("#spec1").css("font-size", $(".thumbs:eq(1)").attr("spec1size") + "px") ;
			$("#spec2").css("font-size", $(".thumbs:eq(1)").attr("spec2size") + "px") ;
			$("#spec3").css("font-size", $(".thumbs:eq(1)").attr("spec3size") + "px") ;
			$("#spec4").css("font-size", $(".thumbs:eq(1)").attr("spec4size") + "px") ;
			$("#spec5").css("font-size", $(".thumbs:eq(1)").attr("spec5size") + "px") ;
			
			$("#spec1").css("top", $(".thumbs:eq(1)").attr("spec1top") + "px") ;
			$("#spec2").css("top", $(".thumbs:eq(1)").attr("spec2top") + "px") ;
			$("#spec3").css("top", $(".thumbs:eq(1)").attr("spec3top") + "px") ;
			$("#spec4").css("top", $(".thumbs:eq(1)").attr("spec4top") + "px") ;
			$("#spec5").css("top", $(".thumbs:eq(1)").attr("spec5top") + "px") ;
			
			$("#spec1").css("left", $(".thumbs:eq(1)").attr("spec1left") + "px") ;
			$("#spec2").css("left", $(".thumbs:eq(1)").attr("spec2left") + "px") ;
			$("#spec3").css("left", $(".thumbs:eq(1)").attr("spec3left") + "px") ;
			$("#spec4").css("left", $(".thumbs:eq(1)").attr("spec4left") + "px") ;
			$("#spec5").css("left", $(".thumbs:eq(1)").attr("spec5left") + "px") ;
	
			$("#specback").css("background-color", $(".thumbs:eq(1)").attr("specbackcolor")) ;
			$("#specback").css("opacity",  $(".thumbs:eq(1)").attr("specbackopacity")) ;
			$("#speccontainer").css("top", $(".thumbs:eq(1)").attr("specbacktop") + "px") ;
			$("#speccontainer").css("left", $(".thumbs:eq(1)").attr("specbackleft") + "px") ;
			$("#specback").css("width", $(".thumbs:eq(1)").attr("specbackwidth") + "px") ;
			$("#specback").css("height", $(".thumbs:eq(1)").attr("specbackheight") + "px") ;
			$("#speccontainer").css("width", $(".thumbs:eq(1)").attr("specbackwidth") + "px") ;
			$("#speccontainer").css("height", $(".thumbs:eq(1)").attr("specbackheight") + "px") ;
	
	
	
	 imgConfig = { 
     sensitivity: 2, // number = sensitivity threshold (must be 1 or higher) 
     interval: 100, // number = milliseconds for onMouseOver polling interval 
     timeout: 100, // number = milliseconds delay before onMouseOut 
     over: function() { 
	 	if (currentImg != $(this).attr("title"))
		{
			$("#largeImg").css("display", "none");
			//$("#largeImg").fadeOut(50);
			$("#largeImg").attr({ src: $(this).attr("name"), alt: $(this).attr("title") });
			$("#largeImg").fadeIn(900);
			
			$("body em").html( $(this).attr("title") ); 
			
			$("#spec1").html( $(this).attr("spec1") );
			$("#spec2").html( $(this).attr("spec2") );
			$("#spec3").html( $(this).attr("spec3") );
			$("#spec4").html( $(this).attr("spec4") );
			$("#spec5").html( $(this).attr("spec5") );
			
			$("#spec1").css("color", $(this).attr("spec1color")) ;
			$("#spec2").css("color", $(this).attr("spec2color")) ;
			$("#spec3").css("color", $(this).attr("spec3color")) ;
			$("#spec4").css("color", $(this).attr("spec4color")) ;
			$("#spec5").css("color", $(this).attr("spec5color")) ;
			
			$("#spec1").css("font-size", $(this).attr("spec1size") + "px") ;
			$("#spec2").css("font-size", $(this).attr("spec2size") + "px") ;
			$("#spec3").css("font-size", $(this).attr("spec3size") + "px") ;
			$("#spec4").css("font-size", $(this).attr("spec4size") + "px") ;
			$("#spec5").css("font-size", $(this).attr("spec5size") + "px") ;
			

			$("#spec1").css("top", $(this).attr("spec1top") + "px") ;
			$("#spec2").css("top", $(this).attr("spec2top") + "px") ;
			$("#spec3").css("top", $(this).attr("spec3top") + "px") ;
			$("#spec4").css("top", $(this).attr("spec4top") + "px") ;
			$("#spec5").css("top", $(this).attr("spec5top") + "px") ;
			
			$("#spec1").css("left", $(this).attr("spec1left") + "px") ;
			$("#spec2").css("left", $(this).attr("spec2left") + "px") ;
			$("#spec3").css("left", $(this).attr("spec3left") + "px") ;
			$("#spec4").css("left", $(this).attr("spec4left") + "px") ;
			$("#spec5").css("left", $(this).attr("spec5left") + "px") ;
			
			$("#specback").css("background-color", $(this).attr("specbackcolor")) ;
			$("#specback").css("opacity",  $(this).attr("specbackopacity")) ;
			$("#speccontainer").css("top", $(this).attr("specbacktop") + "px") ;
			$("#speccontainer").css("left", $(this).attr("specbackleft") + "px") ;
			$("#specback").css("width", $(this).attr("specbackwidth") + "px") ;
			$("#specback").css("height", $(this).attr("specbackheight") + "px") ;
			$("#speccontainer").css("width", $(this).attr("specbackwidth") + "px") ;
			$("#speccontainer").css("height", $(this).attr("specbackheight") + "px") ;
			currentImg = $(this).attr("title");
		}
     }, 
     out: function() { 
	 }} 
	 
	 aConfig = { 
     sensitivity: 2, // number = sensitivity threshold (must be 1 or higher) 
     interval: 100, // number = milliseconds for onMouseOver polling interval 
     timeout: 100, // number = milliseconds delay before onMouseOut 
     over: function() { 
	 	$(".thumbs li").removeClass("active");
		$(this).addClass("active");
     }, 
     out: function() { 
	 }} 
	 
     $(".thumbs a").hoverIntent(imgConfig); 
	
	 $(".thumbs li").hoverIntent(aConfig);

});



$(document).ready(function(){
	$("#slide-down-button h3").click(function(){
		if ($("#slide-down-button").hasClass("active"))
		{
			$("#slide-down-button").removeClass("active");
			$("#register-form").removeClass("active");
		}
		else
		{
			$("#slide-down-button").addClass("active")
		}
		
		if ($("#slide-down-login-form").hasClass("active"))
		{
			$("#slide-down-login-form").fadeOut(300);
			$("#slide-down-login-form").removeClass("active");
			$("#register-form").removeClass("active");
			
		}
		else
		{
			$("#slide-down-login-form").fadeIn(300);
			$("#slide-down-login-form").addClass("active")
			$("#register-form").removeClass("active");
		}
		
		$("#forgotPass").removeClass("active");
		$("#register-form").removeClass("active");
	});	
	$("#slide-down #forgot").click(function(){
		$("#register-form").removeClass("active");
		$("#forgotPass").toggleClass("active");
	});
	
	$("#slide-down #register").click(function(){
		$("#forgotPass").removeClass("active");
		$("#register-form").toggleClass("active");
	});
	
	$(".main-about").hover(function(){
		$("#second-about").slideDown(100);
	});
	$("#second-about").mouseleave(function(){
		$(this).slideUp(100);
	});
	
	$("#welcome-form h3").click(function(){
		if ($("#welcome-form-text").hasClass("active"))
		{
			$("#welcome-form h3").removeClass("active");
			$("#welcome-form-text").fadeOut(300);
			$("#welcome-form-text").removeClass("active");
			var bodyContent = $.ajax({
		      url: "/users/togglePanel/",
		      type: "POST",
		      data: ({}),
				  success: function(msg){
				  }
			   }
			).responseText;
		}
		else
		{
			$("#welcome-form h3").addClass("active");
			$("#welcome-form-text").fadeIn(300);
			$("#welcome-form-text").addClass("active");
			var bodyContent = $.ajax({
		      url: "/users/togglePanel/",
		      type: "POST",
		      data: ({}),
				  success: function(msg){
				  }
			   }
			).responseText;
		}
});


$("#mreg").click(function(){
	$("#slide-down-button").addClass("active");
	$("#forgotPass").removeClass("active");
	
	$("#slide-down-login-form").addClass("active");
	
	$("#register-form").addClass("active")
	
});	

$("#change-password").click(function(){
		if ($("#change-password-form").hasClass("active"))
		{
			$("#change-password-form").fadeOut(300);
			$("#change-password-form").removeClass("active");
		}
		else
		{
			$("#change-password-form").addClass("active");
			$("#change-password-form").fadeIn(300);
		}
});
});


$(function(){
$('.menu-item').hover(function() {
        $(this).animate({ paddingLeft: '26px' }, 150);
      }, function() {
        $(this).animate({ paddingLeft: '20px' }, 150);
      });
});

$(function(){
$('.second-menu-item').hover(function() {
        $(this).animate({ paddingLeft: '6px' }, 150);
      }, function() {
        $(this).animate({ paddingLeft: '0px' }, 150);
      });
});


$(function(){
$('.register-btn').click(function() {
	var bodyContent = $.ajax({

		      url: "/users/register/",

		      type: "POST",

		      data: ({email : $("#remail").val(),
			  name : $("#name").val(),
			  city : $("#city").val(),
			  phone : $("#phone").val()}),

		      success: function(msg){

		         alert(msg);
				 if(msg.indexOf("Успешная") > -1) $("#register-form").removeClass("active");

		      }

		   }

		).responseText;
	});
});

$(function(){
$('.login-btn').click(function() {
	var bodyContent = $.ajax({

		      url: "/users/isvalid/",

		      type: "POST",

		      data: ({email : $("#email").val(),
			  password : $("#password").val()}),

		      success: function(msg){

		         if (msg != "false")
				 {
				 	$("#welcome-form").fadeIn(300);
					$("#welcome-form-text").fadeIn(300);
					$('#welcome-form').addClass("active");
					$('#welcome-form-text').addClass("active");
					
					$("#slide-down-login-form").fadeOut(100);
					$("#slide-down-button").fadeOut(100);
					$("#register-form").fadeOut(100);
					$("#forgotPass").fadeOut(100);
					
					$('#welcome-form-text').html(msg);
				 }
				 else
				 {
					 alert("Неверный email или пароль");
				 }

		      }

		   }

		).responseText;
	});
});

$(function(){
$('.save-btn').click(function() {
	var bodyContent = $.ajax({

		      url: "/users/newpassword/",

		      type: "POST",

		      data: ({oldpassword : $("#oldpassword").val(),
			  newpassword1 : $("#newpassword1").val(),
			  newpassword2 : $("#newpassword2").val()}),

		      success: function(msg){

		         alert(msg);

		      }

		   }

		).responseText;
	});
});


$(function(){
$('.forgot-pass-btn').click(function() {
	var bodyContent = $.ajax({

		      url: "/users/forgotpassword/",

		      type: "POST",

		      data: ({email : $("#femail").val()}),

		      success: function(msg){

		         alert(msg);

		      }

		   }

		).responseText;
	});
});

