/**
 * Is the browser a version of Internet Explorer?
 *
 * @var int
 */
var isIE = $.browser.msie;

$(document).ready(function()
{
	if (!$("#pldv_home").size())
	{
		$("body").append('<div id="pldv_home"></div><div id="pldv_shrink"></div><div id="pldv_container"><a id="pldv" /><div id="flpl_ad" class="pldv_ad_invisible">&nbsp;</div><span class="pldv_resizer" id="pldv_resizer"></span><span class="vich_corner_t_l"></span><span class="vich_corner_t_r"></span><span class="vich_corner_b_l"></span><span class="vich_corner_b_r"></span><div class="pldv_bg_left"></div><div class="pldv_bg_backer"></div><div id="pldv_dragbar"><a href="#" onclick="pldv_hide(); return false;"><span class="pldv_closer"></span></a></div><div id="pldv_player"></div><div id="pldv_meta"><p class="init">&nbsp;</p></div></div>');
	}
});

/***** AVS Overridable Settings *****/
var pldv_player_width  = 385;
var pldv_player_height = 282;
var pldv_init_x = "center";
var pldv_init_y = "center"; 
var pldv_side_margin = 3;
// Minimum size the player will be allowed to resize to. 0 if no minimum
var pldv_min_w = 450;
var pldv_min_h = 330;
var pldv_vid_id; 

var pldv_alt_div_content = "No video has been loaded.  Please click a video to view.";

var pldv_div, pldv_player_div;
var pldv_id = "pldv_container";
var pldv_player_div_id = "pldv_player"; 

var pldv_status = 0;
var pldv_minimized = false;
var pldv_hide_immediate_override = false;
var pldv_animating = false;

// The following are all required for the floating player.  Meta can be used with the player in static mode if desired.
var pldv_meta_div, pldv_dragbar_div, pldv_home_div, pldv_home_shrink_div, pldv_resizer;

var pldv_meta_div_id = "pldv_meta";
var pldv_dragbar_div_id = "pldv_dragbar";
var pldv_home_div_id = "pldv_home";
var pldv_home_shrink_div_id = "pldv_shrink";
var pldv_resizer_id = "pldv_resizer";

// Used to record the location and offset of the player div before minimization so it can be restored later.
var pldv_slidehome_pos_x, pldv_sh_offset_x, pldv_sh_offset_y;

var pldv_use_doc_el;
if (document.compatMode && document.compatMode != "BackCompat")
{
	pldv_use_doc_el = true;
}
else
{
	pldv_use_doc_el = false;	
} 

/***** AVS Overridable Settings *****/
var flpl_skins_dir = Syn.Config.PortalRoot + "video/flpl_skins/";
var flpl_buffer_time = 2;
var flpl_ad_buffer_time = 1;
var flpl_scalemode = "letterbox";
var flpl_default_volume = 75; 
var flpl_alt_use_css = true;
var flpl_alt_ad_w = 300;
var flpl_alt_ad_h = 250;

var flpl_alt_ad_div_id = "flpl_ad"; // Not AVS overridable - no where else to put var though

var flpl_object;
var flpl_vid, flpl_login_status, flpl_username, flpl_stored_volume;
var flpl_play_time, flpl_play_status, flpl_volume, flpl_viewmode; // These are sent from flpl_object to JS.
var flpl_bg_color = "121a1c";
var flpl_skin_array;
var flpl_skin_id = "default";

var flpl_width = 385;
var flpl_height = 282;
var flpl_stored_volume_cookiename = "syna_flpl_volume_store";
var flpl_stored_volume_days_to_expire = 365;
var flpl_playing_ad = false;

var flpl_video_api_url = Syn.Config.PortalRoot + "files/video/video_api.php";
var flpl_playlist_api_url = "playlist_api.php";
var flpl_billing_api_url = "/"; // Functionality currently does not exist
var flpl_billing_success_url = "/"; // Functionality currently does not exist
var flpl_login_function = "vpjs_show_login";

// Override this path var as necessary in JS if player is used on a page
// outside of the video directory.
var flpl_player_swf_path = Syn.Config.PortalRoot + "video/flpl_player.swf";

// External Ad variables.  If LightningCast Ads are being used, and LC banners need to be displayed outside of the flash player...
var flpl_alt_ad_div, flpl_alt_ad_url, flpl_alt_ad_clickurl;

// Standalone variables.  Determine if the player is being used in standalone (non status-API) mode.
// These vars only get set locally.  No DB/API/AVS retrieval.
var flpl_standalone_mode_on = true;	// This only gets set to true locally if using standalone mode.
var flpl_standalone_skin_xml, flpl_standalone_vid_url, flpl_standalone_ad, flpl_standalone_duration;

var flpl_standalone_autostart = false;

// Playlisting flag.  Gets set to true if playlisting functionality is active.
var flpl_playlisting_on = false;
// If playlisting is being used, this should be set to the next video ID. 
var flpl_playlist_nextvid;

flpl_stored_volume = flpl_read_vol_cookie();
if (flpl_stored_volume == null)
{
	// No volume cookie stored.  So, set it to the default volume.
	flpl_stored_volume = flpl_default_volume;
}

/***** PLDV FUNCTIONS *****/

/**
 * pldv_initialize should be used upon page load to initialize the pldv_div and prepare for possible use
 * of the FVP/WMP on the current page.
 *
 * @param {String} div_id This should be the ID of the div that will become the pldv_div (player div).
 *						The FVP/WMP will be loaded within this div.
 */
function pldv_initialize(div_id)
{
	// Called during document onload.
	if (!pldv_status)
	{
		if (div_id != null)
		{
			pldv_id = div_id;
		}

		pldv_status = 1;
		pldv_div = document.getElementById(pldv_id);
		
		if (pldv_div == null)
		{
			pldv_status = 0;
		}
		else
		{
			// Initialize object references
			flpl_alt_ad_div = (flpl_alt_ad_div_id) ? document.getElementById(flpl_alt_ad_div_id) : false;
			
			pldv_player_div = document.getElementById(pldv_player_div_id);
			pldv_meta_div = (pldv_meta_div_id) ? document.getElementById(pldv_meta_div_id) : false;
			pldv_dragbar_div = (pldv_dragbar_div_id) ?  document.getElementById(pldv_dragbar_div_id) : false;
			pldv_player_div.innerHTML = "";
			pldv_resizer = (pldv_resizer_id) ?  document.getElementById(pldv_resizer_id) : false;
			pldv_home_div = (pldv_home_div_id) ? document.getElementById(pldv_home_div_id) : false;
			pldv_home_shrink_div = (pldv_home_div_id) ? document.getElementById(pldv_home_shrink_div_id) : false;
			
			
			// Initialize drag bar and resize handle.
			if (pldv_resizer)
			{
				new pldv_resizehandle(pldv_resizer);
			}

			if (pldv_dragbar_div)
			{
				new pldv_dragbar(pldv_dragbar_div);
			}
			
			if (pldv_player_width > 0)
			{
				flpl_width = pldv_player_width;
				pldv_player_div.style.width= pldv_div.style.width  =  pldv_player_width + "px";
			} 
			else
			{
				pldv_player_div.style.width= pldv_div.style.width  = "1px";
			}
			
			if (pldv_player_height > 0)
			{
				flpl_height = pldv_player_height;
				pldv_player_div.style.height = pldv_player_height + "px";
			}
			
			// Set X and Y of player div, determining center of visible browser window.
			if (pldv_init_x == "center")
			{
				// find the center of the window.
				// then, find the center of the flpl_container.
				var docwidth = pldv_getDocumentDims().width;
				
				// half of the docwidth, minus half of the player width, plus any scroll offset, will give us our x.
				pldv_init_x = (docwidth/2) - (pldv_player_width/2) + pldv_getWindowOffsetX();
			}

			if (pldv_init_y == "center")
			{
				// find the center of the window.
				// then, find the center of the flpl_container.
				var docheight = pldv_getDocumentDims().height;
				// half of the docheight, minus half of the player height, plus any scroll offset, will give us our y.
				pldv_init_y = (docheight/2) - (pldv_player_height/2) + pldv_getWindowOffsetY();
				// If in playlisting mode, this will be screwed up by the very large meta area that will be displayed below
				// the player.  So, subtract a bit to make sure the player doesn't go offstage.
				if (flpl_playlisting_on)
				{
					pldv_init_y = pldv_init_y - 80;
					if (pldv_init_y < 0) 
					{
						pldv_init_y = 0;
					}
				}
			}
			
			// Set X and Y location of player div, not centered.
			if (pldv_init_x >= 0)
			{
				pldv_div.style.left = pldv_check_offsetX(pldv_init_x, pldv_player_width) + "px";
			}

			if (pldv_init_y >= 0)
			{
				var new_style_top_string = pldv_check_offsetY(pldv_init_y, pldv_player_height);
				if (new_style_top_string < 0)
				{
					new_style_top_string = "0";
				}
				pldv_div.style.top = new_style_top_string + "px";
			}

			if (!pldv_min_w)
			{
				pldv_min_w = 0;
			}

			if (!pldv_min_h)
			{
				pldv_min_h = 0;
			}
		}
	}
}

