    var label = null;
    var searchResults = null;
	 
    var documentInitialized = false;
        
    $(document).ready(function()
    {
      if (documentInitialized)
        return;
		
    	var geoSearchTabIndex = 1;
		
		  var isIE;
      var isIE7;
      var isIE6;
      
      var navig =  navigator.userAgent.toLowerCase();
      isIE = navig.indexOf("msie") != -1;
          
      if(navig.indexOf("msie 7") != -1) 
      	isIE7 = true; 
      else if(navig.indexOf("msie 6") != -1)
      { 
      	isIE6 = true;
      }

      if (isIE6)
      {
        $("#browser_not_supported").show();
      }
		
/*		if ($("#tabs").attr("selected"))
		{
			$("#tabs").tabs({selected: $("#tabs").attr("selected")});
		}
		else
			$("#tabs").tabs();
	*/	
		$("#user_location_city_button").unbind("mouseover");
		$("#user_location_city_button").unbind("mouseout");
		$("#user_location_city_button").unbind("click");
		
		$("#user_location_city_button").mouseover(function()
		{
			$("#user_location_city_button")[0].className = "user_location_city_button_over";
		});

		$("#user_location_city_button").mouseout(function()
		{
			$("#user_location_city_button")[0].className = "user_location_city_button";
		});
		
		$("#user_location_city_button").click(function()
		{
			$("#user_location_tutorial_link").focus();
		});	
		
		$(".more_filter_msg").unbind("click");
		
		$(".more_filter_msg").click(function()
		{
			$("#morfilter").toggle();
			
			$("#morfilter_show").toggle();
			$("#morfilter_hide").toggle();
		       
			return false;
		});
	
		$("#user_location_button").fancybox({
				 'hideOnContentClick': false,
				 frameWidth:572,
				 frameHeight:260
		 });
     		    
    documentInitialized = true;
	});
	
	 $(window).load(function()
  { 
     initializeImagesSize();
     
    function initializeImagesSize()
		{
		  $('img').each(function()
      {
  		  if (this.getAttribute("auto_resize") == "true")
  		  {
    		  if (typeof(this.naturalWidth) != "undefined" && this.naturalWidth == 0 || (typeof(this.naturalWidth) == "undefined"  && !this.complete))
          {
            this.src = this.getAttribute("default_src");
            var maxWidth = this.getAttribute("max_width");
    		    var maxHeight = this.getAttribute("max_height");
    		    
    		    var width = this.getAttribute("default_width");
            var height = this.getAttribute("default_height");
            
    		    if (width * maxHeight > maxWidth * height)
    				{
    					this.width = maxWidth;
    					this.height = height * maxWidth / width; 
    				}
    				else 
    				{
    					this.height = maxHeight;
    					this.width = width * maxHeight / height;
    				}
          } 
          else
          {
    		    var maxWidth = this.getAttribute("max_width");
    		    var maxHeight = this.getAttribute("max_height");
    		    var width = this.width;
    		    var height = this.height;
    		    
    		    if (width * maxHeight > maxWidth * height)
    				{
    					this.width = maxWidth;
    					this.height = height * maxWidth / width; 
    				}
    				else 
    				{
    					this.height = maxHeight;
    					this.width = width * maxHeight / height;
    				}
          }

          this.style.visibility = "visible";
		  }});
		  
    }
    });
    
	  function onLoadAutoResizeImage(img)
    {
        if (img.getAttribute("auto_resize") == "true")
  		  {
    		  if (typeof(img.naturalWidth) != "undefined" && img.naturalWidth == 0 || (typeof(img.naturalWidth) == "undefined"  && !img.complete))
          {
            img.src = img.getAttribute("default_src");
            img.width = img.getAttribute("default_width");
            img.height = img.getAttribute("default_height");
          } 
          else
          {
    		    var maxWidth = img.getAttribute("max_width");
    		    var maxHeight = img.getAttribute("max_height");
    		    var width = img.width;
    		    var height = img.height;
    		    
    		    if (width * maxHeight > maxWidth * height)
    				{
    					img.width = maxWidth;
    					img.height = height * maxWidth / width; 
    				}
    				else 
    				{
    					img.height = maxHeight;
    					img.width = width * maxHeight / height;
    				}
          }
        }
    }

	function openPopup(element, width, height)
	{
    window.open(element.href, 'popup', 'scrollbars=no,width=' + width + ',height=' + height);
  }

	function closePopup(refresh)
	{
		$.fn.fancybox.close();
		if (refresh)
			refreshWindow();
	}
	
	function refreshWindow()
	{
		window.location.reload(true);
	}