if (!window.wxtools1) wxtools1 = {};


WxVideoSearch_instance = null;

var searchResultStartIndx = 0
var searchResultEndIndx = 0;
wxtools.a_processSearchResults = 0;
var cityTimeOutID;
var otherTimeOutID;

wxtools.searchingFor = "";

wxtools.searchState = false;
wxtools.haveLocalResults = false;
wxtools.haveKeywordResults = false;
wxtools.keywordResultsIndex = 0;
wxtools.keywordResultsPageIndex =0;

wxtools.localResultsTempLimit = 0;
wxtools.keywordResultsTempLimit = 0;

wxtools.bcTitleDTO_ID = 0;
wxtools.bcTitleDTO_LineupId = 0;

var countOfSearchResultSet = 0;
var searchResultSize = 0;
var inSearchMod = false;
var activeDrillDown = "";
var queryString = new Object;
var space_three = '&nbsp;&nbsp;&nbsp;';
var space_two = '&nbsp;&nbsp;';

var singleTitlePlay = false;
var searchRSArray = new Array();
var rsIndx = 0;
var tmpSearchArray;
wxtools.searchIncrement = 1;


// These functions have be in sync with the name given to the parameter callback when making a server call.
wxtools1.VideoSearchTextResponse = function(instanceID, hash){
	WxVideoSearch_instance.processKeywordSearchResults(hash);
}

wxtools1.VideoSearchLocationResponse = function(instanceID, hash){
	WxVideoSearch_instance.processLocalVideoResults(hash);
}

function SearchResultReturned(results)
{
	wxtools.log("got results");
	if (results.parameters.titles && results.parameters.titles.length >= 1) {
		//wxtools.log("some results");
		wxtools.searchState = true;
		wxtools.haveKeywordResults = true;
		wxtools.keywordSearchResults = results.parameters;
		wxtools.keywordResultsIndex = 0;
		wxtools.keywordSearchResultsReturned = results.totalRows;

		processSearchResult();
	}
	else
	{
		//wxtools.log("no results");
		wxtools.haveKeywordResults = false;
		wxtools.a_processSearchResults ++;
		tryProcessingSearchResults();
	}
}

function SearchResultReturnedWithError(error)
{
	wxtools.log("error");
}

wxtools1.WxVideoSearch = function(){
	WxVideoSearch_instance = this;
	var localSearchID = null;  //need local variable instead of wxtools.searchingFor b/c this could be a locid resolved.
	this.setSearchFor = function(a_searchingFor){localSearchID = a_searchingFor;}
	this.getSearchFor = function(){return localSearchID;}
	var scriptID = 1000 * Math.random();
	var timeoutID;this.getTimeoutID = function(){return timeoutID}

	function callServer(url) {//wxtools.log("call the server" + url);
		var rURL = url;
		var head = document.getElementsByTagName( 'head' ).item(0);
		var last = document.getElementById( scriptID );
		if (last) head.removeChild(last);
		var script = document.createElement('script');
		script.src = rURL;
		script.type = 'text/javascript';
		script.id = scriptID;
		void(head.appendChild(script));
		//rob comment out..trying to debug...timeoutID = setTimeout("WxVideoSearch_instance.processTimeOut()", "10000");
	}
	this.runLocalSearch = function(){
		if(wxtools.searchingFor == null || wxtools.searchingFor == "" ) return;
		//callServer('http://www.weather.com/outlook/multimedia/localvideo/' + wxtools.searchingFor + '?callback=wxtools1.VideoSearchLocationResponse&what=1&limit=10&instance=000');
		callServer('http://www.weather.com/outlook/multimedia/localvideo/' + WxVideoSearch_instance.getSearchFor()  + '?callback=wxtools1.VideoSearchLocationResponse&what=1&limit=10&instance=000');

	}
	this.runKeywordSearch = function(){
		if(wxtools.searchingFor  == null || wxtools.searchingFor  == "" ) return;
		callServer('http://xml.weather.com/search/multimedia/searchlocalvideo?callback=wxtools1.VideoSearchTextResponse&what=1&limit=10&instance=000&where=' + wxtools.searchingFor);

	}

	EventBroadcaster.initialize(this);
}

function processSearchResult()
{
	wxtools.haveKeywordResults = true;
	//foundItems();

	wxtools.log("getTitleById for " + wxtools.keywordSearchResults.titles[wxtools.keywordResultsIndex]);
	callFlash("getTitleById", wxtools.keywordSearchResults.titles[wxtools.keywordResultsIndex]);

}




// Search logic



processNoSearchResults = function(){wxtools.searchState = false;}

