function swapPlayer(playerID)
{
	wxtools.playerID = playerID;
	wxtools.searchingFor = document.getElementById('searchText').value;
	wxtools.isSwappingPlayer = true;
	resetContainer(true);
	adIsPlayingState();
	wxtools.userInitiated = true;
	wxtools.haltAutoPlay = false;
	wxtools.previousClipID = wxtools.clipID;
	
	//get Player Information
	wxtools.playerInfo = getPlayerInfoByPid(playerID);
	activePlayerID = wxtools.playerInfo[0];
	
	if (wxtools.dataHash) 
	{
		for (var i=0;i<wxtools.dataHash.length;i++) 
		{
			if (wxtools.dataHash[i]["pid"] == activePlayerID) 
			{
				wxtools.log("Found the playerID.");
				wxtools.collectionID = wxtools.dataHash[i]["c"][0]["cid"];
				wxtools.lineupRefName = wxtools.dataHash[i]["c"][0]["tid"];
				wxtools.log("Setting the collectionId to "+wxtools.dataHash[i]["c"][0]["cid"]+".");
				break;
			}
		}
	}
	if (wxtools.coll2ClipHash) 
	{
		if (null != wxtools.collectionID) 
		{
			wxtools.clipID = wxtools.coll2ClipHash[wxtools.collectionID][0];
			wxtools.log("Setting the clipId to " + wxtools.clipID);
		}
	}
	
	
	config["videoRef"] = wxtools.clipID;
	config["lineupRef"] = wxtools.collectionID;
	config["lineupRefName"] = wxtools.lineupRefName;		
	config["autoStart"] = false; //tells the player to start playing video on load
	config["preloadBackColor"] = wxtools.playerInfo[2];
	config["continuousPlay"] = "false";
	config["playerId"] = activePlayerID;
	config["width"] = 988;
	config["height"] = 550;
	config["adServerURL"] = wxtools.playerInfo[1];
	
	
	//set the correct CSS
	var z = document.styleSheets.length;
	if(!saf)
	{
		for(var i=1;i<z;i++)
		{
			if(document.styleSheets[i].title != activePlayerID )
			{
				document.styleSheets[i].disabled=true;
			}
			else
			{
				document.styleSheets[i].disabled=false; 							
			}
		}
	}
	//fix for safari css calls
	if(saf)
	{
		var newCSS = "";
		if (activePlayerID == "823425597")
		{
			newCSS = 'http://ima.weather.com/common/stylesheet/verticals/bb_news.css';
		}
		else if (activePlayerID == "824514779")
		{
			newCSS = 'http://ima.weather.com/common/stylesheet/verticals/bb_forecasts.css';
		}	
		else if (activePlayerID == "824720679")
		{
			newCSS = 'http://ima.weather.com/common/stylesheet/verticals/bb_lifestyle.css';
		}
		else if (activePlayerID == "824250742")
		{
			newCSS = 'http://ima.weather.com/common/stylesheet/verticals/bb_severe.css';
		}
		else if (activePlayerID == "823503751")
		{
			newCSS = 'http://ima.weather.com/common/stylesheet/verticals/bb_ontwc.css';
		} 
		
		var head = document.getElementsByTagName('head')[0];
	    var newElement = document.createElement('link');
	 	newElement.rel = 'stylesheet';
	 	newElement.href = newCSS;
	 	head.appendChild(newElement);
	}	

	//keep whatever was in search window.
	document.getElementById('searchText').value = wxtools.searchingFor;
	
	callFlash("loadPlayer", config);
	
	includePromoModule(wxtools.playerID);
}


function isLocalRegCollection(collection)
{	
		return collection == "regwxforecast" || collection == "localwxforecast" ? true : false;
}
	
	
function getPlayerInfoByPid(pid)
{
	for(var pidIndex = 0; pidIndex < wxtools.dataHash.length; pidIndex++)
	{			
		if(wxtools.dataHash[pidIndex]['pid'] == pid)
		{
			return [wxtools.dataHash[pidIndex]['pid'],wxtools.dataHash[pidIndex]['as'],wxtools.dataHash[pidIndex]['bg'],wxtools.dataHash[pidIndex]['c'][0]['cid']];
		}
	}
	return null;
}

