//////////////////////////////////////////////////////////
//                                                      //
//      Red Queen Integration of Wimpy AV Player        //
//      by Stephen Carter <stephen@randommouse.com>     //
//      http://www.randommouse.com/redqueen/            //
//      (c) 2006                                        //
//                                                      //
//////////////////////////////////////////////////////////

/*
   =====================================================================
   THIS SECTION WORKS IN CONJUNCTION WITH RED QUEEN CONFIGURATION PAGES.
   DO NOT EDIT. INSTEAD MAKE CHANGES FROM Configure > Wimpy Player
   =====================================================================
*/

var av_wimpySwf = "http://www.digigirlslibrary.com/rs/other/wimpy/wimpy_av/wimpyAV.swf";

var av_wimpyPHP = "";
var av_wimpyWidth = "320";
var av_wimpyHeight = "260";
var av_startPlayingOnload = "no";
var av_randomOnLoad = "no";
var av_randomButtonState = "off";
var av_getMyid3info = "";
var av_videoSmoothing = "no";
var av_displayDownloadButton = "no";
var av_popUpHelp = "yes";
var av_infoDisplayTime	= "6";
var av_theVolume = "50";
var av_controllocation = "top";	// top, bottom
var av_autoAdvance = "no";
var av_videoDeblocking = "";

var av_backgroundColor = "#000000";

var av_wimpyConfigFile = '';

// =====================================================================

var randNumAv = (Math.round((Math.random()*1000000)+1));

function makeWimpyAVPlayer(av_thePlaylist)
{
	av_thePlaylist = av_thePlaylist || '';
	var newlineChar = "\n";
	var backgroundColor = av_backgroundColor;
	var tptBkgd_param;
	var tptBkgd_embed;
	var writePlaylist;
	var altString;
	var queryString;
	var flashCode = '';
	var flashVersion = "7,0,0,0";

	if( ! backgroundColor )
	{
		backgroundColor = "000000";
		tptBkgd_param = '<param name="wmode" value="transparent" />'+newlineChar;
		tptBkgd_embed = 'wmode="transparent" ';
	} else {
		if(backgroundColor.substring(0,1) == "#"){
			backgroundColor = backgroundColor.substring(1,backgroundColor.length)
		}
		tptBkgd_param = "";
		tptBkgd_embed = "";
	}

	var myConfigs	= "backgroundColor,startPlayingOnload,randomOnLoad,randomButtonState,getMyid3info,"
			+ "videoSmoothing,displayDownloadButton,popUpHelp,infoDisplayTime,theVolume,"
			+ "controllocation,autoAdvance,videoDeblocking";
	var AmyConfigs = myConfigs.split(",");
	var AprintConfigs = Array();
	for(i=0;i<AmyConfigs.length;i++){
		if(eval('av_'+AmyConfigs[i]) != "")
		{
			// create a query string of all non-null parameters defined at the top of this file
			AprintConfigs[AprintConfigs.length] = AmyConfigs[i]+"="+eval('av_'+AmyConfigs[i]);
		}
	}
	myConfigs = AprintConfigs.join("&");
	randNumAv++;

	if(av_thePlaylist){
		if( av_getExtension(av_thePlaylist) == "xml" ){
			// bypass the Wimpy php, asp, or cfm script
			writePlaylist = "&forceXMLplaylist=yes&wimpyApp="+av_thePlaylist;
		} else {
			writePlaylist = "&playlist="+av_thePlaylist;
		}
	} else {
		writePlaylist = '&wimpyApp=' + av_wimpyPHP;
	}
	if(av_wimpyConfigFile.length > 4)
	{
		// read configuration wariables from XML config file
		altString = '&wimpyConfigs='+av_wimpyConfigFile;
	} else {
		// use those specified at the top of this script
		altString = "&"+myConfigs;
	}

	queryString = av_wimpySwf +'?'+altString+writePlaylist;

	flashCode += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+flashVersion+'" width="'+av_wimpyWidth+'" height="'+av_wimpyHeight+'" name="wimpy'+randNumAv+'" id="wimpy'+randNumAv+'" align="middle">'+newlineChar;
	flashCode += '<param name="movie" value="'+queryString+'" />'+newlineChar;
	flashCode += '<param name="allowScriptAccess" value="sameDomain" />'+newlineChar;
	flashCode += '<param name="loop" value="false" />'+newlineChar;
	flashCode += '<param name="menu" value="false" />'+newlineChar;
	flashCode += '<param name="quality" value="high" />'+newlineChar;
	flashCode += '<param name="scale" value="noscale" />'+newlineChar;
	flashCode += '<param name="salign" value="lt" />'+newlineChar;
	flashCode += '<param name="bgcolor" value="'+backgroundColor+'" />'+newlineChar;
	flashCode += tptBkgd_param;
	flashCode += '<embed src="'+queryString+'" width="'+av_wimpyWidth+'" height="'+av_wimpyHeight+'" bgcolor="'+backgroundColor+'" loop="false" menu="false" quality="high" scale="noscale" salign="lt" name="wimpy'+randNumAv+'" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" '+tptBkgd_embed+' /></object>'+newlineChar;
	document.write(flashCode);
	// Uncomment to trouble shoot the HTML code.
	//document.write('<div id="seeCode"><textarea name="textarea" id="textarea" cols="120" rows="15" wrap="VIRTUAL">'+flashCode+'</textarea></div>');

}

function av_getExtension(theFilename){
	// return the lowercased file extension, e.g. '/path/to/video.SWF' => 'swf'
	return unescape(theFilename).split("/").pop().split(".").pop().toLowerCase();
}