/**
 * pldv_show is a function that is called by pldv_playvideo, and can be called on its own.  If the player is in
 * a minimized state, this will cause a slide animation and then cause the player to be visible.  If the appropriate
 * player does not yet exist, it calls the corresponding create function to initialize it.
 *
 * @param {String} which_player This optional var should be "flpl", indicating which player to load.
 *								If not set, the player div will load alternate content instead.
 * @return bool false
 */
function pldv_show(which_player)
{
	// Initialize the player div if it isn't already.
	pldv_initialize();
	
	// Check to see if the player is minimized.
	if (which_player)
	{	
		
		if (pldv_minimized)
		{
			pldv_slide_animate(pldv_home_shrink_div_id, pldv_home_div_id, "restore");
		}
		
		// Now, create the appropriate object and/or embed code for the specified player, and initialize
		// said player.
		switch(which_player)
		{
			case "flpl":
				// Eventually, rename flpl_object to flpl_object for consistency.
				if (pldv_status != 2)
				{
					flpl_create();
				}
				break;

			// End switch
		}
	}
	else
	{
		flpl_hide_ext_ad();
		// The desired player wasn't specified.  So, if an active player exists in minimized state, show it.
		// Otherwise, do nothing.
		
		if (pldv_status > 0)
		{
			// If player is minimized, returns it from minimized position.
			// Wrapper for pldv_slideback, located in video_div_movement.js .
			if (pldv_minimized == true)
			{
				pldv_slide_animate(pldv_home_shrink_div_id, pldv_home_div_id, "restore");
			}
			if (pldv_status == 1) 
			{
				// pldv_status == 1.  In this case, show alternate innerHTML content, which can be promotional.
				pldv_player_div.innerHTML = pldv_alt_div_content;
			}
		} 
	}
	

		
	return false;
}

/**
 * pldv_hide is a function that can be called directly to minimize the pldv_div and make it invisible.
 * This will start a slide animation, pldv_slide_animate, located in video_div_movement.js
 *
 * @return bool false
 */
function pldv_hide()
{
	// If player is currently visible, minimizes it.
	if (flpl_object && (pldv_status == 2))
	{
		flpl_hide_ext_ad();
		flpl_object.minimize();
	}
	if (!pldv_minimized && pldv_div)
	{	
		 pldv_slide_animate(pldv_home_shrink_div_id, pldv_home_div_id, "minimize", false);
	}
	return false;
}

/**
 * pldv_hide_player a function that can be called directly to unload FVP or WMP from the pldv_div.
 * Any currently loaded media will also be unloaded, and the player div will load pldv_alt_div_contents instead.
 *
 * @return bool false
 */
function pldv_hide_player()
{
	flpl_hide_ext_ad();
	
	if ((pldv_status == 2) && flpl_object)
	{
		if (flpl_object.purgeVideo)
		{
			flpl_object.purgeVideo();
		}
	}

	if (pldv_status > 1)
	{
		pldv_player_div.innerHTML = pldv_alt_div_content;
		pldv_status = 1;
	}
	
	return false;
}


/***** FLPL Functions *****/

/**
 * flpl_create is called by pldv_show if flpl_object does not yet exist.  The function creates the object/embed
 * code appropriate to the current browser, with information from JS variables.  Assigns this code to the player div.
 *
 * @param {String} bgcolor This is the (optional) background color (hex code without #) that will be used for the FVP.  
 *                         If not set, black will be used.
 */
function flpl_create(bgcolor)
{
	if (bgcolor == null)
	{	
		if (flpl_bg_color == null)
		{	
			// if no master bg color is set, use black.
			bgcolor = flpl_bg_color = "000000";
		}
		else
		{
			// there was a master color set, use it.
			bgcolor = flpl_bg_color;
		}
	}
	else
	{
		// bgcolor param was passed in, override the existing bg color.
		flpl_bg_color = bgcolor;
	}
	
	// If player side margins were specified, allow for side margins now.
	var sidemargin_divtext = "";
	if (pldv_side_margin > 0)
	{
		sidemargin_divtext = '<div style="width: ' + pldv_side_margin + '%; float: left; height: 20px;"></div><div style="width: '+ pldv_side_margin + '%; float: right; height: 20px;"></div>';
	}
	var tempwidth = (100 - (2*pldv_side_margin)) + "%";

	// Assemble Flash object or embed tag.
	var flash_code = sidemargin_divtext;
	if (isIE)
	{
		flash_code += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0"';
		flash_code += 'width="100%" height="100%" id="flpl_player">';
		flash_code += '<param name="movie" value="' + flpl_player_swf_path + '" />';
		flash_code += '<param name="quality" value="high" />';
		flash_code += '<param name="scale" value="noscale" />';
		flash_code += '<param name="salign" value="lt" />';
		flash_code += '<param name="bgcolor" value="#'+ bgcolor +'" />';
		flash_code += '<param name="wmode" value="opaque" />';
		flash_code += '<param name="swliveconnect" value="true" />';
		flash_code += '<param name="allowfullscreen" value="true" />';
		flash_code += '<param name="allowscriptaccess" value="always" />';
		flash_code += '</object>';
	}
	else
	{
		flash_code += '<div style="width: ' + tempwidth + '; height: 100%; float: left;">';
		flash_code += '<embed src="' + flpl_player_swf_path + '" quality="high" scale="noscale" allowfullscreen="true" ';
		flash_code += 'allowscriptaccess="always" salign="lt" bgcolor="#'+ bgcolor +'" width="100%" height="100%" wmode="opaque" ';
		flash_code += 'name="flpl_player" swliveconnect="true" type="application/x-shockwave-flash" '
		flash_code += 'pluginspage="http://www.macromedia.com/go/getflashplayer" /></div>';
	}

	flpl_sort_skins();

	// Assign flash code to player div and set player status.
	pldv_player_div.innerHTML = flash_code;
	pldv_status = 2;
}

/***** flpl_object REQUEST AND REPLY functions.  Allows coordination of variable data between JS and flpl_object. *****/

/**
 * flpl_request_initialize is a function that is called by FVP as soon as videoplayer.swf loads, in order to retrieve initial
 * variables and settings from JS.  At this time, since it is certain that the FVP has loaded completely, the reference to
 * the FVP is made (and stored in flpl_object) for future use.  See documentation for more information.
 *
 * @return object send_to_flash This is an object containing various values needed to set up initial state of FVP.
 */
function flpl_request_initialize()
{
	flpl_object = isIE ? document.getElementById("flpl_player") : document["flpl_player"];
	
	if (flpl_width == 0)
	{
		flpl_width = pldv_player_width;
	}
	if (flpl_height == 0)
	{
		flpl_height = pldv_player_height;
	}
	if (!flpl_standalone_mode_on)
	{
		flpl_standalone_mode_on = false;
	}
	
	// Make sure the right SIZE skin is being used, if more than one is available.
	flpl_check_skin(flpl_width, flpl_height);
	
	var send_to_flash = {
		flpl_skins_dir: flpl_skins_dir,
		flpl_video_api_url: flpl_video_api_url,
		flpl_billing_api_url: flpl_billing_api_url,
		flpl_billing_success_url: flpl_billing_success_url,
		flpl_username: flpl_username,
		flpl_ad_buffer_time: flpl_ad_buffer_time,
		flpl_login_function: flpl_login_function,
		flpl_stored_volume: flpl_stored_volume,
		flpl_init_width: flpl_width, 
		flpl_init_height: flpl_height,
		flpl_standalone: flpl_standalone_mode_on
	};

	return send_to_flash;
}