function getPlayerInfoByCol(col)
{
	for(var pidIndex = 0; pidIndex < wxtools.dataHash.length; pidIndex++)
	{			
		for(var cidIndex = 0; cidIndex < wxtools.dataHash[pidIndex]['c'].length; cidIndex++)
		{				
			if(wxtools.dataHash[pidIndex]['c'][cidIndex]['cid']== col)
			{					
				return [wxtools.dataHash[pidIndex]['pid'],wxtools.dataHash[pidIndex]['as'],wxtools.dataHash[pidIndex]['bg'],wxtools.dataHash[pidIndex]['c'][cidIndex]['cid'],wxtools.dataHash[pidIndex]['c'][cidIndex]['t']];
			}
		}
	}
	return null;
}

function getCollectionIdUsingTitleID(atid)
{
	for(var pidIndex = 0; pidIndex <  wxtools.dataHash.length; pidIndex++){			
		for(var cidIndex = 0; cidIndex <  wxtools.dataHash[pidIndex]['c'].length; cidIndex++){				
			if( wxtools.dataHash[pidIndex]['c'][cidIndex]['tid']== atid){					
				return  wxtools.dataHash[pidIndex]['c'][cidIndex]['cid'];
			}
		}
	}
	return null;
}

function getVideo2LocalCollectionCode(clipID)
{
	var collection_id =  wxtools.clip2CollHash[clipID];
	if (collection_id) 
	{
		return collection_id;
	}
	return null;
}




function initialState()
{
	//currently not using but may need to swap channel swapper image
	adIsPlayingState();	
}

function adIsPlayingState()
{	
	divList["msg_data"].style.display = "block";
	
	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";	
		
	}
	
	if (wxtools.playerID == "823425597")
	{
		document.getElementById("promo_mask_news_promo").style.display = "block";
	}
	else if (wxtools.playerID == "824514779")
	{
		document.getElementById("promo_mask_forecasts_promo").style.display = "block";
	}
	else if (wxtools.playerID == "824720679")
	{
		document.getElementById("promo_mask_lifestyle_promo").style.display = "block";
	}
	else if (wxtools.playerID == "824250742")
	{
		document.getElementById("promo_mask_severe_promo").style.display = "block";
	}
	else if (wxtools.playerID == "823503751")
	{
		document.getElementById("promo_mask_ontwc_promo").style.display = "block";
	} 
	
}

function adIsDonePlayingState()
{
	divList["msg_data"].style.display = "none";	
	divList["channelSelectorDisabled"].style.display = "none";	
	divList["channelSelector"].style.display = "block";	
	
	if (wxtools.playerID == "823425597")
	{
		document.getElementById("promo_mask_news_promo").style.display = "none";
	}
	else if (wxtools.playerID == "824514779")
	{
		document.getElementById("promo_mask_forecasts_promo").style.display = "none";
	}
	else if (wxtools.playerID == "824720679")
	{
		document.getElementById("promo_mask_lifestyle_promo").style.display = "none";
	}
	else if (wxtools.playerID == "824250742")
	{
		document.getElementById("promo_mask_severe_promo").style.display = "none";
	}
	else if (wxtools.playerID == "823503751")
	{
		document.getElementById("promo_mask_ontwc_promo").style.display = "none";
	} 
	
	
}


function includePromoModule(playerID)
{
	/*
	resetPromoItems();
	if (playerID == "823425597")
	{
		document.getElementById("news_promo").style.display = "block";
		return;
		
	}
	else if (playerID == "824514779")
	{
		document.getElementById("forecasts_promo").style.display = "block";
		return;
	}
	else if (playerID == "824720679")
	{
		document.getElementById("lifestyle_promo").style.display = "block";
		return;
	}
	else if (playerID == "824250742")
	{
		document.getElementById("severe_promo").style.display = "block";
		return;
	}
	else if (playerID == "823503751")
	{
		document.getElementById("ontwc_promo").style.display = "block";
		return;
	}
	*/ 
					
}

function resetPromoItems(){
/*
	//turns off promo elements
	document.getElementById("news_promo").style.display = "none";
	document.getElementById("forecasts_promo").style.display = "none";
	document.getElementById("lifestyle_promo").style.display = "none";
	document.getElementById("severe_promo").style.display = "none";
	document.getElementById("ontwc_promo").style.display = "none";
	*/
}

