$(document).ready(function() {

$("#txtSearch").autocomplete('loadxml.asp',
                  { minChars: 2
                   , matchSubset: false
                   , matchContains: true
                   , width: 290
                   , max: 10
                   , scrollHeight: 600
                   , dataType: 'json'
                   , parse: newParser
		   , cacheLength: 10
                   , selectFirst: false
                   , formatItem: function(row) { return row['value'] }
                  }).result(function(event, data) {
                      window.location.href = data.url;
                  });

    function newParser(raw) {
        var array = new Array();

        var prodCount = 0;

        for (var i = 0; i < raw.length; i++) {
            if (raw[i] != null){
            var text
            if (raw[i].type == "product") {
                text = "<a href='" + raw[i].landing + "'><div class='searchitem product";
                if (prodCount == 0) {
                    text = text + " first";
                    prodCount = 1;
                }
                text = text + "'><div class='imagearea'><img src='" + raw[i].image + "' alt='' /></div>"
            } else {
                text = "<div class='searchitem'>"
            }
            text = text + "<div class='detailarea'>" + raw[i].text + "</div></div>";

            array[array.length] = { 'data': { text: raw[i].text, value: text, url: raw[i].landing, image: raw[i].image },
                'result': '', 'value': raw[i].text
}
            };
        }
        return array;
    }
});