addSearchResult = function(tmpT, fetch)
{
	if(tmpT) {
		searchRSArray[rsIndx] = new Array();
		searchRSArray[rsIndx]["Name"] = tmpT.displayName;
		searchRSArray[rsIndx]["ColID"] = tmpT.tags;
		searchRSArray[rsIndx]["ClipID"] = tmpT.referenceId;
		++rsIndx;


		if(rsIndx == searchResultSize) wxtools.searchState = false;
		else if(rsIndx < searchResultSize) retrieveSearchResult();
		else {wxtools.log("Error adding to search results.....addSearchResult()");}
	}else if(fetch) {callFlash("fetchTitleById", tmpSearchArray[rsIndx]);}

}


function getTitleByReferenceId_Result(TitleDTO)
{
	wxtools.bcTitleDTO_ID = TitleDTO.id;
	wxtools.bcTitleDTO_LineupId = TitleDTO.lineupId;
	//wxtools.log ("getTitleByReferenceId_Result lineupID is "  + wxtools.bcTitleDTO_LineupId );
	if (null == wxtools.bcTitleDTO_LineupId )
	{
		//get lineupid too
		if (wxtools.sameLineup == false)
		{
			//wxtools.log ("callFlash = getPlayerLineupIds");
			callFlash("getPlayerLineupIds"); //get all of the lineup ids so we can run through them
			wxtools.sameLineup = false;
		}
		else
		{
			//wxtools.log ("getTitleByReferenceId_Result passing in " + wxtools.clip2CollHash[config["videoRef"]] );
			callFlash("fetchLineupByReferenceId", wxtools.clip2CollHash[config["videoRef"]]);
		}
	}
	else
	{
		if (wxtools.sameLineup == false)
		{
			//wxtools.log ("callFlash = getPlayerLineupIds");
			callFlash("getPlayerLineupIds"); //get all of the lineup ids so we can run through them
			wxtools.sameLineup = false;
		}
		else
		{
			//wxtools.log ("getTitleByReferenceId_Result select title " + TitleDTO.id);
			callFlash("selectTitle", TitleDTO.id, TitleDTO.lineupId, "full");
		}
	}
	wxtools.samePlayer = false;

}


function getTitleById_Result(TitleDTO)
{
	//wxtools.log("comparing *" + wxtools.keywordSearchResults.titles[wxtools.keywordResultsIndex] + "** with *" + TitleDTO.id + "**" );
	if (Number(wxtools.keywordSearchResults.titles[wxtools.keywordResultsIndex])== Number(TitleDTO.id))
	{
		wxtools.keywordSearchResults.titles[wxtools.keywordResultsIndex]["Name"] = TitleDTO.displayName;
		wxtools.keywordSearchResults.titles[wxtools.keywordResultsIndex]["ColID"] = wxtools.clip2CollHash[TitleDTO.referenceId];
		wxtools.keywordSearchResults.titles[wxtools.keywordResultsIndex]["ClipID"] = TitleDTO.referenceId;
		//wxtools.log(" clipid " + wxtools.keywordSearchResults.titles[wxtools.keywordResultsIndex]["ClipID"]);
		//wxtools.log(" ColID " + wxtools.keywordSearchResults.titles[wxtools.keywordResultsIndex]["ColID"]);
		//wxtools.log(" Name " + wxtools.keywordSearchResults.titles[wxtools.keywordResultsIndex]["Name"]);
	}


	//if(wxtools.keywordResultsIndex + 1 >=  wxtools.keywordSearchResults.totalRows)
	if(wxtools.keywordResultsIndex + 1 >=  wxtools.keywordSearchResults.titles.length)
	{
		wxtools.a_processSearchResults ++
		tryProcessingSearchResults();
	}
	else
	{
		//if (wxtools.keywordResultsIndex < wxtools.keywordSearchResults.totalRows)
		if (wxtools.keywordResultsIndex < wxtools.keywordSearchResults.titles.length)
		{
			wxtools.keywordResultsIndex++;
			processSearchResult();
		}
		else
		{
			wxtools.log(" Error in getTitleById_Result ");
		}
	}

}


function getLineupByReferenceId_Result(lineupDTO)
{
	if (wxtools.samePlayer == false )
	{
		//wxtools.log("getLineupByReferenceId_Result complete")
		callFlash("selectTitle", wxtools.bcTitleDTO_ID, lineupDTO.id, "full");

	}
}

function fetchLineupByReferenceId_Result(lineupDTO)
{
	wxtools.bcTitleDTO_LineupId = lineupDTO.id;

	//wxtools.log("fetchLineupByReferenceId_Result complete")
	callFlash("selectTitle", wxtools.bcTitleDTO_ID, lineupDTO.id, "full");
	wxtools.samePlayer = false;
}

function fetchTitleByReferenceId_Result()
{
	//wxtools.log("fetchTitleByReferenceId_Result complete");
	callFlash("getTitleByReferenceId", wxtools.clipID);
}



function returnSearchResults(SR)
{
	this.broadcastMessage("returnBCSearchResults", SR);
}