/**
 * flpl_request_standalone is a function that is called by FVP after flpl_request_initialize, if flpl_standalone_mode_on
 * has been set to true.  This indicates that the FVP should operate in "standalone" mode, which can be used when API
 * calls are limited or not needed, for special cases where video URLs will be provided directly in Javascript or HTML,
 * such as the case of certain mini-sites or promotional pages.
 * Information on variables:
 * 		flpl_standalone_skin_xml: this can be empty/null if API will be used to retrieve skin XML, or can
 *								contain the path or URL to an XML file containing special stand alone skin XML.
 *		flpl_standalone_vid_url: (required) This is the url to the media that will be played in FVP upon load.
 *		flpl_standalone_ad: this can be empty/null if no LightningCast ad is needed, or should be an LC Affiliate:site pair
 *							if LC ads are desired.
 *		flpl_standalone_autostart: this is a boolean indicating if the specified media should automatically start
 *							after loading.  Can be empty/null but if so will default to true in FVP.
 *       flpl_standalone_duration: this is an integer or float, representing the duration of the flash video in seconds.
 *                           This is optional - should be used if a long-duration HTTP video is used and metadata isn't
 *                           arriving at the player fast enough.  If the progress bar misbehaves with an HTTP video in
 *                           standalone mode, use this!
 * @return object send_to_flash This is an object containing various values needed to set up standalone mode in FVP.
 */
function flpl_request_standalone()
{
	var send_to_flash = {
		flpl_standalone_skin_xml: flpl_standalone_skin_xml,
		flpl_standalone_vid_url: flpl_standalone_vid_url,
		flpl_standalone_ad: flpl_standalone_ad,
		flpl_standalone_autostart: flpl_standalone_autostart,
		flpl_standalone_duration: flpl_standalone_duration
	};
						
	return send_to_flash;
}

/**
 * flpl_request_buffer_time is a function that is called by FVP before playing back a normal (non-ad) video.
 * The value represents how many seconds of video should be buffered before playback will begin.
 *
 * @return int flpl_buffer_time This is the positive integer representing buffer time in seconds.
 */
function flpl_request_buffer_time()
{
	return flpl_buffer_time;
}

/**
 * flpl_request_login_status is a function that is called by FVP if user requests a video that requires login, 
 * and they are not already logged in, FVP will call flpl_login_function (whatever JS function that value represents).
 * Afterwards, this function is polled by flpl_object to see if the login attempt was successful.
 *
 * @return string flpl_login_status This should be "success", "failed", or a null or empty value.
 */
function flpl_request_login_status()
{
	return flpl_login_status;
}

/**
 * flpl_request_username is a function that is called by FVP to request the current username.
 * This will happen when the FVP receives Status XML about a video that indicates that login is required.
 * If the user logs in successfully after such, the FVP will execute this function to retrieve the current username.
 *
 * @return string flpl_username This should be the current username string that will be used by FVP to retrieve
 *                                 new Status XML after login.
 */
function flpl_request_username()
{
	// Gets called after successful login, to update the flash player.
	return flpl_username;
}

/**
 * flpl_reply_jiffy is a function that is called by FVP on interval (multiple times per second)
 * to make sure that JS has current information about FVP's properties.  FVP also checks JS
 * vars for any changes that have occurred since last update, so this function is the MAJOR
 * method of communication both to and from the FVP and Javascript.
 *
 * @param {Object} responseObject This object contains current playback time and playback status (optional).
 * @return object send_to_flash This object contains JS information pertinent to FVP that may have
 *                                 changed since last flpl_reply_jiffy was called.
 */
function flpl_reply_jiffy(responseObject)
{
	// This is called by the flpl_object about 6 times per second (depends on what FPS is set in videoplayer.swf).
	// The player sends relevant information to JS, such as playback time and player status.
	// When called, JS sends current information back to the player.
	if (responseObject)
	{	// Make sure to set the JS vars only if Flash sent data.  flpl_object may call this function without params at startup.
		flpl_play_time = responseObject.flpl_play_time;
		flpl_play_status = responseObject.flpl_play_status;
		if ((flpl_play_status == "error") && (flpl_playing_ad))
		{
			flpl_hide_ext_ad();
		}
	}

	var send_to_flash = {
		flpl_vid_id: flpl_vid,
		flpl_skin_id: flpl_skin_id,
		flpl_scalemode: flpl_scalemode,
		flpl_viewmode: flpl_viewmode,
		flpl_skin_width: flpl_width,
		flpl_skin_height: flpl_height
	};

	// Reset width and height indicators for now, or flpl_object will attempt resize every 1/12 second.
	flpl_width = 0;
	flpl_height = 0;
	return send_to_flash;
}

/**
 * flpl_reply_user_event is a function that is called by FVP when a user
 * changes a setting via a button or control within the FVP.  These settings include
 * volume, viewmode, and scalemode.
 *
 * @param {Object} responseObject - contains the current values of volume, viewmode and scalemode from FVP (required).
 */
function flpl_reply_user_event(responseObject)
{
	if (responseObject.flpl_volume != null)
	{
		flpl_volume = responseObject.flpl_volume;
		if (flpl_volume > -1)
		{
			// Write the current volume to a cookie for later.
			flpl_create_vol_cookie();
			flpl_stored_volume = flpl_volume;
		}
	}
	if (responseObject.flpl_viewmode != null)
	{
		flpl_viewmode = responseObject.flpl_viewmode;
	}
	if (responseObject.flpl_scalemode != null)
	{
		flpl_scalemode = responseObject.flpl_scalemode;
	}
}


/**
 * flpl_setviewmode is a function used to set the viewmode of the FVP.
 * Viewmode options include "minimize", "double", "default".  Other viewmode
 * values used within FVP inclulde "normal" and "fullscreen", but these cannot be
 * used via JS.  The FVP will update with this value when it executes its next
 * flpl_reply_jiffy cycle.
 * Detail of mode types:  
 *    "minimize" will call pldv_hide and cause a minimization animation.
 *    "double" will cause the player (and div) to resize to twice the width
 *        and height of the "default" size of the current skin, but no larger
 *        than the currently visible document area.
 *    "default" will cause the player (and div) to resize to the initial width
 *        and height that it originally loaded as (if the user has resized it since load).
 * Usage: This function can be called directly, in case html/javascript controls
 * are needed for the player to adjust this setting.  Otherwise, this is not
 * used internally.
 *
 * @param {String} mode A string representing one of the three modes.
 */
function flpl_setviewmode(mode)
{
	// Sets the viewmode of the player.  Options are "minimize", "double", "default".  
	// Cannot force player to "fullscreen" from JS.
	if (flpl_object && (flpl_viewmode !="minimize")) 
	{
		flpl_object.set_viewmode(mode);
	}
}

/**
 * flpl_set_ext_ad is a function that is called when an external LightningCast banner ad is
 * to be displayed.  This function is called via the FVP only if the flpl_alt_ad_div has been set.
 * If flpl_alt_ad_div has not been set, the external banner will not be used.  This function sets
 * the url and click url variables with values passed from FVP, which obtains them via the LightningCast
 * Ad API.
 *
 * @param {String} ban_url The source URL of the banner ad, which should be a SWF, JPG, GIF or PNG (required).
 * @param {String} img_click_url A url that the banner should navigate to if the user clicks it (required).
 */
function flpl_set_ext_ad(ban_url, img_click_url)
{
	if (flpl_alt_ad_div)
	{
		flpl_alt_ad_url = ban_url;
		flpl_alt_ad_clickurl = img_click_url;
	}
}

/**
 * flpl_show_ext_ad is a function that is called when an external LightningCast banner ad is
 * to be displayed.  This function is called via the FVP, after flpl_set_ext_ad has been called.
 *
 */
