$(document).ready(function(){
	$("input,textarea").fieldFocus();
	$("ul li img").hover(
		function () {
			$(this).fadeTo(0, 0.7);
		},
		function () {
			$(this).fadeTo(0, 1);
		}
	);
	$(".logo a").hover(
		function () {
			$(".logo a img").css("margin-left","-165px");
		},
		function () {
			$(".logo a img").css("margin-left","0px");
		}
	);
	$(".feedBack").mouseenter(function(){
		$(this).css("background-color","#666");
		$(".feedBack_form").show();
	});
	$(".feedBack_form").hover(
		function(){
		},
		function(){
		$(this).hide();
		$(".feedBack").attr("style","");
	});
	$(".feedBack_form .errors").parent(".feedBack_form").show();
	
	$('.regPriborInfo').width($('.regPribor').width());
	$('.regPribor').hover(
		function() {
			$(this).stop();
			$('.regPriborInfo').slideDown(1000);
		},
		function() {
			$(this).stop();
			$('.regPriborInfo').slideUp(1000);
		}
	);
	
	headImg();
});

// Form start
$.fn.fieldFocus = function(){
  function formCheeck(form,field,val){
    $(form).bind('submit',function(){
      if($(field).val()==val){
        $(field).val('');
      }
      return true;
    });
  }
  function findForm(elem){
    var form = $(elem).parent();
    if($(form).is('form')==false){
      return findForm(form);
    }else{
      return form;
    }
  }
  $(this).each(function(i){
    var value = $(this).attr('title');
    if($(this).is(':password')){
      var passInput = $(this);
      var inputStyle = $(this).attr('style') ? $(this).attr('style') : '';
      $(passInput).after('<input type="text" class="'+$(passInput).attr('class')+'" value="'+value+'" title="'+$(passInput).attr('title')+'" style="'+inputStyle+'">');
      var textInput = $(this).next();
      if($(passInput).val()==''){
        $(passInput).val("").hide();
      }else{
        $(textInput).hide();
      }
      $(textInput).focus(function(){
        if($(this).val()==value || $(this).val()==''){
          $(passInput).show().focus();
          $(this).hide();
        }
      });
      $(passInput).blur(function(){
        if($(this).val()==""){
          $(this).hide();
          $(textInput).show();
        }
      });
    }else{
      if($(this).val()=='')
        $(this).val(value);
      $(this)
      .focus(function(){
        if($(this).val()==value || $(this).val()==''){
          $(this).val("");
        }
      })
      .blur(function(){
        if($(this).val()=="")
          $(this).val(value);
      });
    }
    var thisForm = findForm($(this));
    formCheeck(thisForm,$(this),value);
  });
  return this;
}
// Head slider
function headImg() {
	if ($('.i-block3 img').size() >= 2){
		$('.i-block3 img:last').addClass('active');
		var timeout = setInterval(function() {
			var currentslide = $('.i-block3 img.active');
			if ( currentslide.length == 0 ) currentslide = $('.i-block3 img:last');
			var nextslide =  currentslide.next().length ? currentslide.next() : $('.i-block3 img:first');
			nextslide.fadeIn(3000).addClass('active');
			currentslide.fadeOut(3000).removeClass('active');
		}, 6000);
	}
}
