//NFL Player Search Ajax    
var srchhost = "http://www.fanhouse.com/search-api/";
function lookup(inputString) {
           $('#srchRsltsHdr').remove();
           $('#autoSuggestionsList').height('auto');
	var inputString = inputString.toLowerCase();
	if(inputString.length < 2) {
		$('#suggestions').hide();
		$('#remItems').hide();
	}else{
		$('#suggestions').show();
		$('#autoSuggestionsList').empty();
                $('#remItems').hide("fast");

		jQuery.getJSON(srchhost + "?version=2.2&start=0&rows=6&indent=on&q=sport-name%3A"+sportName+"+AND+category%3APLAYER+AND+"+inputString+"*&wt=json&json.wrf=?", function(data){
			ordList = $("<table class='srcBxTable'></table>").append("<thead><tr><th class='plyrPstn'>Player</th><th class='noRsltsTxt glfFix'>Position</th><th class='plyrPstn glfFix'>Team</th></tr></thead>").append($("<tbody></tbody>")).appendTo("#autoSuggestionsList");
            $('#autoSuggestionsList').empty().append(ordList);

			$(data.response).each(function(j,result){
                                var numFound = result['numFound'];
				//To check if no results are returned
				if (numFound == 0 ){
					$('#autoSuggestionsList').html('<span class="noRsltsTxt">No results found for <b>'+inputString+'</b></span>');
				    $('#remItems').hide('fast');
				}else if (numFound < 7){					
					$('#remItems').hide("fast");		
					
				}else {					
					$('#remItems').empty();
					var rem = numFound - 6;
					$('#remItems').show('fast');
					$('#remItems').html('<span class="noRsltsTxt">'+rem+'</span> more');				
					
				}


			});
	
			$(data.response.docs).each(function(i,item){	
				ordList.append('<tr class="srcTableRow'+i%2+'"><td class="plyrNm"><a href="' + item['player-url'] + '">'+ item['player-first-name'] + ' '+item['player-last-name']+'</a></td><td class="noRsltsTxt glfFix">'+item['player-position']+'</td><td class="plyrTeam glfFix"><a href="' + item['team-url'] + '">' + item['player-team-city'] + ' ' + item['player-team-name'] +'</a></td></tr>');
				$("#autoSuggestionsList ul.srchItems:even").addClass("altRw");
			});
		});
	}
} 
    
function fill(thisValue) {
	$('#inputString').val(thisValue);
	$('#suggestions').hide();
}

function setDefHighlight() {
	var currPath = location.pathname;
	$("#chnnlNav ul .chnnlNavTab").children("a").map(function() {
		var child = $(this);
		if (child.attr("href").length > 0) {
			var thisUrl = child.attr("href");
			var thisPath = thisUrl.substring((thisUrl.indexOf(".com")+4), thisUrl.length-1);
			if (thisPath.length < 1) { 
				thisPath = "/"; 
			}
			//console.log('thisUrl = ' + thisUrl + ', thisPath = ' + thisPath + ', currPath = ' + currPath); 	
			//if ((thisPath.indexOf(currPath) > -1 && currPath.length > 1) || currPath == thisPath) { - Fix for highlight issue
			if ((currPath.indexOf(thisPath) != -1 && thisPath.length > 1) || currPath == thisPath ) {
				// don't highlight home on sub pages
				child.parent(".chnnlNavTab").addClass("slctd");
			}
		}
	});
}

// Load When Doc is Ready
jQuery(document).ready(function() {

 //Standard Effects
	$(".entry-title a").bind("mouseenter", function(e){
	$(this).addClass("hghLght");
	});
	$(".entry-title a").bind("mouseleave", function(e){
	$(this).removeClass("hghLght");
	});
	
	// IE Flickering Fix
	//$(".sprtSubNav a").bind("mouseenter", function(e){
	//$(this).addClass("hghLght");
	//});
	//$(".sprtSubNav a").bind("mouseleave", function(e){
	//$(this).removeClass("hghLght");
	//});

//Nav MouseOver Effects
	$("#fhNav .subNav ul li:last").css('border-bottom','none');

	$("#sprtSubNavTab").mouseover(function(){
        $("#fhNav").toggleClass("sprtSlctd");
	$("#sprtSubNav").show();
	});
	$("#sprtSubNavTab").mouseout(function(){
        $("#fhNav").toggleClass("sprtSlctd");
	$("#sprtSubNav").hide();
	});
	
	$("#videoSubNavTab").mouseover(function(){
        $("#fhNav").toggleClass("videoSlctd");
	$("#videoSubNav").show();
	});
	$("#videoSubNavTab").mouseout(function(){
        $("#fhNav").toggleClass("videoSlctd");
	$("#videoSubNav").hide();
	});
	
        $("#fntsySubNavTab").mouseover(function(){
        $("#fhNav").toggleClass("fntsySlctd");
	$("#fntsySubNav").show();
	});
	$("#fntsySubNavTab").mouseout(function(){
        $("#fhNav").toggleClass("fntsySlctd");
	$("#fntsySubNav").hide();
	});
        
	$("#wrtrsSubNavTab").mouseover(function(){
        $("#fhNav").toggleClass("wrtrsSlctd");
	$("#wrtrsSubNav").show();
	});
	$("#wrtrsSubNavTab").mouseout(function(){
        $("#fhNav").toggleClass("wrtrsSlctd");
	$("#wrtrsSubNav").hide();
	});
	
        $("#moreSubNavTab").mouseover(function(){
        $("#fhNav").toggleClass("moreSlctd");
	$("#moreSubNav").show();
	});
	$("#moreSubNavTab").mouseout(function(){
        $("#fhNav").toggleClass("moreSlctd");
	$("#moreSubNav").hide();
	});
    
//ChannelNav Effects
	$("div#chnnlTms").hide();
	
	$(".chnnlNavTab").mouseover(function(){
		$(this).addClass("slctd");
	}).mouseout(function(){
		$(this).removeClass("slctd");
		setDefHighlight();
	});
	
	$("#srch").mouseover(function(){
	$("div#suggestBox").show();
	}).mouseout(function(){
	$("div#suggestBox").hide();
	});
	
	$("#chnnlPlyrs").mouseover(function(){
	$("div#plyrSrch").show();
	}).mouseout(function(){
	$("div#plyrSrch").hide();
	});
		
	$("#chnnlTeams").mouseover(function(){
	$("div#chnnlTeamsLst").show();
	}).mouseout(function(){
	$("div#chnnlTeamsLst").hide();
	});

        $("#GH_search_select").mouseover(function(){
	$("#GH_search_drop").show();
	}).mouseout(function(){
	$("#GH_search_drop").hide();
	});

	$("#GH_search_select li").mouseover(function(){
		$(this).addClass("selected");
	}).mouseout(function(){
		$(this).removeClass("selected");
	});        
		
});
