﻿
$(function(){
var body_height = $(window).height();
var content_height = $(".container").height();
if (content_height < body_height ) {
    $(".container").css("minHeight", body_height+"px");
}


var cont_height = $(".container").height();
$(".favor_podl").height(cont_height);

$(window).resize(function(){
    var body_height = $(window).height();
    var content_height = $(".container").height();

    $(".container").css("minHeight", body_height+"px");


});

Cufon.replace('.menu_head .td1 a');
Cufon.replace('.menu_headqqq  a', { hover: {  color: '#ffffff'    }});

$('.a2').parent("td").parent("tr").click(function() {
	$(".spacer").css("display", "none");
	$(this).prev(".spacer").css("display", "block");
	$(".ajax").animate({height: 'hide'}, 800); 
	var page = parseInt($(this).attr("id"));
	if($(".menu").children("#"+page).attr("opened")==""){
	$("#loading-overlay").fadeIn(100);
	$.ajax({
		   type: "POST",
		   url: "/ajax/catalog_items.php",
		   data: "page="+page,
		   success: function(data){$(".ajax"+page).html(data);
		   $(".ajax"+page).animate({height: 'show'}, 800);
		   $("#loading-overlay").fadeOut(800); $(".menu").children("#"+page).attr("opened", "1");
		   }
		 });
	}else{
		   $(".ajax"+page).animate({height: 'show'}, 400);
	}
	$(".menu_prev").html("");
    $(".menu li").removeClass("act");
    $('.sc_menu li').removeClass("acti");
    $(".mp").hide();
    $(this).parent("tbody").parent("table").parent("div").parent("li").addClass("act");
});
/////////////////////////////////////////////////////
////////////////////AJAXED FAQ FORM/////////////////
/////////////////////////////////////////////////////
//FAQ INPUT SECURITY 
var pm_pattern = "E-mail";
$("#fcustomer").blur(function(){
var name = /^([A-Za-zА-Яа-я0-9_\-\s]){4,99}$/;
if(name.test($('#fcustomer').val())){}else{$(this).val("");}
});
$("#fmail").blur(function(){
	var mail = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	var phone = /^\+([0-9]{2})+\(([0-9]{3})+\)([0-9\-]{7,9})$/;
	if(mail.test($('#fmail').val())||phone.test($("#fmail").val)){}else{$(this).val(pm_pattern);}
});

$(".send1").live("click", function(){
var fcustomer = $("#fcustomer").val();
var ftext = $("#ftext").val();
var fmail = $("#fmail").val();
var msg = "error";
if(fcustomer==""||fmail == ""||fcustomer=="ошибка"||fmail == "ошибка"){
	$("#q_answer").fadeIn();
	$("#q_answer").html('<p style="color:red;">ошибка! - поля заполнены не верно</p>');
}else{
	$("#q_answer").html("Обрабатывается запрос...");
	$.post("/ajax/faq.php",{'fcustomer':fcustomer,'fmail':fmail,'ftext':ftext},function(msg){
		if((fcustomer!="" && fmail!="")){
			msg = '<p style="color:green;">Сообщение отправлено на модерацию...</p>'; 
    	   $("#fcustomer, #fplace, #ftext").val("");
		}else{
			msg = '<p style="color:red;">ошибка! - заполните обязательные поля</p>';
		}
	$("#q_answer").fadeIn();
	$("#q_answer").html(msg);
	$("#q_answer").fadeOut(3000); 	
});
}
return false;
});

/////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
$('.a1').click(function() {
    //$(this).parent("td").parent("tr").parent("tbody").parent("table").parent("div").next(".menu_prev").next(".menu_list").show();
    $(".spacer").css("display", "none");
	$(".menu li").removeClass("act");
    $(".mp").hide();
  return false;
});



$('.item_close').click(function() {
    $(this).parent(".mp").slideUp();
    $('.sc_menu li').removeClass("acti");
  return false;
});


$(".input_o1").click(function(){
    ish_val = $(this).val();
    if (ish_val== "Ваше имя") {
      $(this).val("");
    } else {   }
});
$(".input_o1").blur(function() {
    var temp_val = $(this).val();
    if ( temp_val == "" ) {  $(this).val("Ваше имя");   }
});

$(".input_o2").click(function(){
    ish_val = $(this).val();
    if (ish_val== "E-mail") {
      $(this).val("");
    } else {   }
});
$(".input_o2").blur(function() {
    var temp_val = $(this).val();
    if ( temp_val == "" ) {  $(this).val("E-mail");   }
});

$(".area1").click(function(){
    ish_val = $(this).val();
    if (ish_val== "Текст сообщения") {
      $(this).val("");
    } else {   }
});
$(".area1").blur(function() {
    var temp_val = $(this).val();
    if ( temp_val == "" ) {  $(this).val("Текст сообщения");   }
});



$("#browsable").scrollable({circular: true, mousewheel: false}).navigator().autoscroll({
	interval: 10000
});

////////////////////////////////////////////////////////////
//////////////////////FAQ ( simple pagination)////////////
//////////////////////////////////////////////////////////
$(".arr_left_n").hide();
$(".arr_right_g").hide();

// if items == items on page

page = parseInt($(".idkeeper").attr("id"));
items = parseInt($(".count").attr("id"));
if(page==items){
	$(".arr_right_n").hide();
	$(".arr_right_g").fadeIn();
}

// navigation right click

$(".arr_right_n").live("click", function(){
	page = parseInt($(".idkeeper").attr("id"));
	items = parseInt($(".count").attr("id"));
	$(this).animate({opacity: '0' }, 200);
	$(this).animate({opacity: '1' }, 300);
	$(".arr_left_g").hide();
	$(".arr_left_n").fadeIn();
	$(".ola").animate({opacity: '0' }, 800, function(){
		$.ajax({
			type: "POST",
			url: "/ajax/faq_paging.php",
			data: "page="+page,
			success: function(data){
				$(".ola").animate({opacity: '1'}, 800);	
				$(".ola").html(data);
				if(page>=items-5){
					$(".arr_right_n").hide();
					$(".arr_right_g").fadeIn();
				}
			}
		});
	});
});

//	navigation left click
 
$(".arr_left_n").live("click", function(){
	$(this).animate({opacity: '0' }, 200);
	$(this).animate({opacity: '1' }, 300);
	$(".review_ul").animate({opacity: '0' }, 800);
	$(".arr_right_n").fadeIn();
	$(".arr_right_g").hide();	

	page = parseInt($(".opinion_ul").attr("id"));
		$(".ola").animate({opacity: '0'}, 800, function(){
			$.ajax({
				type: "POST",
				url: "/ajax/faq_paging.php",
				data: "page="+page,
				success: function(data){
					$(".ola").animate({opacity: '1' }, 800);		
					$(".ola").html(data);	
				}
			});
		});
		if(page==0){
			$(".arr_left_n").hide();
			$(".arr_left_g").fadeIn();
		}
});
$('.item_close').live("click", function() {
    $(this).parent(".mp").slideUp();
    $('.sc_menu li').removeClass("acti");
  return false;
});

$('.sc_menu li a').live("click", function() {
var item = parseInt($(this).attr("rel"));
var item_cat = parseInt($(this).attr("id"));
  var aclass= $(this).attr("class");
	$.ajax({
		   type: "POST",
		   url: "/ajax/catalog_items_opened.php",
		   data: "item="+item+"&&"+"item_cat="+item_cat,
		   success: function(data){
		   $(".menu_prev"+item_cat).html(data); },
		   complete: function(){$(this).attr("opened", "1");
//			  $(".menu_prev").animate({height: 'show'}, 800);
		   	  $("#loading-overlay").fadeOut();
		   }
		 });
});	

});
