$(document).ready(function(){
  $('.towns_list').hover(function(){$(this).addClass('hover');},function(){$(this).removeClass('hover');});
  $('nav ul.l1 li').hover(function(){$(this).addClass('hover');},function(){$(this).removeClass('hover');});
  $('.cat_submenu').hover(function(){$(this).addClass('hover');},function(){$(this).removeClass('hover');});
  
  $('nav ul.l1 li:first').addClass('first'); 
  //$('#so_scroll .so_item:first').addClass('first');
  //$('.cat_list_block .cat_list_item:first').addClass('first');
  $('#catalog .cat_line').each(function(){$(this).children(':first').addClass('first');});
  $('nav ul.l1 ul.l2').each(function(){$(this).children(':first').addClass('first');});
  $('#catalog .cat_line').each(function(){$(this).children(':first').addClass('first');});
  $('#catalog .cat_submenu ul').each(function(){$(this).children(':first').addClass('first');});
  $("input[type='text']").addClass("string");
  $("input[type='password']").addClass("string");
  $("input[type='submit']").addClass("button_link png24");
  


  $('#banner_slides').cycle({
    fx:     'fade',
    speed:  3000, 
    timeout:8000 
  });
  
  $(".jscroll").jCarouselLite({
    btnNext: ".next",
    btnPrev: ".prev",
    speed: 400,
    auto:5000,
    easing: "easeinout"
  }); 

  $(".review_scroll").jCarouselLite({
    btnNext: ".next_review",
    speed: 400,
    auto:5000,
    easing: "easeinout"
  });
  
  
  $('input.hint').each(function(index){
    if(!$(this).val()){
      $(this).val($(this).attr('rel'));
      $(this).addClass("no_focus");
    }
    InputHelperCreateWdgt($(this),$(this).attr('rel'));
  });  
  $('textarea.hint').each(function(index){
    if(!$(this).val()){
      $(this).val($(this).attr('rel'));
      $(this).addClass("no_focus");
    }
    InputHelperCreateWdgt($(this),$(this).attr('rel'));
  });  


  $("#what_you_say_form_id").submit(function(){
    
    res=true;
    $('#what_you_say_form_id input.hint').each(function(index){
      if($(this).attr('rel').indexOf('*')>0 && $(this).attr('rel')==$(this).val() && res){
        alert('Зполните поле: '+$(this).attr('rel').replace('*',''));
        res=false;        
      }
    });
    $('#what_you_say_form_id textarea').each(function(index){
      if($(this).attr('rel').indexOf('*')>0 && $(this).attr('rel')==$(this).val() && res){
        alert('Зполните поле: '+$(this).attr('rel').replace('*',''));
        res=false;        
      }
    });
    return res;
  });
  
});


function InputHelperCreateWdgt(obj,text){
	$(obj)
		.bind('focus',function(){InputHelperInWdgt(this,text);})
		.bind('blur', function(){InputHelperOutWdgt(this,text);});
	InputHelperOutWdgt(obj,text);
}  

function InputHelperInWdgt(obj,text){
	if(obj.value==text){
    $(obj)
      .removeClass('no_focus')
      .val('');
	}
}

function InputHelperOutWdgt(obj,text){
	if(obj.value=='' || obj.value==text){
  	$(obj)
      .addClass('no_focus')
      .val(text);
	}
}

