
function findValue(li) {    

    if( !!li.extra ) 
        var sValue = li.extra[0];

    if (sValue && sValue.length > 0)
            window.location = sValue;

}

function selectItem(li) {
	findValue(li);
}

function formatItem(row) 
{	
    if (row[2] == 'Jukebox')
    {
        return '<a href="' + row[1] + '" class="res res-jukebox-' + row[3].toLowerCase() + ' floatcontainer link-genre-' + row[8] + '"><span class="res-img"><img style="margin-top: ' + row[7] +'px" src="' + row[4] +'" width="' + row[5] +'" height="' + row[6] +'" alt="" /></span><span class="res-items"><strong>' + row[0] + '</strong>' + row[3] + '</span></a>';
    }
    else if (row[2] == 'Artistit' && row[3].length > 0)        
    {    
        return '<a href="' + row[1] + '" class="res res-linkout floatcontainer link-genre-' + row[8] + '" target="_blank"><span class="res-img"><img style="margin-top: ' + row[7] +'px" src="' + row[4] +'" width="' + row[5] +'" height="' + row[6] +'" alt="" /></span><span class="res-items"><strong>' + row[0] + '</strong>' + row[3] + '</span></a>';
    }        
    else
    {
        return '<a href="' + row[1] + '" class="res floatcontainer link-genre-' + row[8] + '"><span class="res-img"><img style="margin-top: ' + row[7] +'px" src="' + row[4] +'" width="' + row[5] +'" height="' + row[6] +'" alt="" /></span><span class="res-items"><strong>' + row[0] + '</strong>' + row[3] + '</span></a>';         
    }
}

$("#searchEMI").autocomplete(
  "/haku/",
  {
		delay:200,
		width: 224,
		minChars:2,
		matchSubset:1,
		matchContains:1,
		cacheLength:10,
		onItemSelect:selectItem,
		onFindValue:findValue,
		formatItem:formatItem,
		maxItemsToShow:2,
		autoFill:false,
		selectFirst:true
	}
);  