/**
 * @author TonyG
 */
var timer = null,
	lasttime = 0;

$(document).ready(function() {
	var off = $('#s').offset(),
		t = off.top+$('#s').height()+15,
		l = off.left+$('#s').width()-$('#result').width()+26;
	$('#result').css({'left':l,'top':t});

	$('#s').change(function() {
	  if(!timer) timer = setInterval(check, 1000);
	  lasttime = new Date().getTime();	
	  var val = $('#s').val();
	  if(val.length > 2) {
	  	$.get("/netcat/modules/ajax/ajax_search.php", { text: val }, function(data){ $('#result').html(data); });
	  } else {
	  	$('#result').html('');
	  }
	});
	$('#s').keyup(function() {
	  var a = $('#s').get(0);
	  a.blur(); a.focus();
	  lasttime = new Date().getTime();
	});
	$('#showall').live('click',function() {
	  var ss =  'text='+$('#s').val();
	  location.href = 'http://timeroom.ru/watches/?'+ss;
	});
	$('.cell').live('mouseover',function(){
		$(this).children('div').addClass('select');
		lasttime = new Date().getTime();
	});
	$('.cell').live('mouseout',function(){
		$(this).children('div').removeClass('select');
		lasttime = new Date().getTime();
	});
	$('.cell').live('click',function() {
	  var ss = $(this).attr('link');
	  lasttime = new Date().getTime();
	  if(ss.length)
	  	location.href = 'http://timeroom.ru'+ss;
	});
});
function check() {
	var tm = new Date().getTime();
	if(tm-lasttime > 50000) {
		 clearInterval(timer);
		 timer = null;
		 $('#result').html('');
	}
}
