/* inline Flash support */

/* example tagsets from http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=tn_4150
    and http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=tn_12701
*/

/*

=pod

=head1 NAME

flv.js - Flash javascript library

=head1 SYNOPSIS

 var movie_cc = 1;
 var flash = new Flash.movie({div_id:'movie'});
 flash.insert(movie_cc);
 
=head1 DESCRIPTION

Prototype-based html generation for Flash movies. Requires Prototype js library >= 1.4.

=head1 METHODS

=cut

*/

var Flash = {
  Version: '1.0.0',
  prototypeVersion: parseFloat(Prototype.Version.split(".")[0] + "." + Prototype.Version.split(".")[1])
}

if((typeof Prototype=='undefined') || Flash.prototypeVersion < 1.4)
      throw("Flash JS requires the Prototype JavaScript framework >= 1.4");

Flash.movie = Class.create();

Flash.movie.prototype = {

/*

=head2 new( I<params> )

Instantiate new object. I<params> should be JSON hash structure. Following key/values
are supported:

=over

=item player

URL for the SWF player.

=item cc_player

URL for the closed captioning SWF player.

=item stream_url

URL for the .flv file to be played.

=item cc_url

URL for the closed captioning text.

=item div_id

ID attribute value for the <div> to be insert()ed into.

=item width

Width of the movie.

=item height

Height of the movie.

=item displayheight

Display height of the movie.

=item type

Type of the movie, e.g. 'flv' or 'mp3'.
Defaults to 'flv'.

=item debug

Dev only. Set to the ID attribute value of the div where you want
the insert() text to be inserted. The text will be HTML-escaped.

=back

=cut

*/

    initialize: function(params)
    {
        this.player     = params.player     || 'http://static.atomiclearning.com/flashplayer/player.swf';
        this.cc_player  = params.cc_player  || 'http://static.atomiclearning.com/flashplayer/cc_player.swf';
        this.stream_url = params.stream_url || 'http://stream.atomiclearning.com';
        this.cc_url     = params.cc_url     || 'http://movies.atomiclearning.com/caption';
        this.shared_stream_url = params.shared_stream_url || 'http://stream.atomiclearning.com';
        this.shared_cc_url     = params.shared_cc_url     || 'http://movies.atomiclearning.com/caption';
        this.div_id     = params.div_id     || 'movie';
        this.width      = params.width      || '538';
        this.height     = params.height     || '565';
        this.debug      = params.debug      || 0;
        this.type       = params.type       || 'flv';
        this.displayheight = params.displayheight ? params.displayheight : 0;
    },
    
/*

=head2 insert( I<has_cc> )

Creates and inserts the HTML to play a .flv movie. If I<has_cc>
is true, the generated HTML will have correct attributes to invoke closed
captioning.

=cut
*/
    insert: function(has_cc)
    {
        var buf = has_cc ? this.caption_tagset() : this.tagset();
        $(this.div_id).innerHTML = buf;
        if (this.debug)
        {
            //alert(buf);
            $(this.debug).innerHTML = buf.escapeHTML();
        }
    },

/*

=head2 tagset

Returns HTML tagset for cross-browser compatability.

=cut
*/
    tagset: function (no_autostart, use_shared)
    {
        return this.generic_tagset(no_autostart, false, use_shared);
    },

/*

=head2 caption_tagset

Returns closed captioning HTML tagset for cross-browser compatability.

=cut
*/
    caption_tagset: function (no_autostart, use_shared)
    {
        return this.generic_tagset(no_autostart, true, use_shared);
    },
  
/*

=head2 generic_tagset

Returns HTML tagset for cross-browser compatability.

=cut
*/
    generic_tagset: function (no_autostart, use_captions, use_shared)
    {
	var stream_url;
	var cc_url;
	if (use_shared) {
		stream_url = this.shared_stream_url;
		cc_url     = this.shared_cc_url;
	}
	else {
		stream_url = this.stream_url;
		cc_url     = this.cc_url;
	}

	if (this.type == 'swf') {
	return '' +
	'<object width="' + this.width + '" height="' + this.height + '"' +
	' classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"' +
	' codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0">\n' +
	'  <param name="movie" value="' + stream_url + '" />\n' +
	'  <param name="wmode" value="transparent" />\n' +
	'  <param name="quality" value="autohigh" />\n' +
	'  <param name="bgcolor" value="#000000" />\n' +
	'  <embed type="application/x-shockwave-flash"' +
	' width="' + this.width + '" height="' + this.height + '"' +
	' src="' + stream_url + '"' +
	' bgcolor="#000000" wmode="transparent" quality="autohigh"' +
	' pluginspage="http://www.macromedia.com/go/getflashplayer"' +
	' />\n' +
	'</object>';
	}

	var player = use_captions ? this.cc_player : this.player;

	var flashvars = new Array();
	var i = 0;
	flashvars[i++] = 'type=' + this.type;
	if (use_captions && this.displayheight) {
		flashvars[i++] = 'displayheight=' + this.displayheight;
	}
	flashvars[i++] = 'file=' + escape(stream_url);
	if (use_captions) {
		flashvars[i++] = 'captions=' + escape(cc_url);
	}
	else {
		flashvars[i++] = 'overstretch=true';
	}
	if (this.type == 'mp3') {
		flashvars[i++] = 'showeq=true';
	}
	if (!no_autostart) {
		flashvars[i++] = 'autostart=true';
	}
	flashvars[i++] = 'showfsbutton=false';
	flashvars[i++] = 'allowfullscreen=false';
	flashvars[i++] = 'usefullscreen=false';

	var flashvars_val = flashvars.join('&');

	return '' +
	'<object width="' + this.width + '" height="' + this.height + '"' +
	' classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"' +
	' codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0">\n' +
	'  <param name="movie" value="' + player + '" />\n' +
	'  <param name="wmode" value="transparent" />\n' +
	'  <param name="quality" value="autohigh" />\n' +
	'  <param name="bgcolor" value="#000000" />\n' +
	'  <param name="flashvars" value="' + flashvars_val + '" />\n' +
	'  <embed type="application/x-shockwave-flash"' +
	' width="' + this.width + '" height="' + this.height + '"' +
	' src="' + player + '"' +
	' bgcolor="#000000" wmode="transparent" quality="autohigh"' +
	' pluginspage="http://www.macromedia.com/go/getflashplayer"' +
	' flashvars="' + flashvars_val + '" />\n' +
	'</object>';
    }

};

/*

=head1 SEE ALSO

http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=tn_12701

=head1 COPYRIGHT

Copyright 2007 by Atomic Learning Inc. All Rights Reserved.

=cut
*/
