// JavaScript Document

var tpFlash = {
	movieIndex : 1, // automatically incrementing index for movies rendered without id
	flashplayerURL : 'http://www.turningpoint.fi/common_swf/jwplayer.swf',
	
	getFlashVersionString : function() { 
	  // ie 
	  try { 
		try { 
		  // avoid fp6 minor version lookup issues 
		  // see: http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/ 
		  var axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6'); 
		  try { axo.AllowScriptAccess = 'always'; } 
		  catch(e) { return '6,0,0'; } 
		} catch(e) {} 
		return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1]; 
	  // other browsers 
	  } catch(e) { 
		try { 
		  if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){ 
			return (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1]; 
		  } 
		} catch(e) {} 
	  } 
	  return '0,0,0'; 
	},
	
	getFlashVersion : function () {
		numbers = this.getFlashVersionString().split(',');
		return { major : numbers[0], minor : numbers[1], revision : numbers[2] }
	},
	
	isNewerThan : function(major,minor,revision) {
		if(!(typeof major == "number" && typeof minor == "number" && typeof revision == "number")) return false;
		version = this.getFlashVersion();
		if(version.major < major) return false;
		if(version.major > major) return true;
		if(version.minor < minor) return false;
		if(version.minor > minor) return true;
		if(version.revision < revision) return false;
		return true;
	},
	
	render : function(targetEl, parms) {
		if(typeof jQuery == "undefined") throw('tpFlash error: jQuery not loaded');
		if(typeof parms.swf == "undefined") throw('tpFlash error: missing swf filename');
		swf = parms.swf;
		width = (typeof parms.width != "undefined" ? parms.width : 100);
		height = (typeof parms.height != "undefined" ? parms.height : 100);
		allowFullScreen = (typeof parms.allowFullScreen != "undefined" ? parms.allowFullScreen : 'false');		
		loop = (typeof parms.loop != "undefined" ? parms.loop : 'true');
		id = (typeof parms.id != "undefined" ? parms.id : "movie_"+(this.movieIndex++));
		flashvars = (typeof parms.flashvars != "undefined" ? parms.flashvars : null);
		
		if($.browser.msie) { 
			flashHTML 	= '<object id="'+ id +'" type="application/x-shockwave-flash" width="'+ width +'" height="'+ height +'">'
  						+ '<param name="movie" value="'+ swf +'">'
  						+ '<param name="loop" value="'+ loop +'">'
  						+ '<param name="allowFullScreen" value="'+ allowFullScreen +'">'						
						+ (flashvars ? '<param name="flashvars" value="'+ flashvars +'">' : '') +
						+ '</object>';
		}
			
		else {
			flashHTML	= '<embed name="'+ id +'" id="'+ id +'" loop="'+ loop +'" type="application/x-shockwave-flash" '
       					+ 'allowFullScreen="'+ allowFullScreen +'" src="'+ swf +'" width="'+ width +'" height="'+ height +'"' 
						+ (flashvars ? ' flashvars="'+ flashvars +'"' : '') + '></embed>';
		}
		
		$(targetEl).html(flashHTML);
		
		
	},
	
	renderFlashMovies : function() {
		$('.tp_flashvideo').each(function() {
			parms = this.title.split(';');	
			if(typeof parms[0] == 'undefined' || typeof parms[1] == 'undefined') return false; 
			dimensions = parms[0].split('x');
			swfFile = parms[1];
			previewFile = (typeof parms[2] != 'undefined' ? parms[2] : null);
			
			if(typeof dimensions[0] == 'undefined' || typeof dimensions[1] == 'undefined') return false; 
			swfWidth = dimensions[0]; swfHeight = dimensions[1];
			if(tpFlash.isNewerThan(9,0,115)) tpFlash.render(this, { 
				swf : tpFlash.flashplayerURL,
				width : swfWidth,
				height : swfHeight,
				allowFullScreen : 'true',
				flashvars : 'file=' + swfFile + (previewFile ? '&image=' + previewFile : '') 
				});
			$(this).attr('title','');
		});
										  
		
	}
	
}