function flpl_show_ext_ad()
{
	flpl_playing_ad = true;
	if (flpl_alt_ad_div && (flpl_alt_ad_url != ""))
	{
		var swf_found = flpl_alt_ad_url.indexOf(".swf");
		var banner_code = "";
		
		if (flpl_alt_use_css)
		{
			flpl_alt_ad_div.className = "pldv_ad_visible";
		}
		
		// Clean up any old ad swf that might be hanging around.
		var old_flash_ad = document.getElementById("flpl_banner");
		if (old_flash_ad)
		{
			old_flash_ad = null;		
		}
		
		if (swf_found >= 0)
		{
			// Handle SWF Banner.  How to handle onclick?
			// need to split url to extract any loadvars.

			if (isIE)
			{
				banner_code += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0"';
				banner_code += 'width="'+ flpl_alt_ad_w +'" height="'+ flpl_alt_ad_h +'" id="flpl_banner">';
				banner_code += '<param name="movie" value="'+ flpl_alt_ad_url +'" />';
				banner_code += '<param name="quality" value="high" />';
				banner_code += '<param name="scale" value="noscale" />';
				banner_code += '<param name="salign" value="lt" />';
				banner_code += '<param name="swliveconnect" value="true" />';
				banner_code += '<param name="allowscriptaccess" value="always" />';
				banner_code += 	'</object>';
			}
			else
			{
				banner_code += '<embed src="'+ flpl_alt_ad_url +'" quality="high" scale="noscale" ';
				banner_code += 'allowscriptaccess="always" salign="lt" width="'+ flpl_alt_ad_w +'" height="'+ flpl_alt_ad_h +'" ';
				banner_code += 'name="flpl_banner" swliveconnect="true" type="application/x-shockwave-flash" '
				banner_code += 'pluginspage="http://www.macromedia.com/go/getflashplayer" />';
			}
		}
		else
		{
			// Handle Image Banner
			banner_code = '<img src="' + flpl_alt_ad_url + '" onclick="flpl_go_ext_ad_url(); return false;" style="cursor: pointer;" alt="" />';
		}
		flpl_alt_ad_div.innerHTML = banner_code;
	}
}

/**
 * flpl_vid_complete is triggered when the current video loaded into the Flash player has ended.
 * This is needed to trigger the next video to play if the playlisting functionality is active.
 * The function is called from within the flpl_object. No parameters or return values.
 *
 */
function flpl_vid_complete()
{
	if (flpl_playlisting_on)
	{
		// Playlisting is active, so set the video id to the next up in the playlist.
		if (flpl_playlist_nextvid && (flpl_playlist_nextvid != flpl_vid))
		{
			pldv_playvideo(flpl_playlist_nextvid, "flash");
			// We can't just change the video id alone and let the flpl_object 
			// pick up the new video id alone, because we will need to repopulate 
			// the video's metadata area with new playlisted material, and metatdata
			// population only occurs if pldv_playvideo is called.
		}
	}
}

/**
 * flpl_go_ext_ad_url is executed on an onclick event, when an external LightningCast banner ad
 * has been clicked, if the LC banner is a jpg, gif or png.  Assigned in flpl_show_ext_ad.  It
 * opens the banner ad's clickurl in a new window.
 *
 */
function flpl_go_ext_ad_url()
{
	if (flpl_alt_ad_clickurl != "")
	{
		var ad_win = window.open(flpl_alt_ad_clickurl, "ad_win");
	}
}

/**
 * flpl_hide_ext_ad is a function that hides the external LightningCast clickable banner div,
 * if present.  Called by the FVP after ad playback is done, as well as pldv_hide, pldv_hide_player
 * and pldv_show, to make sure the ad div isn't visible at an inappropriate time.
 *
 */
function flpl_hide_ext_ad()
{
	flpl_playing_ad = false;
	if (flpl_alt_ad_div)
	{
		flpl_alt_ad_div.innerHTML = "";
		if (flpl_alt_use_css) 
		{
			flpl_alt_ad_div.className = "pldv_ad_invisible";
		}
	}
}

/// FLPL Cookie Functions ///
/**
 * flpl_create_vol_cookie writes the current flpl_volume to a cookie.
 * Called by flpl_reply_user_event.
 *
 */
function flpl_create_vol_cookie()
{
	var name = flpl_stored_volume_cookiename;
	var value = flpl_volume;

	// Set up the expiration date.
	var days = flpl_stored_volume_days_to_expire;
	var date = new Date();
	date.setTime(date.getTime() + (days*24*60*60*1000));
	var expires = "; expires=" + date.toGMTString();

	// Write the cookie.
	document.cookie = name + "=" + value + expires + "; path=/";
}



/**
 * flpl_read_vol_cookie looks for a stored previous flpl_volume from a cookie.
 * Called when this JS file loads.
 *
 * @return int (percentage stored volume) or null
 */
function flpl_read_vol_cookie()
{
	var name = flpl_stored_volume_cookiename;
	var name_equal = name + "=";
	var cookie_array = document.cookie.split(';');

	// Go through the document's cookies and look for the volume cookie.
	for (var i=0; i < cookie_array.length; i++)
	{
		var cookie = cookie_array[i];
		while (cookie.charAt(0)==' ')
		{
			cookie = cookie.substring(1,cookie.length);
		}
		if (cookie.indexOf(name_equal) == 0)
		{
		   // Found the volume cookie, return the value.
			var volume = parseInt(cookie.substring(name_equal.length,cookie.length));
			return volume;
		}
	}
	// Didn't find the cookie, return null instead.
	return null;
}

/** 
 * flpl_sort_skins sorts flpl_skin_array if it contains any objects.  
 * Called when flpl_object is created so that skins are ordered from smallest to 
 * largest in flpl_skin_array - so that skin switching works properly.  
 * Prepares flpl_skin_array for evaluation by flpl_check_skin in video_div_movement.js.  
 *
 */ 
function flpl_sort_skins() 
{ 
	if (flpl_skin_array && (flpl_skin_array.length > 0))
	{ 
		for (var i = 0; i < flpl_skin_array.length; i++) 
		{ 
			// Parse for nulls, and change to int values.  
			if (flpl_skin_array[i].minw == null) 
			{ 
				flpl_skin_array[i].minw = 0; 
			} 

			if (flpl_skin_array[i].minh == null) 
			{ 
				flpl_skin_array[i].minh = 0; 
			} 

			if (flpl_skin_array[i].maxw == null) 
			{ 
				flpl_skin_array[i].maxw = 50000; 
			} 

			if (flpl_skin_array[i].maxh == null) 
			{ 
				flpl_skin_array[i].maxh = 50000; 
			} 
		} 

		// Now, sort widthwise.  
		flpl_skin_array.sort(flpl_by_minwidth); 
	
		// Now, sort heightwise.  
		flpl_skin_array.sort(flpl_by_minheight); 
	} 
} 


 
/** 
 * flpl_by_minwidth is used by flpl_sort_skins, as a sorting function.  
 * Allows sorting of array items using minw and maxw property.  
 *
 * @param {Object} a - first item to be sorted 
 * @param {Object} b - second item to be sorted 
 * @return int (-1, 0 or 1) which denotes order 
 */ 
function flpl_by_minwidth(a, b) 
{ 
	// Helper for flpl_sort_skins 
	var a_min_width = a.minw; 
	var b_min_width = b.minw; 

	if (a_min_width < b_min_width) 
	{ 
		return -1; 
	} 

	if (a_min_width > b_min_width) 
	{ 
		return 1; 
	} 

	// Minimum values are the same!  So now check maxw property.  
	var a_max_width = a.maxw; 
	var b_max_width = b.maxw; 

	if (a_max_width < b_max_width) 
	{ 
		return -1; 
	} 

	if (a_max_width > b_max_width) 
	{ 
		return 1; 
	} 

	// All width properties match.  
	return 0; 
} 
 
/** 
 * flpl_by_minheight is used by flpl_sort_skins, as a sorting function.  
 * Allows sorting of array items using minh and maxh property.  
 *
 * @param {Object} a - first item to be sorted 
 * @param {Object} b - second item to be sorted 
 * @return int (-1, 0 or 1) which denotes order 
 */ 
function flpl_by_minheight(a, b) 
{ 
	// Helper for flpl_sort_skins 
	var a_min_height = a.minh; 
	var b_min_height = b.minh; 

	if (a_min_height < b_min_height) 
	{ 
		return -1; 
	} 

	if (a_min_height > b_min_height) 
	{ 
		return 1; 
	} 
            
	// Minimum values are the same!  So now check maxw property.  
	var a_max_height = a.maxh; 
	var b_max_height = b.maxh; 

	if (a_max_height < b_max_height) 
	{ 
		return -1; 
	} 

   	if (a_max_height > b_max_height) 
	{ 
		return 1; 
	} 
            
	// All height properties match.  
	return 0; 
}



