/*
        Flash Player detection and embedding

        copyright 2010 Artgig Studio - all rights reserved.
        http://www.artgig.com

        v1.2: 2011-1-16
*/


var fV = 0;

FlashEmbed = function( _f, _v, _w, _h, _bg, _id, _c ) {
	this.f = _f;
	this.v = _v;
	this.id = _id;
	this.c = _c;
	this.w = _w;
	this.h = _h;
	this.p = { quality:'high', allowscriptaccess:'sameDomain' };
	if ( _bg ) this.setParam( 'bgcolor', _bg );

};

FlashEmbed.rawVersion = '';
FlashEmbed.majorVersion = 0;
FlashEmbed.h264 = false;
FlashEmbed.mobile = false;
FlashEmbed.ios = false;

FlashEmbed.newVideo = function( f ) {
};

FlashEmbed.prototype = {
	create:function( _id ) {
		if ( document.getElementById && fV >= this.v ) {
			var obj = document.getElementById( _id )
			if ( obj ) {
				obj.innerHTML = this.getHtml();
			}
		}
	},
	getHtml:function() {
		var html = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ';
		html += 'codebase="http';
		if ( document.location.protocol == "https:" ) html += 's';
		html += '://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + this.v + ',0,0,0"';
		if ( this.w ) html += ' width="' + this.w + '"';
		if ( this.h ) html += ' height="' + this.h + '"';
		if ( this.id ) html += ' id="' + this.id + '"';
		if ( this.c ) html += ' class="' + this.c + '"';
		html += '>';
		html += '<param name="movie" value="' + this.f + '" />';
		for ( var pn in this.p ) html += '<param name="' + pn + '" value="' + this.p[pn] + '" />';
		html += '<embed src="' + this.f + '" swLiveConnect="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"';
		if ( this.w ) html += ' width="' + this.w + '"';
		if ( this.h ) html += ' height="' + this.h + '"';
		if ( this.id ) html += ' name="' + this.id + '"';
		if ( this.c ) html += ' class="' + this.c + '"';
		for ( var pn in this.p ) html += ' ' + pn + '="' + this.p[pn] + '"';
		html += ' />';
		html += '</object>';
		return html;
	},
	writeHtml:function() {
		document.writeln( this.getHtml() );
	},
	setParam:function( _p, _v ) { this.p[_p.toLowerCase()] = _v; }
};



FlashEmbed.getFlashPlayerVersion = function() {
	if ( fV == 0 ) {
		if ( navigator.plugins && navigator.mimeTypes.length ) {
			var x = navigator.plugins["Shockwave Flash"];
			if ( x && x.description ) {
				FlashEmbed.rawVersion = x.description;
				var vstr = x.description.replace(/([a-z]|[A-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split(".");
				FlashEmbed.majorVersion = fV = parseInt( vstr[0] );
				FlashEmbed.h264 = (fV > 9) || (fV == 9 && parseInt(vstr[2]) >= 115);
			}
		}
		else if ( window.ActiveXObject ) {
			var axo = new ActiveXObject( "ShockwaveFlash.ShockwaveFlash" );
			// this will throw an error for controls prior to Flash 4...
			/*@cc_on
   				/*@if (@_jscript_version < 5)
					// Older version of Windows IE do not support try/catch, so here's a poor-man's version:
					window.onerror = function () { return true; }
					FlashEmbed.rawVersion = axo.GetVariable("$version");
					var vstr = FlashEmbed.rawVersion.split(" ")[1].split(",");
					FlashEmbed.majorVersion = fV = parseInt( vstr[0] );
					FlashEmbed.h264 = (fV > 9) || (fV == 9 && parseInt(vstr[2]) >= 115);
				@else @*/
					try {
						FlashEmbed.rawVersion = axo.GetVariable("$version");
						var vstr = FlashEmbed.rawVersion.split(" ")[1].split(",");
						FlashEmbed.majorVersion = fV = parseInt( vstr[0] );
						FlashEmbed.h264 = (fV > 9) || (fV == 9 && parseInt(vstr[2]) >= 115);
					}
					catch (e) {
						// do nothing, leave as player version 0
					}
			   /*@end
			@*/
		}
	}

	var ua = navigator.userAgent;
	if ( ua.search(/sony|symbian|nokia|samsung|mobile|windows ce|epoc|opera mini|nitro|j2me|midp-|cldc-|netfront|mot|up\.browser|up\.link|audiovox/i) != -1
			|| ua.search(/blackberry|ericsson,|panasonic|philips|sanyo|sharp|sie-|portalmmm|blazer|avantgo|danger|palm|series60|palmsource|pocketpc/i) != -1
			|| ua.search(/smartphone|rover|ipaq|au-mic,|alcatel|ericy|vodafone\/|wap1\.|wap2\.|iPhone|iPad|android/i) != -1 )
		FlashEmbed.mobile = true;
	if ( ua.search(/iPhone|iPad/i) != -1 )
		FlashEmbed.ios = true;
	return fV;
}

FlashEmbed.saveLocation = function( loc ) {
	document.cookie = 'flembed_lastloc=' + encodeURIComponent(loc) + ';domain=.jfk50.org;PATH=/';
}

FlashEmbed.getLocation = function( clear ) {
	if ( document.cookie ) {
		var cookies = document.cookie.split( ';' );
	
		for( var i = 0; i < cookies.length; i = i + 1 ) {
			var parts = cookies[i].split( '=' );
			var name = parts.shift().replace( /^\s*/, '' ).replace( /\s*$/, '' );
			if ( name == 'flembed_lastloc' ) {
				var value;
				var rawValue = parts.join( '=' );
				try {
					value = decodeURIComponent( rawValue );
				}
				catch( e1 ) {
					value = rawValue;
				}
				if ( clear ) {
					FlashEmbed.clearLocation();
				}
				return value;
			}
		}
	}
	return '';
}

FlashEmbed.clearLocation = function() {
	document.cookie = 'flembed_lastloc=;domain=.jfk50.org;PATH=/';
}

FlashEmbed.getFlashPlayerVersion();

