//alert(1);
var photo_now = 1;

$(document).ready(function(){

	$('.p_menu').mouseover(function(){
		$(this).removeClass("p_menu").addClass("p_menu2");;
	});

	$('.p_menu').mouseout(function(){
		$(this).removeClass("p_menu2").addClass("p_menu");;
	});


	$('.menu_p2').mouseover(function(){
		$(this).removeClass("menu_p2").addClass("menu_p");
		$(this).children("ul.drop_menu").show();
	});

	$('.menu_p2').mouseout(function(){
		$(this).removeClass("menu_p").addClass("menu_p2");
		$(this).children("ul.drop_menu").hide();
	});

	$('.menu_p_here').mouseover(function(){
		$(this).children("ul.drop_menu").show();
	});

	$('.menu_p_here').mouseout(function(){
		$(this).children("ul.drop_menu").hide();
	});


	$('.show_photogallery_fotos').click(function(){
	id_fotogallery = $(this).attr('rel');
	         $.ajax({
                url: "/ajax/fotogallery.php",
                cache: false,
                data: "id_fotogallery="+id_fotogallery+"&lang="+lang+" ",
                success: function(html){
                   $("#conteiner_f").html(html);
                    photo_now=1;
                    photo_now = photo_now*1;
                    var this_photo = photo_now;
                    $('a.foto_click').removeClass("here");
                    var all_photo = $('a.foto_click').size();
                    if(photo_now == 1) $('a.go_left').css('display','none'); else $('a.go_left').css('display','block');
                    if(photo_now == all_photo) $('a.go_right').css('display','none'); else $('a.go_right').css('display','block');
                    //  	if(this_photo > all_photo) this_photo = 1;
                    var path = $('#fotka_' + this_photo).attr('href');
	                  $('#fotka_' + this_photo).addClass('here');
	                  var title = $('#fotka_' + this_photo).attr('title');
	                  $('.foto_name').html(title);
                    $('#foto_big').animate({opacity: 0},500,function(){
  	                $(this).html('<img src=' + path + ' />').find('img').bind('load',function(){ $('#foto_big').animate({opacity: 1},500); });
                    });
                }
            });
    $('#photogallery_ON').show();
    ffr = $(document).height();
    $('#photogallery_ON').height(ffr);
    scrol = self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
    $('.conteiner_fotogalery').css('margin-top',scrol+50);
    return false;
  });


  $(window).scroll(function () {
    scrol = self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
    $('.conteiner_fotogalery').css('margin-top',scrol+50);
  });


  $('.back_to_fotogallery').click(function(){
    $('#photogallery_ON').hide();
    $('.foto_name').html(' ');
    $('#foto_big').html(' ');
    $("#conteiner_f").html(' ');
    return false;
  });


  $('#go_top').click(function(){
    $('#conteiner_f').animate({"scrollTop": "-=480px"}, "slow", function(){});
    return false;
  });


  $('#go_bottom').click(function(){
    $('#conteiner_f').animate({"scrollTop": "+=480px"}, "slow", function(){});
    return false;
  });



  

$('a.foto_click').live("click", function(){
  $('a.foto_click').removeClass("here");
  photo_now = photo_now*1;
  photo_now = $(this).attr('rel');
  var all_photo = $('a.foto_click').size();
  var this_photo = photo_now;
  if(photo_now == 1) $('a.go_left').css('display','none'); else $('a.go_left').css('display','block');
  if(photo_now == all_photo) $('a.go_right').css('display','none'); else $('a.go_right').css('display','block');
  var path = $(this).attr('href');
  $(this).addClass('here');
  var title = $('#fotka_' + this_photo).attr('title');
	$('.foto_name').html(title);
	$('#foto_big').animate({opacity: 0},500,function(){
  	$(this).html('<img src=' + path + ' />').find('img').bind('load',function(){ $('#foto_big').animate({opacity: 1},500); });
  });
  	return false;
});
  
  
$('a.go_right').click(function () {
  $('a.foto_click').removeClass("here");  
	photo_now = photo_now*1 + 1;
  var all_photo = $('a.foto_click').size();
  var this_photo = photo_now;
  if(photo_now == 1) $('a.go_left').css('display','none'); else $('a.go_left').css('display','block');
  if(photo_now == all_photo) $('a.go_right').css('display','none'); else $('a.go_right').css('display','block');
  //  	if(this_photo > all_photo) this_photo = 1;
	var path = $('#fotka_' + this_photo).attr('href');
	$('#fotka_' + this_photo).addClass('here');
	var title = $('#fotka_' + this_photo).attr('title');
	$('.foto_name').html(title);
  $('#foto_big').animate({opacity: 0},500,function(){
  	$(this).html('<img src=' + path + ' />').find('img').bind('load',function(){ $('#foto_big').animate({opacity: 1},500); });
  });
  return false;
});


$('a.go_left').click(function () {
  $('a.foto_click').removeClass("here");
	photo_now = photo_now*1 - 1;
  var all_photo = $('a.foto_click').size();
  var this_photo = photo_now;
  if(photo_now == 1) $('a.go_left').css('display','none'); else $('a.go_left').css('display','block');
  if(photo_now == all_photo) $('a.go_right').css('display','none'); else $('a.go_right').css('display','block');
    	//if(this_photo < 1) {this_photo = all_photo*1 - 1; photo_now = all_photo*1 - 1}
	var path = $('#fotka_' + this_photo).attr('href');
	$('#fotka_' + this_photo).addClass('here');
	var title = $('#fotka_' + this_photo).attr('title');
	$('.foto_name').html(title);
  $('#foto_big').animate({opacity: 0},500,function(){
    $(this).html('<img src=' + path + ' />').find('img').bind('load',function(){ $('#foto_big').animate({opacity: 1},500); });
  });
  return false;
});


$("input[name='face']").change(function(){
if ($("input[name='face']:checked").val() == '1') {
  $("input[name='posada']").attr('disabled','disabled');
  $("input[name='company_name']").attr('disabled','disabled');
}else{
  $("input[name='posada']").removeAttr('disabled');
  $("input[name='company_name']").removeAttr('disabled');
}
});

$('#f_zayavka').submit(function(){
      if (($("input[name='fio']").val()=='') ||
          ($("input[name='city']").val()=='') ||
          ($("input[name='adress']").val()=='') ||
          ($("input[name='emaill']").val()=='') ||
          ($("input[name='phone']").val()=='') ||
          (!$('input:radio[name=type_t]').is(':checked')) || //
          (!$('input:radio[name=garant]').is(':checked')) ||  //
          ($("input[name='proizvoditel']").val()=='') ||
          ($("input[name='captcha_code']").val()==''))
      {
        alert("Не заполнены обязательные поля!");
        return false;
      } else {
        var regexp=/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/ //regular expression defining an email address
	       if (document.forms['f_zayavka'].emaill.value.search(regexp)==-1) { //if match failed
	       alert('Введите правильно Ваш e-mail');
	       document.forms['f_zayavka'].emaill.value='';
	       document.forms['f_zayavka'].emaill.focus();
	       return false;
	       } else return true;
	    }
});

$('#subscribe').submit(function(){
    var email_aj = $("input[name='email_subscribe']").val();
    var name_aj = $("input[name='name_subscribe']").val();
    $.ajax({
            url: "/tpl/includes/inc.subscribe.php",
            cache: false,
            data: "email="+email_aj+"&name_aj="+name_aj,
            success: function(html){
                $("#thank_text").show();
                $("#thank_text").html(html);
            }
    });
    return false;
});

$('#opros').submit(function(){
    var vois = $('input:radio[name="otvet"]:checked').val();
    var id = $('input:[name="v_id"]').val();
      if(vois) {
            $.ajax({
                url: "/tpl/includes/ajax.voiting.php",
                cache: false,
                data: "id_voting=" + id + "&lang=" + lang + "&vois="+vois,
                success: function(html){
                    $("#variants").html(html);
                    $("#submit").hide();
                }
            });
        }
    return false;
});

});

