var dessous = [];
var mudada = false;
var textda = false;


if (!$.browser.msie)
$(document).ready (function ()
{
  $('.testarea').append ('<div class="sauron sauron1" style="opacity:0"></div>');
  $('.testarea').append ('<div class="sauron sauron2" style="opacity:0"></div>');
  $('.testarea').append ('<div class="sauron sauron3" style="opacity:0; display:none;"><input class = "sauron-search" style="background:none; border:none; margin-top:3px; margin-left: 13px; font-size:12px; width:120px; height:15px;" value = ""><div class="sauron-search-button" style="width:22px; height:21px; position:absolute; top:0px; left:141px;"></div></a>');

var slow = 1;

  $('.f-fix').hover (

  function () //hoverIn
  {
    if (! (mudada || textda))
      $(this).find ('.sauron1').stop().animate( {opacity:1}, (300*slow) );
  },

  function () //hoverOut
  {
    //if (!mudada)
      $(this).find ('.sauron1').stop().animate( {opacity:0}, (300*slow) );
  }

  ); //hover


  $('.area11').hover (

  function () //hoverIn
  {
    if (! (mudada || textda))
	{
      $(this).find ('.sauron2').stop().animate( {opacity:1}, (300*slow) );
	}
  },

  function () //hoverOut
  {
    $(this).find ('.sauron2').stop().animate( {opacity:0}, (300*slow) );
var s3 = $(this).find ('.sauron3');
if (!s3.find('input').is(':focus') )
    s3.stop().animate( {opacity:0}, 0, function () { s3.css("display","none").find('input'); } );
  }

  ); //hover
  


  $('.sauron2').click (

  function (event)
  {
//alert();
var th = $(this);
    $('.sauron3:visible').animate({opacity:0},200, function () {$(this).css("display","none") } );
    $(this).parent().find('.sauron3').animate({opacity:1},200, function () { th.animate({opacity:0},100) } ).css("display","block").find('input').val('').focus();
    event.stopPropagation();
    return false;

  }

  ); //onClick sauron 2

$('.sauron-search').keypress (function (event)

{

  iftext();
  
  if ( event.which == 13 ) 
  {
    syochi ($(this).val());
    event.preventDefault();
  }
});

$('.sauron-search-button').click (function(event)
{
    syochi ($(this).parent().find('.sauron-search').val());
    return false;
    event.preventDefault();
});


$('.sauron-search').change (function (event) 
{
  var v = $(this).val();
  syochi (v);
});

function iftext()
{
  textda = false;//$('.sauron-search[value!=""]').length>=1;
}



$('.sauron-search').click (function (event)
{
    event.stopPropagation();
});

  $('body').click ( function () 
  {
    $('.sauron3:visible .sauron-search[value=""]').parent().animate( {opacity:0}, (300*slow), function () {$(this).css("display","none") } );
  }); 

// desuuuuuuuu

$('.dashed.name').each (function () 
{
  $(this).attr ('name','shana'+dessous.length);
  $(this).parent().parent().parent().find ('.sauron-search').attr('id','hana'+dessous.length).parent().append('<div class="suggest3" id="ana'+dessous.length+'"></div>');
 new autoComplete(dessous,document.getElementById('hana'+dessous.length),document.getElementById('ana'+dessous.length),20);
  dessous.push($(this).text());
 // alert(dessous);
}
);

 

function syochi (s) //почти сочи, - извините за такие названия функций.
{
  $('.selecteditem').removeClass('selecteditem');
  for (a in dessous)
  {
    if (dessous[a]==s)
    {
      var bl = $('a[name="shana'+a+'"]');
	  $('.sauron-search').val('');
	  iftext();
	  var bll = bl.parent().parent().parent().parent();
	  bll.addClass('selecteditem');
	  mudada=true;
	  $('html,body').animate({scrollTop:bl.offset().top - ($(window).height()-200)/2 }, 500, function () {	   bll.find('.sauron3').animate( {opacity:1}, 10, function () {$(this).css("display","block");  bll.find('input').focus(); mudada=false; } );	
	    } );


    }
  }
}



}
);

//смерть пидоргам
