﻿$(document).ready(function() {
    //search functions
    //$("#search-box").autocomplete(searchData);
    $("#search-box").autocomplete(searchData, {
        matchContains: true,
        minChars: 0,
        max: 50
           
    }).result(function(e, data) {
        if (propertyJson[data] != null)
        {
            $("#search-box").val(data);
            $("#search-box").blur();
            location.href = propertyJson[data];
        } 
    });

    $("#search-box").focus(function() { 
        $(this).val('');
    
        e = jQuery.Event('keydown');
        e.keyCode = 40;
        
        $(this).trigger(e);
    })
    
    $("#search-box").blur(function() { 
        if ($(this).val() == '')
            $(this).val('Find a property by typing its name or address');
    })
    
    $('#search-box').keyup(function(e) {
	    if(e.keyCode == 13) {
	        e.preventDefault;
		     $("#search-area img").click();
	    }
    });

    $("#search-area img").click(function() {
        if (propertyJson[$("#search-box").val()] != null)
        {
            location.href = propertyJson[$("#search-box").val()];
        } 
        
    });
    
});