/**
 * pldv_slide_animate is a set of functions used to animate the minimization or return from minimization of
 * the floating player div.  When used to minimize, the floating player div is moved to an invisible position
 * and an animation div is assigned to the previous width, height and location as the player div.
 * The animation div is then moved and resized until it matches the size of the finish_el.
 * When used to "restore", the animation element starts off at the same size and location as the
 * "home" div, and is resized and moved until it matches the previous location of the floating player div.
 * The floating player div is then made visible.  At the end of both cycles, the animation div becomes invisible.
 *
 * @param {String} ani_el The id of the div that is to be used to animate.
 * @param {String} finish_el The id of the target div, that the ani_el will move to.
 * @param {String} end_state Should either be "minimize" or "restore".
 * @param {boolean} unload Optional param, when used with end_state == "minimize", will
 *							unload any video present in the flash player.
 */
function pldv_slide_animate(ani_el, finish_el, end_state, unload)
{
	if (unload == null)
	{
		unload = false;
	}
	
	var slide_obj =document.getElementById(ani_el);
	var finish_obj = document.getElementById(finish_el);
	var startX, startY, endX, endY;
	var startWidth, startHeight, endWidth, endHeight;
	var w_d, h_d, x_d, y_d;
	var self, interval;	
	var speed = 30;
	var interval_time = 20;
	
	if (end_state && (slide_obj) && (finish_obj))
	{
		switch (end_state)
		{
			case "minimize":
				if ((parseInt(pldv_div.style.left) > -50)&&(slide_obj.style.display != "block"))
				{
					startX = parseInt(pldv_div.style.left);
					startY = parseInt(pldv_div.style.top);
					endX = parseInt(pldv_getOffsetX(finish_el));
					endY = parseInt(pldv_getOffsetY(finish_el));
					startWidth = parseInt(pldv_getOffsetWidth(pldv_id));
					startHeight = parseInt(pldv_getOffsetHeight(pldv_id));
					endWidth = parseInt(pldv_getOffsetWidth(finish_el));
					endHeight = parseInt(pldv_getOffsetHeight(finish_el));	
					start_slide();
				}
				break;
			case "restore":
				if ((parseInt(pldv_div.style.left) < -50)&&(slide_obj.style.display != "block"))
				{
					startX = parseInt(pldv_getOffsetX(finish_el));
					startY = parseInt(pldv_getOffsetY(finish_el));
					endX = parseInt(pldv_slidehome_pos_x);
					endY = parseInt(pldv_getOffsetY(pldv_id));
					startWidth = parseInt(pldv_getOffsetWidth(finish_el));
					startHeight = parseInt(pldv_getOffsetHeight(finish_el));
					endWidth = parseInt(pldv_getOffsetWidth(pldv_id));
					endHeight = parseInt(pldv_getOffsetHeight(pldv_id));
					
					endX = pldv_check_offsetX(endX, endWidth, pldv_sh_offset_x);
					if ((endX != parseInt(pldv_slidehome_pos_x)) && (endX != -3000))
					{
						pldv_slidehome_pos_x = endX + "px";
					}
					
					endY = pldv_check_offsetY(endY, endHeight, pldv_sh_offset_y);
					pldv_div.style.top = endY + "px";

					start_slide();
				}
			default:
				break;
		}
	}
	
	/**
	 * Begins the animation by making the animation div visible setting its start location.
	 */
	function start_slide() 
	{
		pldv_animating = true;
		self = this;
		slide_obj.style.width = startWidth + "px";
		slide_obj.style.height = startHeight + "px";
		slide_obj.style.left = startX + "px";
		slide_obj.style.top = startY + "px"
		slide_obj.style.display = "block";
		
		if (end_state == "minimize")
		{
			// Store the current x location of the player div, and move it so it is not visible.
			// Cannot use style.display = none or opacity = 0, since that would unload the player object.
			// So, to get around this, move it to an absolute negative position.
			if (parseInt(pldv_div.style.left) != -3000)
			{
				pldv_slidehome_pos_x = pldv_div.style.left;
			}
						
			// set pldv_sh_offset.  These values will be used to reset the pldv_div position on restore, if user scrolls the browser window.
			pldv_sh_offset_x = parseInt(pldv_div.style.left) + offsetx;
			pldv_sh_offset_y = parseInt(pldv_div.style.top) + offsety;
			
			pldv_div.style.left = "-3000px";
			
			if (pldv_status == 2)
			{	
				// If flash player loaded...
				if (unload)
				{
					// unload the current video or swf from the player.
					flpl_object.unload();
					flpl_vid = "";
				}
				else
				{
					// If flash plugin is installed, cease playback, since the player will be hidden.
					if (flpl_object)
					{
						flpl_object.pbk_pause();
					}
				}
			}
		}
		w_d = (startWidth < endWidth) ? 1 : -1;
		h_d = (startHeight < endHeight) ? 1 : -1;
		x_d = (startX < endX) ? 1 : -1;
		y_d = (startY < endY) ? 1 : -1;
		
		// Create the animation interval.
		interval = setInterval(slide_check, interval_time);
	};



	/** 
	 * Executed on an interval, this function periodically changes the size and location of the
	 * animation div to simulate shrinking or stretching for minimization or restore.
	 */
	function slide_check()
	{
		var width_ended = true;
		var height_ended = true;
		var x_ended = true;
		var y_ended = true;

		if (end_state == "restore")
		{
			// put a check in to see if the login window is working.
			if (pldv_hide_immediate_override)
			{
				slide_obj.style.width = endWidth + "px";
				slide_obj.style.height = endHeight + "px";
				slide_obj.style.left = endX + "px";
				slide_obj.style.top = endY + "px";
				width_ended = true;
				height_ended = true;
				x_ended = true;
				y_ended = true;
			}
			
		}

		if (parseInt(slide_obj.style.width) != endWidth)
		{
			width_ended = false;
			slide_obj.style.width = (parseInt(slide_obj.style.width) + (w_d*speed)) + "px";
			if (Math.abs(parseInt(slide_obj.style.width) - endWidth) < (1.5 * speed))
			{
				slide_obj.style.width = endWidth + "px";
				width_ended = true;
			}
		}
		if (parseInt(slide_obj.style.height) != endHeight)
		{
			height_ended = false;
			slide_obj.style.height = (parseInt(slide_obj.style.height) + (h_d*speed)) + "px";
			if (Math.abs(parseInt(slide_obj.style.height) - endHeight) < (1.5 * speed))
			{
				slide_obj.style.height = endHeight + "px";
				height_ended = true;
			}
		}
		if (parseInt(slide_obj.style.left) != endX)
		{
			x_ended = false;
			slide_obj.style.left = (parseInt(slide_obj.style.left) + (x_d*speed)) + "px";
			if (Math.abs(parseInt(slide_obj.style.left) - endX) < (1.5 * speed))
			{
				slide_obj.style.left = endX + "px";
				x_ended = true;
			}
		}
		if (parseInt(slide_obj.style.top) != endY)
		{
			y_ended = false;
			slide_obj.style.top = (parseInt(slide_obj.style.top) + (y_d*speed)) + "px";
			if (Math.abs(parseInt(slide_obj.style.top) - endY) < (1.5 * speed))
			{
				slide_obj.style.top = endY + "px";
				y_ended = true;
			}
		}
	
		if (width_ended && height_ended && x_ended && y_ended)
		{	
			pldv_animating = false;
			// Destination size/location reached.  Stop the interval, and perform any final actions.	
			if (end_state == "minimize")
			{
				slide_obj.style.display = "none";
				pldv_minimized = true;
			}
			else
			{
				slide_obj.style.display = "none";
				if (!pldv_hide_immediate_override)
				{
					pldv_div.style.left = pldv_slidehome_pos_x;
				
					// If the flpl_object exists, tell it to activate its return-from-minimization code.
					if (flpl_object)
					{
						flpl_object.unmini();
					}
			
					// Reset minimization and viewmode flags.
					pldv_minimized = false;
					if (flpl_viewmode == "minimize")
					{
						flpl_viewmode = "normal";
					}
				}
				else
				{
					pldv_hide_immediate_override = false;
				}	
			}
			clearInterval(interval);
		}
	};
}

//////////////////////// Dragging and resize handle functions.

/**
 * pldv_resizehandle is a class used to allow a div within pldv_div to act as
 * a resize handle to resize pldv_div and pldv_player_div if the user desires.
 * Object el must be assigned to an existing div before becoming a resize handle.
 * Usage:  if (pldv_resizer) new pldv_resizehandle(pldv_resizer);
 * Found in video_players.js, within pldv_initialize.
 *
 * @constructor
 * @param {Object} el This is a reference to the div that should be used as the resize handle (required).
 */
