var $j = jQuery.noConflict();

$j(document).ready(function() {


 
 //Show sort by options when required
         $j("#sortby").hover(function(){  
         $j("#sub").show();        
     }, function(){  
         $j("#sub").hide();           
     }); 
 
 
$j("table.customer-table").tablesorter(); 
    $j("#company-link").click(function() { 
        // set sorting column and direction, this will sort on the first and third column the column index starts at zero 
        var sorting = [[1,0]]; 
        // sort on the first column 
        $j("table.customer-table").trigger("sorton",[sorting]); 
        // return false to stop default link action 
        return false; 
    }); 
	
	$j("#sector-link").click(function() { 
		// set sorting column and direction, this will sort on the first and third column the column index starts at zero 
		var sorting = [[2,0]]; 
		// sort on the first column 
		$j("table.customer-table").trigger("sorton",[sorting]); 
		// return false to stop default link action 
		return false; 
    }); 

$j(function() { 
  var theTable = $j('table.customer-table');

 $j("#sector-select").change(function() {
    if(this.value != "All Sectors")
    {
        $j.uiTableFilter( theTable, this.value );
    }  
    else
    {
        $j.uiTableFilter( theTable, '' );
    }
 })
}); 

//Populate the dropdown from the table
var item=[], options=[];

//Add select all text

//Iterate all td's in second column
$j('table.customer-table span.cust-type').each( function(){
   //add item to array
//   alert($j(this).text());
   	
	if($j.inArray($j.trim($j(this).text()), item) < 0){ item.push($j.trim($j(this).text())); }
	
});

item.push("All Sectors");

//restrict array to unique items
var items = $j.unique(item).sort();

//iterate unique array and build array of select options
$j.each( items, function(i, item){
//alert('<option value="' + item + '">' + item + '</option>'); 
	if(item == 'All Sectors'){
		options.push('<option value="' + item + '" selected="selected">' + item + '</option>');
	}else{
		options.push('<option value="' + item + '">' + item + '</option>');
	}
})

//finally empty the select and append the items from the array
$j('#sector-select').empty().append( options.join() );

 //initially hide sub div
 $j("#sub").hide();

$j('.keys a').attr('target', '_self');

// Added by Chris Garrett
$j('span.keys a[href=]').remove();

 
});