// Copyright (C) 2010 Optaros, Inc. All rights reserved.

function parseSearchData(response) {
    var array = new Array();
    if(response.products && response.products.length > 0) {
        for(i=0; i<response.products.length; i++) {
            product = response.products[i];
            product.type = 'product';
            array[array.length] = {data: product, value: product.title, result: product.title };
        }
    }
    if(response.content && response.content.length > 0) {
        for(i=0; i<response.content.length; i++) {
            content = response.content[i];
            content.type = 'content';
            array[array.length] = {data: content, value: content.title, result: content.title };
        }
    }
    return array;
}

function formatAutosuggestItem(row) {
    if(row.type == 'product') {
        html = '<div class="autocomplete_product" onclick="document.location=\''+row.url+'\'">';
        html+= '<img width="50" align="left" src="'+row.full_thumbnail_url+'"/>';
        html+= '<p class="item-title">'+jQuery('<div/>').text(row.title).html();+'</p>';
        html+= '<p>'+jQuery('<div/>').text(row.snippet).html();+'</p>';
        html+= '</div>';
        return html;
    }
    else if(row.type == 'content') {
        html = '<div class="autocomplete_content" onclick="document.location=\''+row.url+'\'">';
        html+= '<p class="item-title">'+jQuery('<div/>').text(row.title).html();+'</p>';
        html+= '<p>'+jQuery('<div/>').text(row.snippet).html();+'</p>';
        html+= '</div>';
        return html;
    }
    return row.title;
}