function pldv_resizehandle(el)
{
	// These vars keep track of any old document mouseup or mousemove assignments.
	var old_mouseup, old_mousemove;
	
	// Assign mousedown for the div
	el.onmousedown = resize_mousedown;
	
	/**
	 * resize_enddrag is a method of pldv_resizehandle, and is executed when user
	 * releases the mouse button after clicking on the resize div.
	 */
	function resize_enddrag()
 	{
		// Occurs when user stops dragging.
		// Causes the flpl_object to rescale itself to fit the newest size of the pldv_player_div.
		
		// Reset any old existing mouse behaviors that may have existed before the resize event.
		document.onmouseup = old_mouseup;
		document.onmousemove = old_mousemove;
		
		var new_width = parseInt(pldv_player_div.style.width);
		var new_height = parseInt(pldv_player_div.style.height);
		
		
		// Resize for Flash Video Player
		if (pldv_status == 2)
		{	  
			flpl_resize(new_width, new_height, "normal");
		}
	}


	
	/**
	 * resize_drag is a method of pldv_resizehandle, and is executed when user
	 * releases the mouse button after clicking on the resize div.
	 *
	 * @param {Event} e The event activated upon mousemove after user clicks resize handle.
	 * @return false
	 */
	function resize_drag(e)
	{
		// Occurs repeatedly while user moves mouse after clicking on the resize handle.
		// Resizes the pldv_player_div.
		// The flpl objects only get resized after the user releases the mouse.
		e = e || window.event;
		
		// Get the height of the metadata display area and the height of the dragbar.
		var meta_height = parseInt(pldv_getOffsetHeight(pldv_meta_div_id));
		var drag_height = parseInt(pldv_getOffsetHeight(pldv_dragbar_div_id));
		
		// Get the real browser window inner dimensions.
		var dimensions = pldv_getDocumentDims();
		var docwidth = dimensions.width;
		var docheight = dimensions.height;
		
		// Determine the scrolled offset of the window - if user has scrolled down or to the right on the page.
		var offsetx = pldv_getWindowOffsetX();
		var offsety = pldv_getWindowOffsetY();
		
		// Find the width and height of the player div, in relation to the mouse position and the upper left corner of the div.
		var this_width = e.clientX - parseInt(pldv_div.style.left);
		var this_height = e.clientY  - parseInt(pldv_div.style.top) - meta_height;
		
		// Check to make sure the user isn't resizing out of bounds.
		var total_width = parseInt(pldv_getOffsetWidth(el.id));
		var total_height = this_height + meta_height + drag_height;
		var height_check = e.clientY + parseInt(pldv_getOffsetHeight(el.id))/2;
		if (((this_width + total_width) < docwidth)
				&& (e.clientX < docwidth)
				&& (total_height < docheight) 
				&& (height_check < docheight))
		{
			// check minimium sizes	
			if ((this_width + offsetx) < pldv_min_w)
			{
				this_width = pldv_min_w - offsetx;
			}
			if ((this_height + offsety) < pldv_min_h)
			{
				this_height = pldv_min_h - offsety;
			}

			pldv_set_div_size(this_width + offsetx + 5 , this_height + offsety - (parseInt(pldv_getOffsetWidth(el.id))));
		}
		return false;
	}


	
	/**
	 * resize_mousedown is a method of pldv_resizehandle, and is executed when user
	 * presses the mouse button over the resize div.
	 *
	 * @param {Event} e The event activated upon mousedown when user clicks resize handle.
	 * @return false
	 */
	function resize_mousedown(e)
	{
		// Initiates a drag event, occurs when user clicks the resize handle.
		e = e || window.event;
		
		var target = (e && e.target) || (window.event && window.event.srcElement);
		// We may need to prevent WMP from resizing in FireFox.
		// Save any existing mouseup/mousemove functions that may have been set before the user resized.
		old_mouseup = document.onmouseup;
		old_mousemove = document.onmousemove;
		if (target == el)
		{
			// Only begin dragging if the mousedown event occurred from the resize handle.
			resize_enddrag();	// Make sure no other mousedrags are happening at the moment.
			document.onmouseup = resize_enddrag;
			document.onmousemove = resize_drag;
		}
		return false;
	}
}


/**
 * pldv_dragbar is a class used to allow a div within pldv_div to act as
 * a draggable handle to reposition pldv_div and pldv_player_div if the user desires.
 * Object el must be assigned to an existing div before becoming a dragbar.
 * Usage: if (pldv_dragbar_div) new pldv_dragbar(pldv_dragbar_div);
 * Found in video_players.js, within pldv_initialize.
 *
 * @param {Object} el This is a reference to the div that should be used as the dragbar handle (required).
 */
function pldv_dragbar(el)
{
	var click_offsetx = 0;
	var click_offsety = 0;
	var old_mouseup, old_mousemove;
	
	old_mouseup = document.onmouseup;
	old_mousemove = document.onmousemove;
	
	el.onmouseup = enddrag;
	el.onmousedown = drag_mousedown;
	
	/**
	 * enddrag is a method of pldv_dragbar, and is executed when user
	 * releases the mouse button and/or when dragging is complete.
	 * @param {Event} e The event activated upon mouseup when user releases the mouse after clicking the drag handle.
	 */
	function enddrag(e)
	{
		// Occurs when user releases mouse after dragging.
		document.onmouseup = old_mouseup;
		document.onmousemove = old_mousemove;
	}
	
	/**
	 * drag is a method of pldv_dragbar, and is executed repeatedly as the user
	 * moves the mouse after clicking the dragbar handle div.  The function
	 * repositions the player div appropriately within the browser window, disallowing
	 * position adjustment outside of the visible browser window area.
	 * @param {Event} e The event activated upon mousemove when drags mouse after clicking drag handle.
	 * @return false
	 */
	function drag(e)
	{
		// Occurs when user moves mouse (drags) after a mousedown occurs on the dragbar element.
		e = e || window.event;
		if ((parseInt(pldv_getOffsetX(pldv_id)) > -50)&&(!pldv_minimized))
		{
			// Determine the scrolled offset of the window - if user has scrolled down or to the right on the page.
			var offsetx = pldv_getWindowOffsetX();
			var offsety = pldv_getWindowOffsetY();
		
			var dimensions = pldv_getDocumentDims();
			var docwidth = dimensions.width;
			var docheight = dimensions.height;
			// Window restraints - prevents user from dragging pldv_div outside of the current window boundaries.
			if ((e.clientX - click_offsetx - offsetx + parseInt(pldv_getOffsetWidth(pldv_id))  < docwidth)
				&& (e.clientX - click_offsetx - offsetx > 0))	
			{
	  			pldv_div.style.left = (e.clientX - click_offsetx) + "px" ;
			} 
			if ((e.clientY - offsety - click_offsety + parseInt(pldv_getOffsetHeight(pldv_id)) < docheight )
				&& (e.clientY - click_offsety - offsety > 0)) 
			{
				pldv_div.style.top = (e.clientY - click_offsety) + "px";
			} 
		}
		else
		{
			// The user may have clicked the flpl_object's minimize button while near the edge of the browser window, while
			// a drag event was still active.  If so, stop the drag event so that the minimize animation isn't interrupted.
			enddrag();
		}
		return false;
	}
	
	/**
	 * drag_mousedown is a method of pldv_dragbar, and is executed when user clicks
	 * the drag handle div.  This starts the drag cycle.
	 * @param {Event} e The event activated upon mousedown when user clicks the drag handle.
	 * @return false
	 */
	function drag_mousedown(e)
	{
		// Occurs when user clicks down on the dragging element.
		e = e || window.event;
		var target = (e && e.target) || (window.event && window.event.srcElement); 
		if (target.id == el.id)
		{
			enddrag(); // Make sure any other drag events are cleared.
   			click_offsetx = parseInt(e.clientX) - parseInt(pldv_getOffsetX(pldv_id));
			click_offsety = parseInt(e.clientY) - parseInt(pldv_getOffsetY(pldv_id));
			old_mouseup = document.onmouseup;
			old_mousemove = document.onmousemove;
			document.onmouseup = enddrag;
			document.onmousemove = drag;
		}

		return false;
	}
}

///////////// Resizing functions for setting size of pldv_div and pldv_player_div, and rescaling flpl_object.


