var suggest = new playphone.suggest();
suggest.url = '/SearchSuggest.aspx';
suggest.object = playphone.$('ctl00_txtSearch');
suggest.delay = 0.5;
suggest.nodes_to_select = ['Title', 'Artist', 'Sample', 'Description', 'CategoryName', 'ContentTypeId'];
suggest.initialize();

var last_content_type = -1;

suggest.format_result = function(result_item) {
    
    var title = result_item[0];
    var artist = result_item[1];
    
    if (result_item[2] == null){
        result_item[2] = '/Images/album_image.gif'
    }
    
    var sample = result_item[2];
    
    // /Images/album_image.gif
    
    var description = result_item[3];
    var category_name = result_item[4];
    var content_type = parseInt(result_item[5]);
    
    var title_url = playphone.config_url(title);
    var artist_url = playphone.config_url(artist);
    
    artist_url = artist_url.replace('N/A', 'NA');
    
    if (last_content_type != content_type && last_content_type != -1) {
    
        this.markup += '</div>'
    }
    
    switch (content_type) {
    
        case 0:
        
            /*if (last_content_type != 0) {
                
                this.markup += '<div class="top">'
                this.markup += '  <a href="/FeaturedArtists/">+</a>'
                this.markup += '  <h2>Featured Artists</h2>'
                this.markup += '</div>'
                this.markup += '<div class="content artists">'
            }
            
            this.markup += '  <div class="sample" title="More info about ' + title + ' - Ringtones, Wallpapers and Biography" selectable="true" url="/Ringtones/' + title_url + '/">'
            this.markup += '    <a href="/Ringtones/' + title_url + '/"><img src="' + sample + '" alt="' + title + ' - Ringtones, Wallpapers and Biography" /></a>'
            this.markup += '    <h3><a href="/Ringtones/' + title_url + '/">' + (title.length > 7 ? title.substring(0, 7) + '...' : title) + '</a></h3>'
            this.markup += '    <h4><a href="/Ringtones/' + title_url + '/">' + (artist.length > 7 ? artist.substring(0, 7) + '...' : artist) + '</a></h4>'
            this.markup += '  </div>'
            
            last_content_type = 0;*/
        
            break;
            
        case 1:
        
            if (last_content_type != 1) {
                
                this.markup += '<div class="top">'
                this.markup += '  <a href="/Polyphonic-Ringtones/">+</a>'
                this.markup += '  <h2>Polytones</h2>'
                this.markup += '</div>'
                this.markup += '<div class="content musictones">'
            }
            
            this.markup += '  <div class="sample" title="More info about ' + artist + ' - ' + title + ' Ringtone" selectable="true" url="/Polyphonic-Ringtones/' + title_url + '/">'
            this.markup += '    <a href="/Download-PolyphonicRingtones-' + artist_url + '-' + title_url + '/"><img src="' + sample + '" alt="More info about ' + artist + ' - ' + title + ' Ringtone" /></a>'
            this.markup += '    <h3><a href="/Download-PolyphonicRingtones-' + artist_url + '-' + title_url + '/">' + (title.length > 10 ? title.substring(0, 10) + '...' : title) + ' - ' + (artist.length > 10 ? artist.substring(0, 10) + '...' : artist) + '</a></h3>'
            this.markup += '    <h4><a href="/Download-PolyphonicRingtones-' + artist_url + '-' + title_url + '/">' + (category_name.length > 30 ? category_name.substring(0, 30) + '...' : category_name) +  '</a></h4>'
            this.markup += '  </div>'
            
            last_content_type = 1;
        
            break;
            
        case 2:
        
            if (last_content_type != 2) {
                
                this.markup += '<div class="top">'
                this.markup += '  <a href="/Music-Tones/">+</a>'
                this.markup += '  <h2>Music Tones</h2>'
                this.markup += '</div>'
                this.markup += '<div class="content musictones">'
            }
            
            this.markup += '  <div class="sample" title="More info about ' + artist + ' - ' + title + ' Ringtone" selectable="true" url="/Music-Tones/' + title_url + '/">'
            this.markup += '    <a href="/Download-Music-Tones-' + artist_url + '-' + title_url + '/"><img src="' + sample + '" alt="More info about ' + artist + ' - ' + title + ' Ringtone" /></a>'
            this.markup += '    <h3><a href="/Download-Music-Tones-' + artist_url + '-' + title_url + '/">' + (title.length > 10 ? title.substring(0, 10) + '...' : title) + ' - ' + (artist.length > 10 ? artist.substring(0, 10) + '...' : artist) + '</a></h3>'
            this.markup += '    <h4><a href="/Download-Music-Tones-' + artist_url + '-' + title_url + '/">' + (category_name.length > 30 ? category_name.substring(0, 30) + '...' : category_name) +  '</a></h4>'
            this.markup += '  </div>'
            
            last_content_type = 2;
        
            break;
            
        case 4:
        
            if (last_content_type != 4) {
            
                this.markup += '<div class="top">'
                this.markup += '  <a href="/Wallpaper/">+</a>'
                this.markup += '  <h2>Wallpaper</h2>'
                this.markup += '</div>'
                this.markup += '<div class="content wallpapers">'
            }
            
            this.markup += '    <a href="/Download-Wallpaper-' + artist_url + '-' + title_url + '/"><img src="' + sample + '" alt="More info about ' + title + ' Wallpaper" /></a>'
            
            last_content_type = 4;
            
            break;
            
        case 6:
        
            if (last_content_type != 6) {
            
                this.markup += '<div class="top">'
                this.markup += '  <a href="/Mobile-Games/">+</a>'
                this.markup += '  <h2>Games</h2>'
                this.markup += '</div>'
                this.markup += '<div class="content gm">'
            }
            
            this.markup += '  <div class="sample" title="More info about ' + title + ' Mobile Game" selectable="true" url="/Mobile-Games/' + title_url + '/">'
            this.markup += '    <a href="/Mobile-Games/' + title_url + '/"><img src="' + sample + '" alt="More info about ' + title + ' Mobile Game" /></a>'
            this.markup += '    <h3><a href="/Mobile-Games/' + title_url + '/">' + (title.length > 25 ? title.substring(0, 25) + '...' : title) + '</a></h3>'
            this.markup += '    <h4><a href="/Mobile-Games/' + title_url + '/">' + description + '</a></h4>'
            this.markup += '  </div>'
            
            last_content_type = 6;
        
            break;
    }
}