//jQuery SWFObject v1.1.1 MIT/GPL @jon_neal
//http://jquery.thewikies.com/swfobject
(function(f,h,i){function k(a,c){var b=(a[0]||0)-(c[0]||0);return b>0||!b&&a.length>0&&k(a.slice(1),c.slice(1))}function l(a){if(typeof a!=g)return a;var c=[],b="";for(var d in a){b=typeof a[d]==g?l(a[d]):[d,m?encodeURI(a[d]):a[d]].join("=");c.push(b)}return c.join("&")}function n(a){var c=[];for(var b in a)a[b]&&c.push([b,'="',a[b],'"'].join(""));return c.join(" ")}function o(a){var c=[];for(var b in a)c.push(['<param name="',b,'" value="',l(a[b]),'" />'].join(""));return c.join("")}var g="object",m=true;try{var j=i.description||function(){return(new i("ShockwaveFlash.ShockwaveFlash")).GetVariable("$version")}()}catch(p){j="Unavailable"}var e=j.match(/\d+/g)||[0];f[h]={available:e[0]>0,activeX:i&&!i.name,version:{original:j,array:e,string:e.join("."),major:parseInt(e[0],10)||0,minor:parseInt(e[1],10)||0,release:parseInt(e[2],10)||0},hasVersion:function(a){a=/string|number/.test(typeof a)?a.toString().split("."):/object/.test(typeof a)?[a.major,a.minor]:a||[0,0];return k(e,a)},encodeParams:true,expressInstall:"expressInstall.swf",expressInstallIsActive:false,create:function(a){if(!a.swf||this.expressInstallIsActive||!this.available&&!a.hasVersionFail)return false;if(!this.hasVersion(a.hasVersion||1)){this.expressInstallIsActive=true;if(typeof a.hasVersionFail=="function")if(!a.hasVersionFail.apply(a))return false;a={swf:a.expressInstall||this.expressInstall,height:137,width:214,flashvars:{MMredirectURL:location.href,MMplayerType:this.activeX?"ActiveX":"PlugIn",MMdoctitle:document.title.slice(0,47)+" - Flash Player Installation"}}}attrs={data:a.swf,type:"application/x-shockwave-flash",id:a.id||"flash_"+Math.floor(Math.random()*999999999),width:a.width||320,height:a.height||180,style:a.style||""};m=typeof a.useEncode!=="undefined"?a.useEncode:this.encodeParams;a.movie=a.swf;a.wmode=a.wmode||"opaque";delete a.fallback;delete a.hasVersion;delete a.hasVersionFail;delete a.height;delete a.id;delete a.swf;delete a.useEncode;delete a.width;var c=document.createElement("div");c.innerHTML=["<object ",n(attrs),">",o(a),"</object>"].join("");return c.firstChild}};f.fn[h]=function(a){var c=this.find(g).andSelf().filter(g);/string|object/.test(typeof a)&&this.each(function(){var b=f(this),d;a=typeof a==g?a:{swf:a};a.fallback=this;if(d=f[h].create(a)){b.children().remove();b.html(d)}});typeof a=="function"&&c.each(function(){var b=this;b.jsInteractionTimeoutMs=b.jsInteractionTimeoutMs||0;if(b.jsInteractionTimeoutMs<660)b.clientWidth||b.clientHeight?a.call(b):setTimeout(function(){f(b)[h](a)},b.jsInteractionTimeoutMs+66)});return c}})(jQuery,"flash",navigator.plugins["Shockwave Flash"]||window.ActiveXObject);

jQuery.fn.center = function () {
    $(this).css("position","absolute");
    $(this).css("top", ( $(window).height() - $(this).height() ) / 2+$(window).scrollTop() + "px");
    $(this).css("left", ( $(window).width() - $(this).width() ) / 2+$(window).scrollLeft() + "px");
    return $(this);
};

var videos = new Array();
videos["moa"]  = "http://global3digital.dl.groovygecko.com/gelclair/GelclairMOA.flv";
videos["moahcp"]  = "http://global3digital.dl.groovygecko.com/gelclair/GelclairMOA.flv";
videos["peters"] = "http://global3digital.dl.groovygecko.com/gelclair/PetersStory.flv";
videos["petershcp"] = "http://global3digital.dl.groovygecko.com/gelclair/PetersStoryHCP.flv";
videos["jacquelines"] = "http://global3digital.dl.groovygecko.com/gelclair/JacquelinesStory.flv";
videos["jacquelineshcp"] = "http://global3digital.dl.groovygecko.com/gelclair/JacquelinesStoryHCP.flv";
///gelclair/templates_gelclair/assets/flvs/JacquelinesStoryHCP.flv

function showVideo(video){
	//hack: show alternative video when in 'blue' mode
	if($('#player_div').hasClass("blue")) {
		video = video + "hcp";
	}
	
	var player = $('#player_div').video_player();
	if ( video in videos ){
		//first try to use the array of defined values.
		player.setVideoUrl(videos[video]);
	} else if ( typeof(video)=='string' ){
		//otherwise, try to load it as a url.
		player.setVideoUrl(video);
	} else {
		//video not found.
		return false;
	}
	player.showPlayer();
	player.bind( 'close', function() {} );
}

(function($){
	$.fn.video_player = function (options) {
		
				
		//fixed - we're pushing a whole div into the page, this will be where the actual flash lives
		var swfArea = '.player_flash_area';
		var html = '<div class="player_window"><a href="javascript: void(0)" class="close_btn">close</a><div class="player_flash_area"></div></div>';
		
		//fixed - dimensions.
		var width = 512;
		var height = 317;
		
		//fixed - url of the player.
		var videoSwfUrl = '/gelclair/templates_gelclair/assets/Player.swf';
		
		this.showPlayer = function () {
			$('#player_overlay').height($('body').height()).css('visibility', 'visible');
			$(this).html(html)
			.find(swfArea).flash(
				{
					swf: videoSwfUrl,
					width: width,
					height: height,
					allowfullscreen: true,
					stretching: "none",
					allowscriptaccess: "always",
					flashvars: {
						media: videoUrl
					}
				}
			);
			$(this).center();
			var that = this;
			$(this).find(".close_btn").click ( function () {
				that.removePlayer();
			});
			return this;
		};
		
		this.removePlayer = function () {
			$('#player_overlay').css('visibility', 'hidden');
			$(this).empty();
			$(this).trigger('close');
		};
		
		this.setCloseFn = function ( closeFunction ){
			closeFn = closeFunction;
		};
		
		this.setVideoUrl = function ( url ) {
			videoUrl = url;
			return this;
		};
		
		this.getVideoUrl = function () {
			return videoUrl;
		};
		
		return this;
	};
}
)(jQuery);