/**
 * flpl_resize is a function used to resize the flash video player and the pldv_player_div.
 * It is used when the player div has been resized (ie via the resize handle).
 * @param {int} new_width This is the desired new width of the player div.
 * @param {int} new_height This is the desired new height of the player div.
 * @param {String} mode This is the viewmode, which is passed to the Flash player.
 */
function flpl_resize(new_width, new_height, mode)
{
	// Resizes the flash video player and the pldv_player_div.
	if (flpl_object)
	{
		pldv_set_div_size(new_width, new_height);

		// Now, reset the skin if necessary.
		flpl_check_skin(new_width, new_height);

		// Need to wait a moment before telling the flash object to resize so the player doesn't scale before the div is done sizing.
		setTimeout('flpl_object.resize_skin(' + new_width + ', ' + new_height + ', "' + mode + '");', 35);	
	}
}

/**
 * flpl_check_skin is a function used to make sure the appropriate skin is being used
 * when the flash player is resized, in case there is more than one skin available in 
 * the flpl_skin_array.
 * @param {int} new_width This is the new width of the player.
 * @param {int} new_height This is the new height of the player.
 */
function flpl_check_skin(new_width, new_height)
{
	// If there are multiple sizes of skins available, chooses the correct one for the particular width and height.
	// Performed on flpl_resize, as well as when switching from WMP to FLV playback.

	var new_id = flpl_skin_id;
	if ((flpl_skin_array != null) && (flpl_skin_array.length > 0))
	{	
		var found = false;
		for (i = 0; i < flpl_skin_array.length; i++)
		{
			if (found)
			{
				break;
			}
			if ((new_width >= flpl_skin_array[i].minw)
				&& (new_height >= flpl_skin_array[i].minh))
			{	
				new_id = flpl_skin_array[i].id;
				if ((new_width <= flpl_skin_array[i].maxw)&&(new_height <= flpl_skin_array[i].maxh))
				{
					found = true;
				}
			} 
		}		
	}
	if (new_id != flpl_skin_id)
	{
		flpl_skin_id = new_id;
	}
}

/**
 * flpl_resize_restricted is a wrapper for flpl_resize, only to be used in special cases.
 * When the flash player viewmode is set to "double" or "default", the player div gets
 * resized, and we need to make sure that the player isn't resized larger than the
 * visible area of the document in the browser.  See documentation.
 *
 * @param {int} new_width This is the desired new width of the player div.
 * @param {int} new_height This is the desired new height of the player div.
 * @param {String} mymode This is the viewmode, which is passed to the Flash player.
 */
function flpl_resize_restricted(new_width, new_height, mymode)
{
	if (flpl_object)
	{
		var dimensions = pldv_getDocumentDims();
		var docwidth = dimensions.width;
		var docheight = dimensions.height;
		var offsetx = pldv_getWindowOffsetX();
		var offsety = pldv_getWindowOffsetY();
		var meta_height = parseInt(pldv_getOffsetHeight(pldv_meta_div_id));
		var dragbar_height = parseInt(pldv_getOffsetHeight(pldv_dragbar_div_id));
		if (docwidth < (new_width + parseInt(pldv_getOffsetX(pldv_id)) - offsetx ))
		{	
			// first, move to flush left, then check again.
			pldv_div.style.left = (0 + offsetx) + "px";
			if (docwidth < (new_width + offsetx))
			{
				new_width = docwidth-2;
			}
		}
		if (docheight < (new_height + parseInt(pldv_getOffsetY(pldv_id)) - offsety ))
		{
			// set y coord to 0
			pldv_div.style.top = (0 + offsety) + "px";
			if (docheight < (new_height + offsety))
			{
				new_height = docheight - (meta_height + dragbar_height)-2;
			}
		}
		flpl_resize(new_width, new_height, mymode);
	}	
}

/**
 * pldv_set_div_size is function used to set the pldv_player_div and pldv_div width and height.
 * It can be called when the Flash player is loading a new skin, or when the player div is
 * being resized.
 *
 * @param {int} new_width This is the desired new width of the player div.
 * @param {int} new_height This is the desired new height of the player div.
 */
function pldv_set_div_size(new_width, new_height)
{
	// Resizes pldv_div (width only since height will stretch) and pldv_player_div.
	if (!new_width)
	{
		new_width = parseInt(pldv_player_div.style.width);
	}
	if (!new_height)
	{
		new_height = parseInt(pldv_player_div.style.height);
	}
	if ((pldv_player_div)&&(new_width > 20)&&(new_height > 20))
	{
		var old_width = pldv_player_div.style.width;
		pldv_player_div.style.width = new_width + "px";
		
		// check to make sure the window isn't shrinking further than the largest item in the div....
		var meta_width = parseInt(pldv_getOffsetWidth(pldv_meta_div_id));
		var dragbar_width = parseInt(pldv_getOffsetWidth(pldv_dragbar_div_id));
		var actual_width = parseInt(pldv_getOffsetWidth(pldv_player_div_id));
		
		if ((meta_width > actual_width))// && (dragbar_width > actual_width))
		{	
			if (parseInt(old_width) >= meta_width)
			{
				pldv_player_div.style.width = old_width;
			}
			else
			{
				pldv_player_div.style.width  = (meta_width + 10) + "px";
			}
			pldv_div.style.width = pldv_getOffsetWidth(pldv_player_div_id)+"px";
			
			// Now, if the new width is SIGNIFICANTLY smaller than the meta width, stop the mousedrag event, to prevent
			// weird video artifacts.
			if ((meta_width - actual_width) > 15)
			{
				document.onmouseup();
			}
		}
		else
		{
			pldv_div.style.width = pldv_getOffsetWidth(pldv_player_div_id)+"px";
		}
		// Because the metadata height may change, we have to check height as well.
		var meta_height = parseInt(pldv_getOffsetHeight(pldv_meta_div_id));
		var dragbar_height = parseInt(pldv_getOffsetHeight(pldv_dragbar_div_id));
			
		pldv_player_div.style.height = new_height + "px";
		flpl_width = new_width;
		flpl_height = new_height;
	}
}


////////////// Helpers - these determine various size/position information for <div>s that might not have a styled size/position.

/**
 * pldv_getOffsetHeight is function used to determine the actual height of a div
 * that may not have a style.height property.
 *
 * @param {String} id This is the id of the div whose height needs to be determined.
 * @return int The height in pixels of the div.
 */
function pldv_getOffsetHeight(id)
{
	// Returns actual height of elements that may not have a style.height property.
	var h = 0;
	var o;
	var d = document.getElementById(id);
	if('number' == typeof d.offsetHeight) 
	{
		h = d.offsetHeight;
	}
	else if ((o = document.defaultView) && o.getComputedStyle) 
	{
		h = o.getComputedStyle(d, null).height;
	}
	return h;
}

/**
 * pldv_getOffsetWidth is function used to determine the actual width of a div
 * that may not have a style.width property.
 *
 * @param {String} id This is the id of the div whose width needs to be determined.
 * @return int The width in pixels of the div.
 */
function pldv_getOffsetWidth(id)
{
	// Returns actual width of elements that may not have a style.width property.
	var w = 0;
	var o;
	var d = document.getElementById(id);
	if ('number' == typeof d.offsetWidth)
	{
		w = d.offsetWidth;
	}
	else if ((o = document.defaultView) && o.getComputedStyle)
	{
		w = o.getComputedStyle(d, null).width;
	}
	return w;
}

/**
 * pldv_getOffsetX is function used to determine the x position of a div
 * that may not have a style.left property.  Position is from left of browser.
 *
 * @param {String} id This is the id of the div whose x position needs to be determined.
 * @return int The position in pixels of the div, from the left side of the document window.
 */
function pldv_getOffsetX(id)
{
	// Returns X position of elements that may not have a style.left property.
	// Relative to browser window.
	var obj = document.getElementById(id);
	var curleft = 0;
	var parent_el=obj.offsetParent; 
	curleft = obj.offsetLeft;
	while (parent_el!=null)
	{ 
		curleft+=parent_el.offsetLeft; 
		parent_el=parent_el.offsetParent; 
	} 
	return curleft;
}

/**
 * pldv_getOffsetY is function used to determine the y position of a div
 * that may not have a style.top property.  Position is from top of browser.
 *
 * @param {String} id This is the id of the div whose y position needs to be determined.
 * @return int The position in pixels of the div, from the top of the document window.
 */
