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];
    
    var sample;
    
    if (parseInt(result_item[5]) == 0)                    
        sample = result_item[2] || urlStaticServer + '/Images/artist-image-suggestions.gif';
    else
        sample = result_item[2] || urlStaticServer + '/Images/album-image-suggestions.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);
    
    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="/Ringtones/Artists/">+</a>'
                this.markup += '  <h2>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>Polyphonic Ringtones</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="/Polyphonic-Ringtones/' + artist_url + '/' + title_url + '/"><img src="' + sample + '" alt="More info about ' + artist + ' - ' + title + ' Ringtone" /></a>'
            this.markup += '    <h3><a href="/Polyphonic-Ringtones/' + 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="/Polyphonic-Ringtones/' + 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="/Music-Tones/' + artist_url + '/' + title_url + '/"><img src="' + sample + '" alt="More info about ' + artist + ' - ' + title + ' Ringtone" /></a>'
            this.markup += '    <h3><a href="/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="/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="/Wallpapers/">+</a>'
                this.markup += '  <h2>Wallpapers</h2>'
                this.markup += '</div>'
                this.markup += '<div class="content wallpapers">'
            }
            
            this.markup += '  <div class="sample" title="More info about ' + title + ' Wallpaper" selectable="true" url="/Wallpapers/' + title_url + '/">'
            this.markup += '    <a href="/Wallpapers/' + title_url + '/"><img src="' + sample + '" alt="More info about ' + title + ' Wallpaper" /></a>'
            this.markup += '  </div>'
            
            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;
            
                 
        case 7:
        
            if (last_content_type != 7) {
            
                this.markup += '<div class="top">'
                this.markup += '  <a href="/Video-Clip/">+</a>'
                this.markup += '  <h2>Video Clip</h2>'
                this.markup += '</div>'
                this.markup += '<div class="content musictones">'
            }
            
            this.markup += '  <div class="sample" title="More info about ' + title + ' Video Clip" selectable="true" url="/Video-Clip/' + title_url + '/">'
            this.markup += '    <a href="/Video-Clip/' + title_url + '/"><img src="' + sample + '" alt="More info about ' + artist + ' - ' + title + ' Video Clip" /></a>'
            this.markup += '    <h3><a href="/Video-Clip/' + title_url + '/">' + (title.length > 25 ? title.substring(0, 25) + '...' : title) + '</a></h3>'
            this.markup += '    <h4><a href="/Video-Clip/' + title_url + '/">' + category_name + '</a></h4>'
            this.markup += '  </div>'
            
            last_content_type = 7;
        
            break;
    }
}