// general

var submenu_close = true;
var submenu_timer_handler = 0;

$(document).ready( function() {
	$("#search_query").keypress( function(e){ if (e.which==13) { _search($(this).val()); } } );
	$("#search_button").click( function() {  _search( $("#search_query").val() ); } );
	$("#submenu_agents_wrap").hover( show_submenu_onhover, show_submenu_onout );
	//var border = RUZEE.ShadedBorder.create({ corner:0, shadow:8,  border:0 });
	//border.render('submenu_agents');
	// applyDropShadows("#submenu_agents","shadow3");
} );

function _search( q ) { if (q!='') { location.href = '/search.php?q=' + q; } }

  function getElementLeft(p_elm) {
    var x = 0;
    var elm;
    if(typeof(p_elm) == "object"){
      elm = p_elm;
    } else {
      elm = document.getElementById(p_elm);
    }
    while (elm != null) {
      x+= elm.offsetLeft;
      elm = elm.offsetParent;
    }
    return parseInt(x);
  }

  function getElementTop(p_elm) {
    var y = 0;
    var elm;
    if(typeof(p_elm) == "object"){
      elm = p_elm;
    } else {
      elm = document.getElementById(p_elm);
    }
    while (elm != null) {
      y+= elm.offsetTop;
      elm = elm.offsetParent;
    }
    return parseInt(y);
  }


function show_submenu(el) {
	// submenu_agents
	var x = getElementLeft(el);
	var y = getElementTop(el);
	// alert(x + ' ' + y);
	// var elem = $("#submenu_agents")[0];
	 
	$("#submenu_agents_wrap").css({ left : (x-10) + 'px', top: (y)+'px' });
	$("#submenu_agents_wrap").slideDown('fast');	
	
	show_submenu_onout();
	// applyDropShadows("#submenu_agents","shadow1");
}


function show_submenu_onhover() {
	submenu_close = false;
	if (submenu_timer_handler) {
		window.clearTimeout(submenu_timer_handler);
	}
}
function show_submenu_onout() {
	submenu_close = true;
	submenu_timer_handler = window.setTimeout(submenu_timeout,700);
}

function submenu_timeout() {
	if (submenu_close) {
		$("#submenu_agents_wrap").slideUp('fast');	
	}
}


 
