
// MATTEL ONLINE
// Copyright 2006 Mattel, Inc. All Rights Reserved.
// This file is proprietary and confidential; unauthorized use or redistribution is prohibited.


/**
 * FlashMovie Class
 * @author Scott Jeppesen
 * @author Scott Delamater
 * @version 2.0
 *
 * Javascript class to write out FlashTags.  2.0 implementation includes:
 * 	-Flash Detection Kit implementation
 *	-Modified constructor allowing definition of src, width, and height properties on creation
 * This requires inclusion of the Flash Detection Kit scripts (main.js and config.js).
 */
// A static Boolean value obtained from the Flash Detection Kit indicating availability of the required version of Flash.

var flashDetected = readCookie("flashDetected");

if (flashDetected) {
     var hasRightVersion = true;
} else {
     var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
     createCookie("flashDetected", hasRightVersion, 1);
}

//var hasRightVersion = (readCookie("flashDetected")) ? true : DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
//var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
//var hasRightVersion = true;

// A static Boolean value indicating whether a write() attempt has been made
var hasWritten = false;

/**
* @class FlashMovie
*/
function FlashMovie ( s,w,h )
{	
	// <embed> and <object> tag properties
	this.src       = (s!=null) ? s : "";	// [String] path to the swf file
	this.width     = (w!=null) ? w : 550;	// [int] movie width
	this.height    = (h!=null) ? h : 400;	// [int] movie height
	this.flashVars = "";			// [String] name value pairs to pass into the movie on load
	this.align     = "";			// [String] movie alignment
	this.name      = "";			// [String] movie name/id
	this.bgColor   = "#FFFFFF";		// [String] movie background color
	this.quality   = "high";		// [String] movie quality
	this.menu   	= "false";		// [String] right-click menu visibility
	this.wmode 		= "window";		// [String] window mode
	this.salign 	= "";			// [String] screen alignment; valid values are "", "lt", "l", "lb", "t", "b", "rt", "r", and "rb"
	this.scale 		= "";			// [String] scale mode; valid values are "", "exactfit", "noborder", and "noscale"
}

/**
* Writes the object/embed tags, if the current version of Flash is available.  Otherwise writes alternate content.
*/
FlashMovie.prototype.write = function ()
{
	// Has required version of Flash
	if ( hasRightVersion )
	{
		document.write( this.getTags() );
	}
	// Has no flash
	else if ( !hasWritten )
	{
		window.location = noFlashURL;
	}
	
	hasWritten = true;
};

FlashMovie.prototype.getTags = function ()
{
	var oeTags = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '
		+ 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab" ' 
		+ 'width="' + this.width +'" '
		+ 'height="' + this.height + '" '
		+ 'id="' + this.name + '" '
		+ 'align="' + this.align + '" >'
		+ '<param name=movie value="' + this.src + '">'
		+ '<param name=quality value="' + this.quality + '">'
		+ '<param name=bgcolor value="' + this.bgColor + '">'
		+ '<param name=FlashVars value="' + this.flashVars + '">'
		+ '<param name=menu value="' + this.menu + '">'
		+ '<param name=wmode value="' + this.wmode + '">'
		+ '<param name=salign value="' + this.salign + '">'
		+ '<param name=scale value="' + this.scale + '">'
		+ '<param name=allowscriptaccess value="always">'
		+ '<embed src="' + this.src + '" '
		+ 'FlashVars="' + this.flashVars + '" '
		+ 'scale="' + this.scale +'" '
		+ 'wmode="' + this.wmode + '" '
		+ 'salign="' + this.salign + '" '
		+ 'quality="' + this.quality +'" '
		+ 'bgcolor="' + this.bgColor + '" '
		+ 'width="' + this.width + '" '
		+ 'height="' + this.height + '" '
		+ 'name="' + this.name + '" '
		+ 'align="' + this.align + '" '
		+ 'menu="' + this.menu + '" '
		+ 'allowscriptaccess="always" '
		+ 'type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
	return oeTags;
};


// cookie read/write script from quirksmode.org: 
// http://www.quirksmode.org/js/cookies.html

function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}