wxtools1.WxVideoSearch.prototype = {
	broadcastMessage:function() {},
	addListener:function() {},
	removeListener:function() {},

	processKeywordSearchResults:function(hash){
		clearTimeout(this.getTimeoutID());
		this.broadcastMessage("localSearchResults", hash);
	},

	processLocalVideoResults:function(hash){
		clearTimeout(this.getTimeoutID());
		this.broadcastMessage("localVideosResults" , hash);
	},

	doZipSearch:function(zipCode){
		this.doLocIDSearch(zipCode);
	},

	doLocIDSearch:function(LocID){//wxtools.log(LocID);
		this.setSearchFor(LocID);
		this.runLocalSearch();
	},

	doKeywordSearch:function(searchingFor){
		this.setSearchFor(searchingFor);
		this.runKeywordSearch();
	},

	processTimeOut:function(searchFor, hash){
		this.broadcastMessage("WxSearchTimedOut");
	}
};

var wxSearchListener = {
	localSearchResults:function(hash)
	{
		wxtools.log('localSearchResults got results');
		// Set global arrays
		wxtools.haveLocalResults = true;
		clearTimeout(cityTimeOutID);
		// Let's make sure we give BC search enough time to search
		// rob commented out for now...getting funny results if not...
		//cityTimeOutID = setTimeout("tryProcessingSearchResults(2)", "10000");

		wxtools.searchState = true;
		wxtools.localSearchResults = hash;
		wxtools.localResultsIndex = 0;
		wxtools.localSearchResultsReturned = hash['loc'].length;
		if ( wxtools.localSearchResultsReturned == 0 )
		{
			wxtools.haveLocalResults = false;
		}
		wxtools.a_processSearchResults ++;
		tryProcessingSearchResults();


	},
	localVideosResults:function(hash){
		singleResult(getLocalVideoDiv(hash));
		//wxtools.log('localVideosResults singleResult');

	},
	WxSearchTimedOut:function(){
		//wxtools.log("WxSearchTimedOut");
		noResultsFound(1);
	}
};

var Playerlistener = {
	playerIsReady:function() {
		if(!inSearchMod)
		{
			adIsDonePlayingState();
		}
	}

};

/*mark for deletion
function doLocIDSearch(LocID)
{
	wxtools.log("doLocIDSearch");
	this.setSearchFor(LocID);
	this.runLocalSearch();
}

*/

function doBCSearch(where)
{
	if(inSearchMod )
	{
		rsIndx = 0;
		searchResultSize = 0;
		searchRSArray = new Array();
		tmpSearchArray = null
/************Changed callFlash by Steve Sherwood*****************/
		callFlash("searchTitles", wxtools.searchIncrement++, where, ["Science & Nature"],[], 10,"NAME",true); // Need to validate parameters************
/************Changed callFlash by Steve Sherwood*****************/
//wxtools.log("callFlash searchTitles");
	}
}


function searchMe()
{
	if (wxtools.adIsPlaying == true)
	{
		return;
	}
	preSearchSetUp();
	inSearchMod = true;

	startedSearchingState();
	//if search started, halt autoplay per business rule, will reset each time clip finishes
	wxtools.haltAutoPlay = true;

	// This assumes that the player has loaded and notify the page to activate the search field, for the user to use
	wxtools.searchingFor = document.getElementById('searchText').value;// Need to validate and determine type of search(may be)zip or keyword??????????????
	if (wxtools.searchingFor == null || wxtools.searchingFor == "")
	{
		foundItems();
		return false;
	}
	// Do the search using the player(BC side)
	doBCSearch(wxtools.searchingFor);
	//otherTimeOutID = setTimeout("searchTimedOut()", "2000000");

/****************Removed by Steve Sherwood for Epic Player ******************************
	// Do the search using the player(wx side)
	WxVideoSearch_instance.doKeywordSearch(wxtools.searchingFor);
	cityTimeOutID = setTimeout("searchTimedOut()", "10000");
****************************************************************************************/
}



function searchTimedOut(){	noResultsFound(1);}

