﻿var SearchCity = function($){	
	/**
	 * public methods
	 */
	return {	    
	    selectCity : function(city){
           $("a.selected-region").get(0).innerHTML=unescape(city);
           $('#dropDownContent').hide();
           priv.clearResults();
	    },
	    	    
		/**
		 * initializes the page logic
		 * to be called on $(document).ready
		 */
		OnReady	: function(){
		    var mouse_is_inside=false;	    
		      
            $('span.custom-dropdown').click(function() {
               if( $('#dropDownContent').is(':hidden') ) {
                   $('#dropDownContent').show();
                   $('#regionSuggestions').show();
               }
               else {
                    priv.clearResults();
                    $('#dropDownContent').hide();
                    mouse_is_inside=false;
                }
            });
		      
            $('#dropDownContent').hover(function(){ 
                mouse_is_inside=true; 
            }, function(){ 
                mouse_is_inside=false; 
            });

            $(document).mouseup(function(event){ 
                if(! mouse_is_inside && event.target!=$('span.custom-dropdown').get(0)){
                    $('#dropDownContent').hide();
                }
            });
		}
	}
}(jQuery);

/**
 * Initiate onload methods and functions
 */
$(document).ready(
	function(){
		SearchCity.OnReady();
	}
);


