$(function() {
	$('#header #regionPopup').appendTo(document.body);
	$('#regionDD').mousemove(function() {
		var offset = $('#regionDD').offset();

		$('#regionPopup').css('display', '');

		$('#regionPopup').css({
			left: offset.left + $('#regionDD')[0].offsetWidth - $('#regionPopup')[0].offsetWidth,
			top: offset.top + $('#regionDD')[0].offsetHeight + 6
		});
	});

	$('#regionPopup').mouseleave(function() {
		$(this).css('display', 'none');
	});
	
	$('#header #loginPopup').appendTo(document.body);
	$('#loginDD').mousemove(function() {
		var offset = $('#loginDD').offset();

		$('#loginPopup').css('display', '');

		$('#loginPopup').css({
			left: offset.left + $('#loginDD')[0].offsetWidth - $('#loginPopup')[0].offsetWidth,
			top: offset.top + $('#loginDD')[0].offsetHeight + 6
		});
	});

	$('#loginPopup').mouseleave(function() {
		$(this).css('display', 'none');
	});
	BindEvents();
});

function BindEvents() {

    $('input.input_find').bind("focus", function(e) {
        $(document).bind("keydown", function(e) {
            var key = e.keyCode || e.which;
            if (key === 13) { return false; }
        });
    });
    
    $('input.input_find').bind("focusout", function(e) {
        $(document).unbind("keydown");
    });
    
    $('input.input_find').bind("keydown", function(e) {
        var key = e.keyCode || e.which;
        if (key === 13) { OnSearchEnter(this.value); }
    });

    $('a.search').click(OnSearchClick);
}

function OnSearchEnter(findValue) {
    Search(findValue);
}

function OnSearchClick() {
    Search($('input.input_find').val());
}

function Search(findValue) {
    if (findValue != '') {
        location.href = 'http://renaissancegroup.com/Search/?q=' + encodeURIComponent(findValue);
    }
}