function trim(stringToTrim)
{
	if (stringToTrim == null || stringToTrim == "")
	{
		return;
	}
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function preSearchSetUp()
{
	clearTimeout(otherTimeOutID);
	clearTimeout(cityTimeOutID);
	otherTimeOutID = null;
	cityTimeOutID = null;
	wxtools.keywordSearchResults = null;
	wxtools.localSearchResults = null;

}

function navButtons(po,pa,no,na)
{
	//by default, previous and next are off
	//if previous is needed, but not active lets turn it on
	//po is to turn previous on, pa is to make previous active, no is to turn next on, na is to make next active
	if(po == true){
		divList["previous"].style.display = "block";
		divList["next"].style.color = "#999999";
		divList["navSep"].style.display = "block";
	}else{
		divList["previous"].style.display = "none";
		divList["navSep"].style.display = "none";
	}
	if(pa == true){
		divList["previous"].innerHTML = "<a class='vd_navLinks' href='javascript:previous();'>previous</a>";


	}
	if(no == true){
		divList["next"].style.display = "block";
		divList["next"].style.color = "#999999";
		divList["next"].innerHTML = "next";
	}else{
		divList["next"].style.display = "none";
	}
	if(na == true){
		divList["next"].innerHTML = "<a class='vd_navLinks' href='javascript:next();'>next</a>";
	}

}

function previous()
{
	//wxtools.log("activeDrillDown " + activeDrillDow
		if(searchResultEndIndx > 10){
			searchResultEndIndx -=10;
			searchResultStartIndx = searchResultStartIndx > 10 ? searchResultStartIndx - 10 : 0;
		}
		else if (wxtools.keywordSearchResults )
		{
			searchResultEndIndx = wxtools.keywordSearchResults.titles.length > 5 ? 5 : wxtools.keywordSearchResults.titles.length
			searchResultStartIndx = 0;
		}
		foundItems();

		navButtons(false,false,false,false)
}

function next()
{
	if(activeDrillDown == "moreVideo"){
		moreForecast();
	}
	else if(activeDrillDown == "moreForecast"){
		moreVideo();
	}
	else wxtools.log("error in activate next");
}






function singleResult(theText){//wxtools.log(theText);
	navButtons(true,true,true,false);
	//divList["city_result_text"].style.display = "block";
	//divList["city_single_result"].innerHTML = "<br>The following forecasts are available for your location:<br><div id='resultItem'>1. <a href='javascript:recentSearchesTxt(true);' class='vd_other_link'>Atlanta Local Forecast</a></div><div id='resultItem'>2. <a href='javascript:recentSearchesTxt(true);' class='vd_other_link'>Southeast Regional Forecast Video</a></div><div id='resultItem'>3. <a href='javascript:recentSearchesTxt(true);' class='vd_other_link'>National Forecast Video</a></div><div id='resultItem'>4. <a href='javascript:recentSearchesTxt(true);' class='vd_other_link'>Severe Weather Outlook Video</a></div><br><br>";
	divList["city_bar_txt"].innerHTML = ""; //
	divList["city_result_set"].innerHTML = theText;
	divList["more_forecast_link"].style.display = "none";
	divList["more_videos_link"].style.display = "none";
	divList["other_result_set"].style.display = "none";
	divList["city_result_set"].style.display = "block";
	divList["other_bar"].style.display = "none";


}

function getLocalVideos(LocID)
{
	localSearchMgr.doLocIDSearch(LocID);
}

function getLocalVideoDiv(hash)
{
	cntr = 1;
	rtn = '<div id="city_result_text" style="display:block; margin:10px 0px 0px 0px;">The following forecasts are available for your location:</div>'
	var cityCode;

	for(var id in hash['v']){
		cityCode = hash['v'][id]['col']; //assign var to coll title
		rtn += '<div  id="resultItem' + cntr + '">' + space_three;
		rtn += '	<div class="vd_other_linkoff" onmouseover="this.className=\'vd_other_linkon\'" ';
		rtn += '        onmouseout="this.className=\'vd_other_linkoff\'" ';
		rtn += '		onClick="return playClip(\'' + cityCode + '\', \'' + hash['v'][id]['c'] + '\')"  style="margin:0px 0px 0px 10px;">' + cntr++ + ".";
		if (cntr.length == 1 )
		{
			rtn +=  space_three;
		}
		else
		{
			rtn +=  space_two;
		}
		rtn +=  hash['v'][id]['dn'] + '</div></div>';
	}

	return rtn;
}


//2 different error conditions can be returned, based on the condition, activate one of the div elements
function noResultsFound(error)
{
	noResultsFoundState();
	if(error == 1)
	{
		/*
		if (saf)
		{
			divList["someDIV"].innerHTML = "<b style='color:red;'>Can't connect to server.</b><p> Please try your search again later.";
			return;
		}
		*/
		divList["searchError"].innerHTML = "<b style='color:red;'>Can't connect to server.</b><p> Please try your search again later.";
	}
	if(error == 2)
	{
		if (saf)
		{
			divList["someDIV"].innerHTML = "<b style='color:red;'>No items found.</b><p>Please check your spelling or try another term.<p><b>Search Tips</b><br>Based on user feedback, we have compiled the following tips.<div id='searchError3'><ol><li> Check the spelling of the city name.</li><li> 	Make sure you are searching for a U.S. location; International VIDEO forecasts are not available at this time.</li><li> When you use two letter state codes, do not add periods to the code.<br>&nbsp;&nbsp;&nbsp;<b>Works</b> - Lexington NC<br>&nbsp;&nbsp;&nbsp;<b>Doesn't Work</b> - Lexington N.C.</li><li> Do not search using the city and the zip code.<br>&nbsp;&nbsp;&nbsp;<b>Works</b> - Atlanta or 30346<br>&nbsp;&nbsp;&nbsp;<b>Doesn't Work</b> - Atlanta 30346</li><li> Do not use 4 letter state codes. Use 2 letter codes.<br>&nbsp;&nbsp;&nbsp;<b>Works</b> - Cedar Hill TN<br>&nbsp;&nbsp;&nbsp;<b>Doesn't Work</b> - Cedar Hill TENN</li></ol></div>";
			return;
		}
		divList["searchError"].innerHTML = "<b style='color:red;'>No items found.</b><p>Please check your spelling or try another term.</p><br><p><b>Search Tips</b><br>Based on user feedback, we have compiled the following tips.</p><div id='searchError3'><ol><li> Check and make sure your spelling is correct.</li><li>If you still cannot find your video and would like help, <br>please <a href='mailto:epic@talk2.weather.com'>Email Us.</a></li></ol>"
/****************Removed by Steve Sherwood for Epic Player ******************************
		<p><b>Search Tips</b><br>Based on user feedback, we have compiled the following tips.<div id='searchError3'><ol><li> Check the spelling of the city name.</li><li> 	Make sure you are searching for a U.S. location; International VIDEO forecasts are not available at this time.</li><li> When you use two letter state codes, do not add periods to the code.<br>&nbsp;&nbsp;&nbsp;<b>Works</b> - Lexington NC<br>&nbsp;&nbsp;&nbsp;<b>Doesn't Work</b> - Lexington N.C.</li><li> Do not search using the city and the zip code.<br>&nbsp;&nbsp;&nbsp;<b>Works</b> - Atlanta or 30346<br>&nbsp;&nbsp;&nbsp;<b>Doesn't Work</b> - Atlanta 30346</li><li> Do not use 4 letter state codes. Use 2 letter codes.<br>&nbsp;&nbsp;&nbsp;<b>Works</b> - Cedar Hill TN<br>&nbsp;&nbsp;&nbsp;<b>Doesn't Work</b> - Cedar Hill TENN</li></ol></div>";
****************************************************************************************/
	}

}

function tryProcessingSearchResults ()
{
	//wxtools.log("tryProcessingSearchResults " + wxtools.a_processSearchResults);
/****************Removed by Steve Sherwood for Epic Player ******************************
	if( wxtools.a_processSearchResults == 2)
	{
		wxtools.a_processSearchResults = 0;
****************Removed by Steve Sherwood for Epic Player ******************************/
		//wxtools.log("reset wxtools.a_processSearchResults to " + wxtools.a_processSearchResults);
		foundItems();
		clearTimeout(cityTimeOutID);
		clearTimeout(otherTimeOutID);

/****************Removed by Steve Sherwood for Epic Player ******************************
	}
****************Removed by Steve Sherwood for Epic Player ******************************/
}


function foundItemsSafari()
{
	finishedSearchingState();

	if ( (!wxtools.keywordSearchResults || wxtools.keywordSearchResults.length == 0) && (!wxtools.localSearchResults || wxtools.localSearchResults['loc'].length == 0))
	{
		noResultsFound(2);
		return;
	}
	var totalResultsFound = wxtools.keywordSearchResults.titles.length + wxtools.localSearchResults['loc'].length;

	if (totalResultsFound > 0 )
	{
		//display total results
		divList["someDIV"] = totalResultsFound + " Search Results Found"// in BOLD
	}


	if (wxtools.localSearchResults['loc'].length > 0 )
	{
		divList["someDIV"].innerHTML =  wxtools.localSearchResults['loc'].length + " Forecast Videos Found";
	}

	for(var id in wxtools.localSearchResults['loc'])
	{
		rtn += '	<div class="vd_other_linkoff" onmouseover="this.className=\'vd_other_linkon\'" ';
		rtn += '        onmouseout="this.className=\'vd_other_linkoff\'" ';
		rtn += '		onClick="return getLocalVideos(\'' + wxtools.localSearchResults['loc'][id]['id'] + '\')" class="vd_other_link">' + space_three;
		rtn +=  space_two + trim( wxtools.localSearchResults['loc'][id]['locValue'] ) + ' - Forecast</div></div>';
	}

	if (wxtools.keywordSearchResults.titles.length > 0 )
	{
		divList["someDIV"].innerHTML =  wxtools.keywordSearchResults.titles.length + "Other Videos Found";
	}

	for(i=0;i < wxtools.keywordSearchResults.titles.length;i++)
	{
		rtn += '<div id="resultItem' + cntr + '">';
		rtn += '	<div class="vd_other_linkoff" onmouseover="this.className=\'vd_other_linkon\'" ';
		rtn += '        onmouseout="this.className=\'vd_other_linkoff\'"  ';
		rtn += '		onClick="return playClip(\'' + wxtools.keywordSearchResults.titles[i]["ColID"] + '\',\'' + wxtools.keywordSearchResults.titles[i]["ClipID"] + '\')" class="vd_other_link">' + space_three + cntr++ + ".";
		rtn += space_two + trim( wxtools.keywordSearchResults.titles[i]["Name"] ) + '</div></div>';
	}

	divList["someDIV"].innerHTML =  wxtools.keywordSearchResults.titles.length + "Other Videos Found";

	wxtools.haveKeywordResults == false;
	wxtools.haveLocalResults == false;

}

function recentSearchResultsDisplay()
{
	document.getElementById("searchIframe").style.display="block";
	document.getElementById("searchResultsContainer").style.display="block";
	wxtools.haltAutoPlay = true;
	foundItems();
}

function foundItems()
{
	wxtools.log("foundItems()");
	/*
	if(saf)
	{
		foundItemsSafari();
		return;
	}
	*/
	document.getElementById("searchTitle").innerHTML = "Your Search: <b>"+wxtools.searchingFor+"</b>";
	finishedSearchingState();
	recentSearchState(true);

	if ( (!wxtools.keywordSearchResults || wxtools.keywordSearchResults.length == 0) && (!wxtools.localSearchResults || wxtools.localSearchResults['loc'].length == 0))
	{
		noResultsFound(2);
		return;
	}

	if (wxtools.haveKeywordResults == true)
	{
		//wxtools.log("haveKeywordResults");

		//use this if user is constantly searching fast as they can. We cannot stop each BC search
		//from returning, so it will cause certain variables to be assigned incorrectly due to this
		//nonsynchronous search. so if keywordSearchResults is null, gently dont do anything.
		if (wxtools.keywordSearchResults)
		{
			//wxtools.log("length is " + wxtools.keywordSearchResults.titles.length);
			var groupInterval = 5;
			//if no local results, display full 10
			if ( wxtools.haveLocalResults == false )
			{
				groupInterval = 17;
			}
			if (wxtools.keywordSearchResults.length == 0)
			{
				divList["city_bar"].style.display = "none";
			}
			else
			{

				wxtools.keywordResultsTempLimit = (wxtools.keywordSearchResults.titles.length > groupInterval )?groupInterval:wxtools.keywordSearchResults.titles.length;
				divList["other_bar_txt"].innerHTML =  "1 - " + wxtools.keywordResultsTempLimit + " of " + wxtools.keywordSearchResults.titles.length + " Videos";
			}

			divList["other_result_set"].innerHTML = createOtherSearchResultDiv();

			//modify this when local search is done..
			finishedSearchingStateKeywordsFound();
			if(wxtools.keywordSearchResults.titles.length > groupInterval)
			{
				divList["more_videos_link"].style.display = "block";
			}

			wxtools.haveKeywordResults == false;
		}

	}
	else
	{
		//wxtools.log("trying to hide other bar");
		divList["other_bar"].display = "none";
	}


	if (wxtools.haveLocalResults == true)
	{
		//wxtools.log("haveLocalResults");
		wxtools.localSearchResults
		wxtools.localResultsIndex = 0;
		wxtools.localSearchResultsReturned = wxtools.localSearchResults['loc'].length;
		var groupInterval = 5;
		if (wxtools.haveKeywordResults == false)
		{
			groupInterval = 10;
		}
		//wxtools.log("length is " + wxtools.localSearchResults['loc'].length);
		if (wxtools.localSearchResults['loc'].length == 0)
		{
			divList["other_bar"].style.display = "none";
		}
		else
		{
			wxtools.localResultsTempLimit = (wxtools.localSearchResults['loc'].length > groupInterval )?groupInterval:wxtools.localSearchResults['loc'].length;
			divList["city_bar_txt"].innerHTML =  "1 - " + wxtools.localResultsTempLimit + " of " + wxtools.localSearchResults['loc'].length + " Forecast Videos";
		}

		divList["city_result_set"].innerHTML = createLocalSearchResultsDiv();

		finishedSearchingStateCityFound();


		if(wxtools.localSearchResults['loc'].length > groupInterval)
		{
			divList["more_forecast_link"].style.display = "block";
		}

		wxtools.haveLocalResults == false;
		//wxtools.log("finishedLocalResults");
	}
	else
	{
		divList["city_bar"].style.display = "none";
		divList["city_result_set"].style.display = "none";
	}

}

function createLocalSearchResultsDiv()
{
	var cntr = 1;
	var rtn = '<div>';
	for(var id in wxtools.localSearchResults['loc'])
	{
		if ( cntr <= wxtools.localResultsTempLimit)
		{
			rtn += '	<div class="vd_other_linkoff" onmouseover="this.className=\'vd_other_linkon\'" ';
			rtn += '        onmouseout="this.className=\'vd_other_linkoff\'" ';
			rtn += '		onClick="return getLocalVideos(\'' + wxtools.localSearchResults['loc'][id]['id'] + '\')" class="vd_other_link">' + space_three + cntr++ + ".";
			rtn +=  space_two + trim( wxtools.localSearchResults['loc'][id]['locValue'] ) + ' - Forecast</div></div>';
		}
	}

	rtn += '</div>';
	return rtn;
}

//who removes forecast clips???  I will do for now, but need to figure out calculation for total clips.
function createOtherSearchResultDiv(){
	var cntr = 1;
	var foundMatch = false;
	rtn = '<div>';
	for(i=0;i < wxtools.keywordSearchResults.titles.length;i++)
	{
		if ( cntr <= wxtools.keywordResultsTempLimit)
		{
		/* filtering dups forecasts..tbd
			for(var id in wxtools.localSearchResults['loc'])
			{
				wxtools.log("comparing " + wxtools.keywordSearchResults.titles[i]["Name"] + " and " + wxtools.localSearchResults['loc'][id]['locValue']  )
				if (trim(wxtools.keywordSearchResults.titles[i]["Name"]) == trim( wxtools.localSearchResults['loc'][id]['locValue'] ) )
				{
					foundMatch == true;
				}
			}

			if( foundMatch == false)
			{
					rtn += '<div id="resultItem' + cntr + '" style="margin:10px 0px 10px 0px;">' + space_three + '<a href = "#" onClick="return playClip(\'' + wxtools.keywordSearchResults.titles[i]["ColID"] + '\',\'' + wxtools.keywordSearchResults.titles[i]["ClipID"] + '\')" class="vd_other_link">' + cntr++ + ".";
					rtn += space_two + trim( wxtools.keywordSearchResults.titles[i]["Name"] ) + '</a></div>';
			}
			*/
			rtn += '<div id="resultItem' + cntr + '">';
			rtn += '	<div class="vd_other_linkoff" onmouseover="this.className=\'vd_other_linkon\'" ';
			rtn += '        onmouseout="this.className=\'vd_other_linkoff\'"  ';
			rtn += '		onClick="return playClip(\'' + wxtools.keywordSearchResults.titles[i]["ColID"] + '\',\'' + wxtools.keywordSearchResults.titles[i]["ClipID"] + '\')" class="vd_other_link">' + space_three + cntr++ + ".";
			rtn += space_two + trim( wxtools.keywordSearchResults.titles[i]["Name"] ) + '</div></div>';

		}
	}
	return rtn;
}

function moreForecast()
{
	divList["city_bar_txt"].innerHTML = "1 - " + wxtools.localSearchResults['loc'].length + " of " + wxtools.localSearchResults['loc'].length + " Forecast Videos";
	divList["more_forecast_link"].style.display = "none";
	divList["more_videos_link"].style.display = "none";
	divList["other_result_set"].style.display = "none";
	wxtools.localResultsTempLimit = wxtools.localSearchResults['loc'].length;
	divList["city_result_set"].innerHTML = createLocalSearchResultsDiv();
	divList["other_bar"].style.display = "none";
	activeDrillDown = "moreForecast";
	navButtons(true,true,true,wxtools.localSearchResults['loc'].length > wxtools.localResultsTempLimit ? true:false);
}

function moreVideo(){
	divList["other_bar_txt"].innerHTML = "1 - " + wxtools.keywordSearchResults.titles.length + " of " + wxtools.keywordSearchResults.titles.length + " Videos";
	divList["more_forecast_link"].style.display = "none";
	divList["more_videos_link"].style.display = "none";
	wxtools.keywordResultsTempLimit = wxtools.keywordSearchResults.titles.length;
	divList["other_result_set"].innerHTML = createOtherSearchResultDiv();
	divList["city_result_set"].style.display = "none";
   	divList["city_bar"].style.display = "none";
   	activeDrillDown = "moreVideo";
	navButtons(true,true,true,wxtools.keywordSearchResults.titles.length > wxtools.keywordResultsTempLimit ? true:false);

	searchResultStartIndx = 0;

	}


function startedSearchingState()
{
	/*if(saf)
	{
		divList["msg_data"].style.display = "block";
		return;
	}
	*/

	document.getElementById("searchIframe").style.display="block";
	//document["searchIframe"].style.display="block";

	document.getElementById("searchResultsContainer").style.display="block";
	//divList["searchResultsContainer"].style.display="block"; /* commented out MEA 10/19 for test */

    document.getElementById("searchTitle").style.display="none";
	//divList["searchTitle"].style.display="none";

	document.getElementById("msg_data").style.display = "block";
	//divList["msg_data"].style.display = "block";

	divList["city_bar"].style.display="none";
	divList["other_bar"].style.display="none";
	divList["city_bar_txt"].innerHTML  = "";
	divList["city_result_set"].innerHTML = "";
	divList["other_result_set"].innerHTML = "";
	divList["other_bar_txt"].innerHTML  = "";
	divList["flashSearching"].style.display="block";
	divList["closeContainer"].style.display="block";
	divList["fullResultSet"].style.display="none";
	navButtons(false,false,false,false);
	divList["searchError"].style.display="none";

/****************Removed by Steve Sherwood for Epic Player ******************************

	if (ie5xwin && ieVersion < 7 )
	{
		if (wxtools.playerID == "823425597")
		{
			divList["channelSelectorDisabled"].style.background = "url(http://ima.weather.com/web/interact/bluebox/newsbreaking_dropdown.gif)";
		}
		else if (wxtools.playerID == "824514779")
		{
			divList["channelSelectorDisabled"].style.background = "url(http://ima.weather.com/web/interact/bluebox/localforecast_dropdown.gif)";
		}
		else if (wxtools.playerID == "824720679")
		{
			divList["channelSelectorDisabled"].style.background = "url(http://ima.weather.com/web/interact/bluebox/lifestyle_dropdown.gif)";
		}
		else if (wxtools.playerID == "824250742")
		{
			divList["channelSelectorDisabled"].style.background = "url(http://ima.weather.com/web/interact/bluebox/severeweather_dropdown.gif)";
		}
		else if (wxtools.playerID == "823503751")
		{
			divList["channelSelectorDisabled"].style.background = "url(http://ima.weather.com/web/interact/bluebox/ontwc_dropdown.gif)";
		}
		divList["channelSelectorDisabled"].style.backgroundRepeat ="no-repeat";

		divList["channelSelectorDisabled"].style.display = "block";
		divList["channelSelector"].style.display = "none";

	}

****************Removed by Steve Sherwood for Epic Player ******************************/



}


function finishedSearchingState()
{
	if (wxtools.adIsPlaying == true)
	{
		adIsPlayingState();
		divList["flashSearching"].style.display="none";
		return;
	}
	divList["searchTitle"].style.display="block";
	divList["msg_data"].style.display = "none";
	divList["more_videos_link"].style.display = "none";
	divList["more_forecast_link"].style.display = "none";
	divList["closeContainer"].style.display="block";
	divList["flashSearching"].style.display="none";
	divList["fullResultSet"].style.display="block";
	divList["foundResultSet"].style.display="block";

/****************Removed by Steve Sherwood for Epic Player ******************************
	divList["channelSelectorDisabled"].style.display = "none";
	divList["channelSelector"].style.display = "block";
****************Removed by Steve Sherwood for Epic Player ******************************/


}

function finishedSearchingStateCityFound()
{
	divList["city_result_set"].style.display = "block";
	divList["city_bar"].style.display = "block";
	divList["city_bar_txt"].style.display = "block";

/****************Removed by Steve Sherwood for Epic Player ******************************
	divList["channelSelectorDisabled"].style.display = "none";
	divList["channelSelector"].style.display = "block";
****************Removed by Steve Sherwood for Epic Player ******************************/
}


function finishedSearchingStateKeywordsFound()
{
	divList["other_result_set"].style.display = "block";
	divList["other_bar"].style.display = "block";
	divList["other_bar_txt"].style.display = "block";

/****************Removed by Steve Sherwood for Epic Player ******************************
	divList["channelSelectorDisabled"].style.display = "none";
	divList["channelSelector"].style.display = "block";
****************Removed by Steve Sherwood for Epic Player ******************************/
}

function noResultsFoundState()
{
/*
	if(saf)
	{
		//do something to text area
		return;
	}
	*/
	divList["searchError"].style.display="block";
/****************Removed by Steve Sherwood for Epic Player ******************************
	divList["topInfo"].style.display = "block";
****************Removed by Steve Sherwood for Epic Player ******************************/
	divList["searchTitle"].style.display="none";
	divList["closeContainer"].style.display = "block";
	divList["flashSearching"].style.display="none";
	divList["searchTitle"].style.display="block";
	divList["foundResultSet"].style.display="none";
	adIsDonePlayingState();
}

function playingClipState()
{
	document.getElementById("searchIframe").style.display="none";
	divList["searchResultsContainer"].style.display="none";
	divList["msg_data"].style.display = "none";
	divList["flashSearching"].style.display="none";
	divList["closeContainer"].style.display="none";
	divList["fullResultSet"].style.display="none";
	navButtons(false,false,false,false);
	divList["searchError"].style.display="none";
}

//once a search is done, turn this on
function recentSearchState(n){
	if (n != false){
		divList["recentSearchText"].style.display="block";
	}else{
		divList["recentSearchText"].style.display="none";
	}
}

function resetContainer(n){
	//turns main search container on and off
	if(n == true){
		divList["searchResultsContainer"].style.display="none";
		document.getElementById("searchIframe").style.display="none";
		divList["msg_data"].style.display = "none";//testing rob
		divList["city_bar"].style.display = "none";//testing rob
		divList["other_bar"].style.display = "none";//testing rob
		divList["city_bar_txt"].innerHTML = "";
		divList["city_result_set"].innerHTML = "";
		divList["other_result_set"].innerHTML = "";
		divList["other_bar_txt"].innerHTML  = "";


	}else{
		divList["searchResultsContainer"].style.display="block";
		document.getElementById("searchIframe").style.display="block";
	}

	if (wxtools.adIsPlaying == true)
	{
		adIsPlayingState();
	}
}



var WxVideoSearch = wxtools1.WxVideoSearch;

