var queryStr = new String(window.location.search);
queryStr = queryStr.substr(1)+"&location="+window.location+"&config=config/properties.xml";

/**
 * Embed the player.
 * 
 * mode - The player mode. "single or "lineup"
 * title - The default title id to load. If there's a query string of 'bctid', then it will be used to override default one.
 * lineup = The default lineup id to load. If there's a query string of 'bctid' then it will be used to override default one.
 */
function createPlayer(height, query)
{
	query = query.replace("lineup", "bclid");
	query = query.replace("title", "bctid");
	var so = new SWFObject("loader.swf?"+query, "adageVideoPlayer", "687", height, "8", "#ffffff");
	so.addParam("allowScriptAccess", "always");
	so.useExpressInstall('expressinstall.swf');	
	so.addParam("salign", "t");
	so.addParam("menu", "false");
	so.addParam("FlashVars", query);
	so.write("adage_player");
}

/**
 * Create a single title player.
 * 
 * titleId - The default title ID to load
 */
function createSinglePlayer(titleId)
{
	queryStr += "&player_mode=single&titleId="+titleId;
	createPlayer(575, queryStr);
}

/**
 * Create a lineup player.
 *
 * lineupId - The lineup ID to load
 * titleId (optional) - The default title to play when the player loads. It's recommended that this title is part of the lineupId.
 */
function createLineupPlayer(lineupId, titleId)
{
	queryStr += "&player_mode=lineup&lineupId="+lineupId;
	
	if (titleId != undefined) 
		queryStr += "&titleId="+titleId;
		
	createPlayer(665, queryStr);	
	
	//document.title = "Ad Age Lineup Player";
}

/**
 * Returns the embedded flash object
 */
function getFlashMovie()
{
	if (navigator.appName.indexOf("Microsoft") != -1)
		return window["adageVideoPlayer"];
	else
		return document["adageVideoPlayer"]
}

/**
 * Track media play when a video starts
 */
function hbxMediaPlay(hbxFileName) 
{
	_hbSet('m.f',hbxFileName);
	_hbSet('m.s','play');
	_hbSet('m.cl','Flash Player');
	_hbSet('m.tt','e');
	_hbSend();
}

/**
 * Track media stop when a video is complete 
 */
function hbxMediaStop(hbxFileName, hbxCurrentPos) 
{
	_hbSet('m.f',hbxFileName);
	_hbSet('m.cp',hbxCurrentPos);
	_hbSet('m.s','stop');
	_hbSet('m.cl','Flash Player');
	_hbSet('m.tt','e');
	_hbSend();
}

/**
 * Send tracking information when the user clicks on Home, Latest News, or More Video from the player
 */
function hbxTrackPageView(name, url) 
{
	_hbPageView(name, url);
}

/**
 * Used in conjunction with the function hbxTrackPageView to open the URL under the popup
 */
function openWindow(url) 
{
	if (window.opener == null)
		window.open(url, '_new', 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width='+screen.width+',height='+screen.height+',left=0,top=0');	
	else
		opener.location = url;
}

/**
 * Call the flash player to track unload
 */
window.onunload = function() 
{
	getFlashMovie().trackUnload();
}

/**
 * Called by the player to track user's behavior
 */
function hbxTrackUniqueUser(username, time, videos) 
{
	_hbSet('c1',username);
	_hbSet('c2',time);
	_hbSet('c3',videos);
	_hbSend();
}

/**
 * Call this function from anywhere on the site to open the popup centered.
 */
function openVideo(url, w, h) {
	var center = (screen.width - w)/2;
	var middle = (screen.height - h)/2;
	window.open(url, 'parent', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width='+w+',height='+h+',left='+center+',top='+middle);	
}

function onFSCommand() 
{
}