	
// -------------------------------------------------------------------------------------------------
// COOKIE CODE 
// -------------------------------------------------------------------------------------------------

function timestamp() {
    return parseInt((new Date).getTime()/1e3);
}

function getCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ';', len );
	if ( end == -1 ) end = document.cookie.length;
	
	return unescape( document.cookie.substring( len, end ) );
}

function setCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}

	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name+'='+escape( value ) +
		( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString()
		( ( path ) ? ';path=' + path : '' ) +
		( ( domain ) ? ';domain=' + domain : '' ) +
		( ( secure ) ? ';secure' : '' );
}

function deleteCookie( name, path, domain ) {
	if ( getCookie( name ) ) document.cookie = name + '=' +
			( ( path ) ? ';path=' + path : '') +
			( ( domain ) ? ';domain=' + domain : '' ) +
			';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}


// -------------------------------------------------------------------------------------------------
// CODE FOR MEDIA PLAYER 
// -------------------------------------------------------------------------------------------------

// Global Variables
/*
var URL='';
var state=0;
var position=0.0;
var player=null; //wmplayer
var p=null; //wmplayer.player
var width = 356;
var height = 339;
*/


// global API variable for the player
var api
var sErrorClip = 'http://downloads.cbn.com/onecubedplayer/images/onecubed_video_unavailable_med.jpg';
var iErrorDuration = 30;

function onStreamNotFound(clip) {
	// load error slate
	api.playClip( { url: sErrorClip, duration: iErrorDuration } );
}

function play_jukebox_video() {
	onClipDone(null);
}

function onClipDone(clip) {
	// load One Cubed Juke Box
	
	var aNextVideo;
	var sURL = "mediaplayer_jukebox.php";
	// retrieve next video to play
	new Ajax.Request(sURL, 
	{ 
		method:'get', 
		onSuccess: function(transport){ 
		   // 		alert("success");
		   if (transport.responseText) {
				// jukebox returns video in the following format: s,v
				aNextVideo = transport.responseText.split(",");
				if (Object.isArray(aNextVideo)) {
					if ((aNextVideo[0]!=0) && (aNextVideo[1] !=0)) {
						// play s and v
						play(aNextVideo[0],aNextVideo[1]);
						// load info panel
						info(aNextVideo[0],aNextVideo[1]);
					}
				}
		   } else {
				// load player with error message
				api.playClip( { url: sErrorClip, duration: iErrorDuration } );
		   }
		   
		}, 
		onFailure: function(){ 
			// load player with error message
				api.playClip( { url: sErrorClip, duration: iErrorDuration } );
		} 
	});
}

var playcount=0;

var bandwidth = getCookie("bandwidth");
if (!bandwidth) {
	bandwidth = "m"; // default medium quality
}

// Functions
function PluginCheck(name) {

	// check if a specified plug in exists for the browser           
	for ( var i in  navigator.plugins ) {
		var n = navigator.plugins[i].name;
		 //alert(n);
		if ( n != null && n.indexOf(name) >= 0 ) {
			return true;
		}

	}
	return false;
}

function setBandwidth(b) {
	// set bandwidth
	setCookie("bandwidth",b,365 ); // store cookie for future mediaplayer access (causes screen flash in IE6)
	bandwidth = b; // update global variable for current mediaplayer instance
}

function getVideoOptions(s,v) {
	
	// retrieve current bandwidth setting (bandwidth is a global variable)
	var b = bandwidth;

	var sHTML = "";
	
	// update the player options bar
	var oDiv = document.getElementById("panelOptions");

	// add the share link
	sHTML = "<a href='#' onClick='toggleShare(" + s + "," + v + "); return false;'>SHARE</a> &nbsp;&nbsp;&nbsp;&nbsp;";
	// display the share panel contents
	displaySharePanel (s,v);
	
	// add the comment link
	sHTML += "<a href='#' onClick='toggleComment(" + s + "," + v + "); return false;' style='color: #660000'>MY VOICE</a> &nbsp;&nbsp;&nbsp;&nbsp;";

	// display the comment panel contents
	displayCommentPanel (s,v);
	
	// add the video quality links
	sHTML += " QUALITY ( ";
	sHTML += " <a href='#' onClick='setBandwidth(\"l\"); play(" + s + "," + v + "); return false;'>";
	if (b == "l") {
		sHTML += "<u>Low</u>";
	} else {
		sHTML += "Low";
	}
	sHTML += "</a> ";
	sHTML += " <a href='#' onClick='setBandwidth(\"m\"); play(" + s + "," + v + "); return false;'>";
	if (b == "m") {
		sHTML += "<u>Med</u>";
	} else {
		sHTML += "Med";
	}
	sHTML += "</a> ";
	sHTML += " <a href='#' onClick='setBandwidth(\"h\"); play(" + s + "," + v + "); return false;'>";
	if (b == "h") {
		sHTML += "<u>High</u>";
	} else {
		sHTML += "High";
	}
	sHTML += "</a> )";

	// update the div
	oDiv.innerHTML = sHTML;
	
	

}

function getPlayer (s,v) {
	
	// retrieve current bandwidth setting (bandwidth is a global variable)
	var b = bandwidth;
	
	// create url to retrieve the video
	var sURL = "mediaplayer_flv.php?v=" + v + "&s=" + s + "&b=" + b; // bandwidth is global var
	
	// Modify the requested page url to include a unique parameter (prevent caching)
	var d = new Date()
	var timestamp = d.getTime();
	if (sURL.indexOf("?") != -1) {
		sURL = sURL + "&timestamp=" + timestamp;
	} else {
		sURL = sURL + "?timestamp=" + timestamp;
	}

	// retrieve the video URL
	new Ajax.Request(sURL, 
	{ 
		method:'get', 
		onSuccess: function(transport){ 
		   // 		alert("success");
		   if (transport.responseText) {
		   		// var response = transport.responseText || "ERROR MESSAGE"; 
			  	
				// update player with correct video
				api.playClip( { url: transport.responseText });
		   } else {
				// populatePanel("panelVideo","<p class='videoItem'>Unable to display the requested information.</p>");    
				// load player with error message
				api.playClip( { url: sErrorClip, duration: 30 } );
		   }
		   
		}, 
		onFailure: function(){ 
			// 		alert("failure");
			// populatePanel("panelVideo","<p class='videoItem'>Unable to display the requested information.</p>"); 
			// load player with error message
			api.playClip( { url: sErrorClip, duration: 30 } );
		} 
	}); 

	// return wmplayer ("", sURL, "wmplayer", 356, 339);
	
}

function wmplayer(p, filename, name, width, height) {

	this.id = (name != undefined) ? name : "wmplayer";
	/*
	if (!p) return;
	this.className = this.id;
	this.document = p.ownerDocument || p.document;
	this.container = p;
	this.container.player = this;
	this.ended = false;
	this.container.unselectable = "on";
	*/
	
	var html='';
	
	if (window.ActiveXObject && navigator.userAgent.indexOf('Windows') != -1 && navigator.userAgent.indexOf('MSIE') != -1)
		//I Browser Type: IE on Windows
		{
	
		html = 	'<object width="' + width + '" height="' + height + '" id="' + this.id + 'control" ' +
				'classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" ' +
				'codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,1,52,701" ' + 
				'standby="Loading..." ' +
				'type="application/x-oleobject"> ' +
				'<param name="url" value="' + filename + '">' + 
				'<param name="FileName" value="' + filename + '">' + 
				'<param name="stretchtofit" value="true">' + 
				'<param name="autoStart" value="true">' + 
				'<param name="EnableContextMenu" value="true">' +
				'<param name="ShowStatusBar" value="true">' +
				'<param name="showFrame" value="true">' +
				'<param name="uiMode" value="full">' +
				'</object> ';
		
	} else if (navigator.userAgent.indexOf('Macintosh') !=-1 && navigator.userAgent.indexOf('Safari')!=-1)	{
		// Browser Type: Mac or Safari
		
		// display a warning if they are trying to play a video on a mac or using safari
		if (playcount==0) {
			html =	'<br><br><p class="linkFeatureText">Some features may not function as intended in Safari.<br><br>' +
		 			'The free <a href="http://www.mozilla.com" target="_blank" class="linkHelpText">Firefox</a> browser <br>' + 
					' (available from <a href="http://www.mozilla.com" target="_blank" class="linkHelpText">http://www.mozilla.com</a>)<br>' +
				 	'<br><br>and the free <a href="http://www.flip4mac.com" target="_blank" class="linkHelpText">Flip4Mac component for QuickTime</a><br>' +
				 	' (available from <a href="http://www.flip4mac.com" target="_blank" class="linkHelpText">http://www.flip4mac.com</a>)<br><br>are recommended.</p>';
		} else {
			 html = '<embed type="video/x-ms-wmx" ' +
					'pluginspage="http://www.microsoft.com/windows/windowsmedia/player/wmcomponents.mspx" ' +
					'width="' + width + '" height="' + height + '" ' +
					'src="' + filename + '" filename="' + filename + '" ' +
					'allowembedtagoverrides="True"' +
					'bgcolor="#000000"' +
					'enablejavascript="True" ' +
					'id="' + this.id + 'control" ' +
					'autoplay="True" scale="ASPECT"></embed>';
		}
		
	} else if (navigator.userAgent.indexOf('Windows') != -1 && navigator.userAgent.indexOf('Firefox') != -1) {
		//Browser Type: Windows-FireFox

		// Do they have the Windows Media Player plugin for Firefox?
		if (PluginCheck('Windows Media Player Firefox')) {
			 html = '<object type="application/x-ms-wmp" ' +
					'codebase="http://port25.technet.com/videos/downloads/wmpfirefoxplugin.exe" ' +
					'data="' + filename + 
					'" width="' + width + '" height="' + height + '">'; 
					'<param name="URL" value="' + filename + '">' + 
					'<param name="stretchtofit" value="true">' + 
					'<param name="autoStart" value="true">' + 
					'<param name="EnableContextMenu" value="true">' +
					'<param name="ShowStatusBar" value="true">' +
					'<param name="showFrame" value="true">' +
					'<param name="uiMode" value="full">' +
					'</object> ';
		} else {
		
		 	html =	'<br><br><p class="linkFeatureText">' + 
					' Please <a href="http://port25.technet.com/pages/windows-media-player-firefox-plugin-download.aspx" target="_blank" class="linkHelpText">' +
					'download the latest Windows Media Player<br> Plugin for FireFox.</a><br>' +
		 			'(You will need to close and restart <br> Firefox after installing the plugin)';
		}
	
	} else {
	
		// Browser Type: Other
		 html = '<embed type="application/x-mplayer2" ' +
				'pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/MediaPlayer/" ' +
				'width="' + width + '" height="' + height + '" ' +
				'src="' + filename + '" filename="' + filename + '" ' +
				'enablejavascript="true" ' +
				'id="' + this.id + 'control" ' +
				'name="' + this.id + 'control" ' +
				'autostart="True" showcontrols="True" showstatusbar="1" showstatusbar="True" showdisplay="False" autorewind="True" scale="ASPECT"></embed>';
	}
   
   	/*
	// load player code into the page
	this.container.innerHTML = html;
	// create reference to the object on the page
	this.wmplayer = this.document.getElementById(this.id+"control");
	
	if (window.ActiveXObject && navigator.userAgent.indexOf('Windows') != -1 && navigator.userAgent.indexOf('MSIE') != -1) 	{
		// ATTACH EVENTS TO WINDOWS IE BROWSER
		this.wmplayer.attachEvent("playstatechange",this.eventHandlers.playStateChanged);
	}
	*/
	// we have now played a video (no longer first play)
	playcount++;
	return html;
}

// -------------------------------------------------------------------------------------------------
// History Functions
// -------------------------------------------------------------------------------------------------

// handle the related panel history (forward/back) functionality
var iHistory_RP_Counter = 0;
var iHistory_RP_MaxCounter = 0;
var aHistory_RP = [];

function history_Related_Show() {
	// determine if forward and back buttons should be displayed for the related panel
	var sBack = "";
	var sForward = "";
	var sHTML = ""; // iHistory_RP_Counter + "|" + iHistory_RP_MaxCounter + "<br>";
	if (iHistory_RP_Counter > 1) {
		// display a back button
		sBack = "<a href='#' onClick='history_Related_Back(); return false;'><img src='images/arrow_left.gif' border=0 alt='<' height='12' width='14'></a>";
	} 
	
	if (iHistory_RP_Counter < iHistory_RP_MaxCounter) {
		// display a forward button
		sForward =  "<a href='#' onClick='history_Related_Forward(); return false;'><img src='images/arrow_right.gif' border=0 alt='>' height='12' width='14'></a>";
	} 
	
	if ((sBack != "") || (sForward !="")) {
		sHTML +=	"<div class='relatedTitle' style='text-align: right'>";
		if (sBack != "") {
			sHTML += sBack;
		}
		if ((sBack != "") && (sForward !="")) {
			sHTML += " &nbsp; ";	
		}
		if (sForward !="") {
			sHTML += sForward;
		}
		sHTML += "</div>";
	}
	
	var oDiv = document.getElementById("panelHistory");
	oDiv.innerHTML = sHTML;

}

function history_Related_Back() {
	if (iHistory_RP_Counter > 1) {
		iHistory_RP_Counter --;
		var oDiv = document.getElementById("panelRelated");
		oDiv.innerHTML = aHistory_RP[iHistory_RP_Counter]; 
		// update the history panel 
		history_Related_Show();
	} 
}

function history_Related_Forward() {
	if (iHistory_RP_Counter < iHistory_RP_MaxCounter) {
		iHistory_RP_Counter ++;
		var oDiv = document.getElementById("panelRelated");
		oDiv.innerHTML = aHistory_RP[iHistory_RP_Counter]; 
		// update the history panel 
		history_Related_Show();
	} 
}

// INFO PANEL

// handle the info panel history (forward/back) functionality
var iHistory_IP_Counter = 0;
var iHistory_IP_MaxCounter = 0;
var aHistory_IP = [];

function history_Info_Show() {
	// determine if forward and back buttons should be displayed for the related panel
	var sBack = "";
	var sForward = "";
	var sHTML = "";
	//alert (iHistory_IP_Counter + "|" + iHistory_IP_MaxCounter );
	if (iHistory_IP_Counter > 1) {
		// display a back button
		sBack = "<a href='#' onClick='history_Info_Back(); return false;'><img src='images/arrow_left.gif' border=0 alt='<' height='12' width='14'></a>";
	} 
	
	if (iHistory_IP_Counter < iHistory_IP_MaxCounter) {
		// display a forward button
		sForward =  "<a href='#' onClick='history_Info_Forward(); return false;'><img src='images/arrow_right.gif' border=0 alt='>' height='12' width='14'></a>";
	} else if (iHistory_IP_Counter == iHistory_IP_MaxCounter) {
		sForward =  "<a href='#' onClick='play_jukebox_video(); return false;'><img src='images/arrow_right.gif' border=0 alt='>' height='12' width='14'></a>";
	}
	
	if ((sBack != "") || (sForward !="")) {
		sHTML +=	"<div class='relatedTitle' style='text-align: right'>";
		if (sBack != "") { sHTML += sBack; }
		if ((sBack != "") && (sForward !="")) { sHTML += " &nbsp; ";}
		if (sForward !="") { sHTML += sForward;	}
		sHTML += "</div>";
	}
	
	var oDiv = document.getElementById("panelVideoHistory");
	oDiv.innerHTML = sHTML;

}

function history_Info_Back() {
	if (iHistory_IP_Counter > 1) {
		iHistory_IP_Counter --;
		// update the info panel
		var oDiv = document.getElementById("panelInfo");
		oDiv.innerHTML = aHistory_IP[iHistory_IP_Counter]; 
		
		// Execute any javascript contained in the panel
		//oDiv.innerHTML.evalScripts();

		// update video player (retrieve specific video info from the info panel contents)
		//var aData = /--sectionid=(\d+)videoid=(\d+)--/(aHistory_IP[iHistory_IP_Counter]);
		var re = /--sectionid=(\d+)videoid=(\d+)--/
		var aData = re.exec(aHistory_IP[iHistory_IP_Counter]);
		if (Object.isArray(aData)) {
			if (aData.length == 3) {
				play(aData[1],aData[2]); 
			}
		}		
		// update the history panel 
		history_Info_Show();
	} 
}

function history_Info_Forward() {
	if (iHistory_IP_Counter < iHistory_IP_MaxCounter) {
		iHistory_IP_Counter ++;
		// update the info panel
		var oDiv = document.getElementById("panelInfo");
		oDiv.innerHTML = aHistory_IP[iHistory_IP_Counter]; 

		
		// Execute any javascript contained in the panel
		// oDiv.innerHTML.evalScripts();
		
		// update video player (retrieve specific video info from the info panel contents)
		//var aData = /--sectionid=(\d+)videoid=(\d+)--/(aHistory_IP[iHistory_IP_Counter]);
		var re = /--sectionid=(\d+)videoid=(\d+)--/
		var aData = re.exec(aHistory_IP[iHistory_IP_Counter]);
		if (Object.isArray(aData)) {
			if (aData.length == 3) {
				play(aData[1],aData[2]); 
			}
		}		
		// update the history panel 
		history_Info_Show();
	} 
}

// -------------------------------------------------------------------------------------------------
// Ajax Code for Panels
// -------------------------------------------------------------------------------------------------


function populatePanel(sPanelID,data) {
	
	// populate a Panel with the specified data (html)
	var oDiv = document.getElementById(sPanelID);
	oDiv.innerHTML = data;
	
	// if this is the related or info panel, then store the current contents in the history array
	switch (sPanelID) {
			case "panelRelated": 
					// manage the history of the panel
					iHistory_RP_Counter++; 							// increase the history page counter
					aHistory_RP[iHistory_RP_Counter] = data; 		// store current page contents
					iHistory_RP_MaxCounter = iHistory_RP_Counter; 	// reset the forward counter
					// show the history panel contents
					history_Related_Show();
 				break; 
			case "panelInfo":
					// manage the history of the panel
					iHistory_IP_Counter++; 							// increase the history page counter
					aHistory_IP[iHistory_IP_Counter] = data 		// store current page contents
					iHistory_IP_MaxCounter = iHistory_IP_Counter; 	// reset the forward counter
					history_Info_Show();
				break
	}
}   

function loadPanel(sPanelID,sPageUrl) {
	
	// Parameters
	// 				sPanelID - the id of the panel to populate with the retrieved page's contents
	//				sPageURL - the url of the page to retrieve
	
	// Mark Panel as Loading
	//var oDiv = document.getElementById(sPanelID);
	//oDiv.innerHTML = "<div class='panel-loading-indicator'>loading</div>";
	
	// Modify the requested page url to include a unique parameter (prevent caching)
	var d = new Date()
	var timestamp = d.getTime();
	var sOriginalUrl = sPageUrl;
	if (sPageUrl.indexOf("?") != -1) {
		sPageUrl = sPageUrl + "&timestamp=" + timestamp;
	} else {
		sPageUrl = sPageUrl + "?timestamp=" + timestamp;
	}
   
   	// debug
	// alert(sPageUrl);
	
	// display loading indicator
	loadingIndicator(sPanelID);
	
	// populate a specified Panel via AJAX
	new Ajax.Request(sPageUrl, 
	{ 
		method:'get', 
		onSuccess: function(transport){ 
		   // debug
		   // 		alert("success");
		   var response = transport.responseText || "<div class='videoItem' style='width:100%; text-align:center;'>Unfortunately, an error occured. <br>No information available to display.</div>"; 
		   // debug
		   // 		alert(response);
		   
		   // Update the Panel
		  populatePanel(sPanelID,response);
		  
		  // Execute any javascript contained in the panel
		  // response.evalScripts();
		  
		  // Log the panel view in Google Analytics
		  urchinTracker(sOriginalUrl);
		}, 
		onFailure: function(){ 
			// debug
			// 		alert("failure");
			populatePanel(sPanelID,"<p class='videoItem'>Unable to display the requested information.</p>"); 
		} 
	}); 
}

// -------------------------------------------------------------------------------------------------
// loading indicator
// -------------------------------------------------------------------------------------------------

function loadingIndicator(sPanelID) {
	// display a loading indicator
	var shtml = "";
	if (sPanelID) {
		switch (sPanelID) {
			case "panelVideo": 
					// black version of the loading indicator
					shtml = "_black"; 
					break; 
			case "panelInfo":
			case "panelShare":
			case "panelComment":  
			case "panelListComments":  
			case "panelCommentsForm":
					// dark blue version of the loading indicator
					shtml = "_three"; 
					break; 
		}
	}
	shtml = "<center><div class='loadingIndicator" + shtml + "'><img src='images/loading_indicator" + shtml + ".gif' width=31 height=31 alt='loading...'></div></center>";
	// populate the panel contents
	var oDiv = document.getElementById(sPanelID);
	oDiv.innerHTML = shtml;
}

// -------------------------------------------------------------------------------------------------
// simplified functions for standard panels
// -------------------------------------------------------------------------------------------------


function play(s,v) {
	// load video options
	getVideoOptions(s,v);
	// load video
	getPlayer(s,v);

	// moved the loading of the comments panel and the comments form beneath it into this function
	// future note: can also move the info functionality into this function as all changes to the info panel, commentslist panel, and 
	//				commentslistadd panel occur whenever a new video is played

	// load comments
	comments(s,v);
	// load comments add form
	commentsForm(s,v);
	
}

function info (s,v) {
	// populate info panel
	loadPanel("panelInfo","mediaplayer_info.php?sID=" + s + "&vID=" + v);
}

function related (s,v) {

	// populate related panel
	var sURL = "mediaplayer_related.php?sID=" + s + "&vID=" + v;
	loadPanel("panelRelated",sURL);
}

function comments (s,v,r,p) {
	
	if (!r) { r = 10 };
	if (!p) { p = 1};
	
	// if there are any video comments, load them into the comments list panel
	var sURL = "mediaplayer_user_comments.php?sID=" + s + "&vID=" + v + "&rowsPerPage=" + r + "&pageNum=" + p;
	loadPanel("panelListComments",sURL);
}

function commentsForm (s,v) {
	
	var sHTML;
	sURL = "mediaplayer_comment.php?s=" + s + "&v=" + v + "&title=" + escape(sVideoTitle) + "&honorific=" + escape(sUserHonorific) + "&fullname=" + escape(sUserName) + "&email=" + escape(sUserEmail)  + "&country=" + escape(sUserCountry) + "&panel=panelCommentsForm";
	loadPanel("panelCommentsForm",sURL);

}

// -------------------------------------------------------------------------------------------------
// Share Panel
// -------------------------------------------------------------------------------------------------

// global variable to handle share toggle
var bShareExpand = false; 

// handle share panel
function toggleShare (s,v) {
	// toggle the display of the share information panel	
	if (!bShareExpand) {
		// set flag
		bShareExpand = true;
	} else {
		// set flag
		bShareExpand = false;
	} 
	displaySharePanel(s, v);
}

function displaySharePanel (s,v) {
	
	var sHTML;
	var sURL   = "http://www.1cubed.com/mediaplayer.php?vID=" + v + "&sID=" + s;
	var sEmbed ="";
	if (s == 43 || s== 33 || s==36 ) {
		sEmbed ='&lt;embed src="http://downloads.cbn.com/onecubedplayer/onecubedPlayer.swf?s=' + s + '_' + v + '&onecubed=1&autoplay=0" type="application/x-shockwave-flash" wmode="transparent" width="425" height="348" allowfullscreen="true"&gt;';
	}
	var sTitle = "1Cubed.com - Media Player "; // retrieve from form in the info panel
	// try update the title if possible
	oForm = MM_findObj("optionsForm");
	if (oForm) {
		if (oForm.videoTitle) {
			sTitle += " - " + oForm.videoTitle.value;
		}
	}
	if (bShareExpand) {
		// we need to display the share information
		sHTML = "<div class='shareForm'><table cellpadding=2 cellspacing=2 border=0>";
		sHTML += "<tr><td>Link:</td><td><input type='text' onClick='this.select();'  class='ColorTwo' style='font-size: 8pt; width:280px; height: 15px;' ";
		sHTML += "value='" + sURL + "'></td></tr>"; 
		// embed code
		if (sEmbed != "") {
			sHTML += "<tr><td>Embed:</td><td><input type='text' onClick='this.select();'  class='ColorTwo' style='font-size: 8pt; width:280px; height: 15px;' ";
			sHTML += "value='" + sEmbed + "'></td></tr>"; 
		}
		// add this button
		sHTML += "<tr><td>Share:</td><td align=left>";
		sHTML += "<a href='http://www.addthis.com/bookmark.php' onmouseover=\"return addthis_open(this, '', '" + sURL + "', '" + sTitle + "')\" onmouseout=\"addthis_close()\" onclick=\"return addthis_sendto()\"><img src='http://s9.addthis.com/button1-share.gif' width='125' height='16' border='0' alt='' /></a></td></tr>";
		// update the panel
		sHTML += "</table>";
		sHTML += "<div style='text-align:right;'>[<a href='#' onClick=toggleShare(" + s + "," + v + "); return false'>X</a>]</div>";
		sHTML += "</div>";
		populatePanel("panelShare",sHTML);
	} else {
		// ensure nothing is displayed in the share panel
		populatePanel("panelShare","");
	}
}
	
	
// -------------------------------------------------------------------------------------------------
// Comment Panel
// -------------------------------------------------------------------------------------------------

// global variable to handle comment form and toggle
var bCommentExpand = false; 

// handle share panel
function toggleComment (s,v) {
	// either display the comment form or hide it
	if (!bCommentExpand) {
		// set flag
		bCommentExpand = true;
	} else {
		// set flag
		bCommentExpand = false;
	} 
	displayCommentPanel(s,v);
}

// variables to store current user's details
var sUserName = "";
var sUserEmail = "";
var sUserCountry = "";
var sUserComment = "";
var sUserHonorific = "";
var sVideoTitle = "";

// We have two panels that allow users to add comments - the drop down "panelComment" under MyVoice and the "panelListCommentsAdd" under panelCommentList
function displayCommentPanel(s,v) {
	
	var sHTML;
	if (bCommentExpand) {
		// we need to display the comment information
		sURL = "mediaplayer_comment.php?s=" + s + "&v=" + v + "&title=" + escape(sVideoTitle) + "&honorific=" + escape(sUserHonorific) + "&fullname=" + escape(sUserName) + "&email=" + escape(sUserEmail)  + "&country=" + escape(sUserCountry) + "&panel=panelComment";
		loadPanel("panelComment",sURL);
	} else {
		// ensure nothing is displayed in the comment panel
		populatePanel("panelComment","");
	}
}

function submitComment (panel) {
	
	// panel - the name of the panel that contains the comment form (used to reference the correct fields)

	// ensure referencing correct comment form
	if (!panel) {
		panel = "panelComment";
	} 
	var sURL = "";
	
	var sFormName = "optionsForm";
	oForm = MM_findObj(sFormName);
	if (oForm) {
		
		// reference the correct comment form
		sUserHonorific 	= eval("oForm." + panel + "_honorific.options[oForm." + panel + "_honorific.selectedIndex].value;"); // honorific
		sUserName 		= eval("oForm." + panel + "_fullname.value;"); 	// username
		sUserEmail 		= eval("oForm." + panel + "_email.value;");		// email
		sUserComment 	= eval("oForm." + panel + "_message.value;");	// comment
		sUserCountry 	= eval("oForm." + panel + "_country.options[oForm." + panel + "_country.selectedIndex].value;");	// country 
		
		// are the video specific details available?
		if (oForm.videoTitle) {
			sVideoTitle 	= oForm.videoTitle.value;	// video title
			sVID			= oForm.videoV.value;	// vID
			sSID		 	= oForm.videoS.value;	// sID
		} else {
			sVideoTitle = "1Cubed Video (unknown)";
			sVID = 0;
			sSID = 0;
		}
		sURL = "mediaplayer_comment.php?submit=true&s=" + sSID + "&v=" + sVID + "&title=" + escape(sVideoTitle) + "&honorific=" + escape(sUserHonorific) + "&fullname=" + escape(sUserName) + "&email=" + escape(sUserEmail)  + "&country=" + escape(sUserCountry) + "&message=" + escape(sUserComment) + "&panel=" + panel;
		// submit the comment
		loadPanel(panel,sURL);
	}
}
// -------------------------------------------------------------------------------------------------
// Dreamweaver and extended functions
// -------------------------------------------------------------------------------------------------


function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

// Example: showHideLayers(Layer1,'','show',Layer2,'','hide');
function showHideLayers()
{ 
  var i, visStr, obj, args = showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3)
  {
    if ((obj = MM_findObj(args[i])) != null)
    {
      visStr = args[i+2];
      if (obj.style)
      {
        obj = obj.style;
        if(visStr == 'show') visStr = 'visible';
        else if(visStr == 'hide') visStr = 'hidden';
      }
      obj.visibility = visStr;
    }
  }
}

// Example: expandCollapseLayers(Layer1,'','show',Layer2,'','hide')
function expandCollapseLayers()
{ 
  var i, visStr, obj, args = expandCollapseLayers.arguments;
  for (i=0; i<(args.length-2); i+=3)
  {
    if ((obj = MM_findObj(args[i])) != null)
    {
      visStr = args[i+2];
      if (obj.style)
      {
        obj = obj.style;
        if(visStr == 'show') visStr = 'inline';
        else if(visStr == 'hide') visStr = 'none';
      }
      obj.display = visStr;
    }
  }
}