var documentWrite = document.write;
var documentWriteLn = document.writeln;
var embedSrc;

function captureWrites ( )
{
	embedSrc = '';
	document.write = function ( string ) { embedSrc += string; };
	document.writeln = function ( string ) { embedSrc += string + "\n"; };
}

function releaseWrites ( )
{
	document.write = documentWrite;
	document.writeln = documentWriteLn;
	document.write ( embedSrc );
	embedSrc = '';
}

// Used by scaling movies.
//

function getMovieContainerDimensions ( )
{
	var dimensions = new Object ( );
	
	if ( window.innerWidth )
	{
		dimensions.width = window.innerWidth;
		dimensions.height = window.innerHeight;
	}
	else if ( document.all )
	{
		dimensions.width = document.body.clientWidth;
		dimensions.height = document.body.clientHeight;
	}
	
	// Weirdness. FF3 on one Mac was reporting a window size larger than the
	// available screen size?
	//
	
	if ( dimensions.width > screen.availWidth )
	{
		dimensions.width = screen.availWidth;
	}
	
	if ( dimensions.height > screen.availHeight )
	{
		dimensions.height = screen.availHeight;
	}
	
	if ( dimensions.width < 960 )
	{
		dimensions.width = 960;
	}
	
	if ( dimensions.height < 575 )
	{
		dimensions.height = 575;
	}
	
 	return dimensions;
}

// Extract and return any content id from our url.
//

function getContentId ( )
{
	return paramValue ( 'cid', null );
}

// http://www.quirksmode.org/
//
// Use with care as focus ( ) in a tabbed browser will not bring the tab to 
// the forefront.
//

var externalWindow = null;

function getExternalUrl ( url ) 
{
	if ( externalWindow != null && ! externalWindow.closed && externalWindow.location ) 
	{
		externalWindow.close ( );
	}
	
	externalWindow = window.open ( url, 'external', "toolbar=yes, location=yes, status=yes, menubar=yes, scrollbars=yes, resizable=yes, copyhistory=yes" );
	
	if ( ! externalWindow.opener )
	{
		externalWindow.opener = self;
	}
}

// If CoreMetrics not found then enable debugging calls.
//

if ( typeof cmCreatePageviewTag == "undefined" )
{
	cmCreatePageviewTag = function ( param1, param2, param3 ) { log ( "cmCreatePageviewTag: " + param1 + ', ' + param2 + ', ' + param3 ); }
	cmCreateManualLinkClickTag = function ( param1, param2, param3 ) { log ( "cmCreateManualLinkClickTag: " + param1 + ', ' + param2 + ', ' + param3 ); }
	
	// http://ajaxcookbook.org/javascript-debug-log/
	//
	
//function log(message) {
//		if (!log.window_ || log.window_.closed) {
//			var win = window.open("", null, "width=400,height=200," +
//							  "scrollbars=yes,resizable=yes,status=no," +
//							  "location=no,menubar=no,toolbar=no");
//			if (!win) return;
//			var doc = win.document;
//			doc.write("<html><head><title>Debug Log</title></head>" +
//					  "<body></body></html>");
//			doc.close();
//			log.window_ = win;
//		}
//		var logLine = log.window_.document.createElement("div");
//		logLine.appendChild(log.window_.document.createTextNode(message));
//		log.window_.document.body.appendChild(logLine);
//	}
}

// Get the url of the calling file
function pageURL ( )
{
	var url = location.href;
	return url.replace ( /^([^?#]+).*$/, "$1" );
}