function pldv_getOffsetY(id)
{
	// Returns Y position of elements that may not have a style.top property.
	// Relative to browser window.
	var obj = document.getElementById(id);
	var curtop = 0;
	var parent_el=obj.offsetParent; 
	curtop = obj.offsetTop;
	while (parent_el!=null)
	{ 
		curtop+=parent_el.offsetTop; 
		parent_el=parent_el.offsetParent; 
	} 
	return curtop;
}

/**
 * pldv_getDocumentDims is function used to determine the width and height of the document
 * visible within the browser window, minus the width and height of any visible scrollbars.
 *
 * @return object The width and height of the client window.  Access via object.width and object.height.
 */
function pldv_getDocumentDims()
{
	// Determines the dimensions inside the browser window document area (user viewable), minus scrollbar width/height if present.
	var docwidth, docheight;
	var tempVersion = navigator.appVersion.toLowerCase();
	tempVersion = tempVersion.split("msie");
	tempVersion = tempVersion[1];
	var ieVersion = isIE ? parseInt(tempVersion) : null;
	var vert_scroll = 0;
	var horiz_scroll = 0;
	if (isIE)
	{
		docwidth = pldv_use_doc_el ? document.documentElement.clientWidth : document.body.offsetWidth;
		docheight = pldv_use_doc_el ? document.documentElement.clientHeight : document.body.offsetHeight;
	} 
	else 
	{
		docwidth = window.innerWidth;
		docheight = window.innerHeight;
	}
	 	
	// Check to see if scrollbars are present.  IE7's docwidth & height already take into account scroll widths,
	// but in FF, we need to subtract the width and height of the scrollbars appropriately.
	if (!isIE)
	{
		vert_scroll =  (document.body.scrollHeight - docheight > 0) ? 18 : 0;
		horiz_scroll =  (document.body.scrollWidth - docwidth > 0) ? 16 : 0;
	}
	docwidth = docwidth - vert_scroll - 2;
	docheight = docheight - horiz_scroll - 2;
	return({width: docwidth, height: docheight});
}

/**
 * pldv_getWindowOffsetX is function used to determine the scrolled offset width of the browser window.
 *
 * @return int offsetx The scroll offset width.
 */
function pldv_getWindowOffsetX()
{
	if (isIE)
	{
		offsetx = pldv_use_doc_el ? document.documentElement.scrollLeft : document.body.scrollLeft;
	}
	else 
	{
		offsetx = pageXOffset;
	}
	return offsetx;
}

/**
 * pldv_getWindowOffsetY is function used to determine the scrolled offset height of the browser window.
 *
 * @return int offsety The scroll offset height.
 */
function pldv_getWindowOffsetY()
{
	if (isIE)
	{
		offsety =  pldv_use_doc_el ? document.documentElement.scrollTop : document.body.scrollTop;
	}
	else 
	{
		offsety = pageYOffset;
	}
	return offsety;
}


/**
 * pldv_check_offsetX is function used to determine if the given x position of the floating player div
 * is within the viewable scrolled area of the browser window, and if not, returns a new value.
 *
 * @param {int} x_pos - required, the x position of the pldv_div, relative to the very left of the document
 * @param {int} width - required, the width of the pldv_div
 * @param {int} replace_pos - optional, the new value to use if the given x is bad
 * @return int x_pos - the usable x position.
 */
function pldv_check_offsetX(x_pos, width, replace_pos)
{
	if (!replace_pos)
	{
		replace_pos = 0;
	}
	var offsetx = pldv_getWindowOffsetX();
	var dimensions = pldv_getDocumentDims();
	var docwidth = dimensions.width;

	if ((x_pos < offsetx)||((x_pos + width) > (offsetx + docwidth)))
	{
		// the old x location of the player div is outside of the scrolled viewable area of the browser, adjust.
		x_pos = replace_pos + offsetx;
						
		if ((x_pos + width + 15) > (offsetx + docwidth))
		{
			// Check to make sure the right edge of player is within the scrollable area after repositioning.
			x_pos = offsetx + docwidth - width - 20;
		}			
	}
	return x_pos;
}

/**
 * pldv_check_offsetY is function used to determine if the given y position of the floating player div
 * is within the viewable scrolled area of the browser window, and if not, returns a new value.
 *
 * @param {int} y_pos - required, the y position of the pldv_div, relative to the very top of the document
 * @param {int} height - required, the height of the pldv_div
 * @param {int} replace_pos - optional, the new value to use if the given y is bad
 * @return int y_pos - the usable y position.
 */
function pldv_check_offsetY(y_pos, height, replace_pos)
{
	if (!replace_pos)
	{
		replace_pos = 0;
	}
	var offsety = pldv_getWindowOffsetY();
	var dimensions = pldv_getDocumentDims();
	var docheight = dimensions.height;

	if ((y_pos < offsety)||((y_pos + height) > (offsety + docheight)))
	{
		// the old y location of the player div is outside of the scrolled viewable area of the browser, adjust.
		y_pos = replace_pos + offsety;
						
		if ((y_pos + height + 15) > (offsety + docheight))
		{
			// Check to make sure the bottom edge of player is within the scrollable area after repositioning.
			y_pos = offsety + docheight - height - 20;
		}
	}
	return (y_pos < 0) ? 0 : y_pos;
}

/**
 * pldv_hide_immediate is a function that can be called directly to make pldv_div invisible WITHOUT animation.
 * Can be used by functions that need to temporarily make the player invisible, like login functions.
 */
function pldv_hide_immediate()
{
	if (pldv_div && (!pldv_minimized || pldv_animating)) // && (parseInt(pldv_div.style.left) > 0))
	{
		pldv_hide_immediate_override = true;
		if (parseInt(pldv_div.style.left) > 0)
		{
			pldv_slidehome_pos_x = pldv_div.style.left;
		}

		// set pldv_sh_offset.  These values will be used to reset the pldv_div position on restore, if user scrolls the browser window.
		pldv_sh_offset_x = parseInt(pldv_div.style.left) + pldv_getWindowOffsetX();
		pldv_sh_offset_y = parseInt(pldv_div.style.top) + pldv_getWindowOffsetY();

		if (pldv_status == 2)
		{
			// If flash player loaded...
			// cease playback, since the player will be hidden.
			flpl_object.pbk_pause();
		}
		pldv_div.style.left = "-3000px";
		pldv_minimized = true;
	}
}

/**
 * pldv_show_immediate is a function that can be called directly to make pldv_div visible WITHOUT animation.
 * Should ONLY be used to make the div visible again after calling pldv_hide_immediate. 
 */
function pldv_show_immediate()
{
	if (pldv_div && pldv_minimized)
	{
		pldv_hide_immediate_override = false;
		endX = parseInt(pldv_slidehome_pos_x);
		endY = parseInt(pldv_getOffsetY(pldv_id));
		endWidth = parseInt(pldv_getOffsetWidth(pldv_id));
		endHeight = parseInt(pldv_getOffsetHeight(pldv_id));

		endX = pldv_check_offsetX(endX, endWidth, pldv_sh_offset_x);

		if ((endX != parseInt(pldv_slidehome_pos_x)) && (parseInt(endX) != -3000))
		{
			pldv_slidehome_pos_x = endX + "px";
		}

		endY = pldv_check_offsetY(endY, endHeight, pldv_sh_offset_y);
		pldv_div.style.top = endY + "px";
		pldv_div.style.left = pldv_slidehome_pos_x;
		// If the flpl_object exists, tell it to activate its return-from-minimization code.
		if (flpl_object)                       
		{       
			flpl_object.unmini();                        
		}
		pldv_minimized = false;
		if (flpl_viewmode == "minimize")              
		{
			flpl_viewmode = "normal";   
		}
	}
} 


/**
 * Play a video from a URL
 * @param {String} vidurl}
 * @return bool
 */
function pldv_playurl(vidurl)
{
	vpjs_logging_api(vidurl, flpl_username, 'flashstandalonevideo');

	flpl_standalone_vid_url = vidurl;
	
	flpl_standalone_duration = null;

	pldv_show("flpl");
	return false;
}

/**
 * Simply hit our logging URL when playing popup videos.
 * @param {int} vid
 * @param {String} username
 * @param {String} message
 */
function vpjs_logging_api(vid, username, message)
{
	$.get(flpl_video_api_url, {
		op: "log",
		vid: vid,
		username: username,
		message: message
	});
}
