﻿// use noConflict so there are no conficts with other libraries
$( function() {
	var bodyFlash = $('<div id="modalCover"></div><div id="bodyFlashOuter"><span id="flashVideo"></span></div>')
		.hide()
		.eq(0)
		.css({ position: "absolute", top: "0", left: "0", background: "#000000", opacity: 0.75 })
		.click(closeFlash)
		.end()
		.eq(1)
		.css({ position: "absolute", top: "-357px", left: "50%", "margin-left": "-355px", width: 710 })
		.end()
		.appendTo("body");
});

// Starts the flash video
function openFlash() {
	if (closeFlash.moving) return;
	openFlash.moving = true;
	swfobject.embedSWF("/AtcomCMSLImages/TAF_videoPlayer.swf", "flashVideo", "710", "357", "8", "", {}, { wmode: "transparent" }, {});
	$("#modalCover").fadeIn("500", slideFlash);
	setCoverSize();
	$(window).bind("resize", setCoverSize);
	if ($.browser.msie && parseFloat($.browser.version) <= 6)
		$("select").css("visibility", "hidden");

	function slideFlash() {
		$("#bodyFlashOuter")
			.show()
			.animate({ top: "79px" }, 1000, "easeOutBounce", function() { openFlash.moving = false; })
			.find(":first")
			.css("outline", "0");
	}
}

function closeFlash() {
	if (openFlash.moving) return;
	closeFlash.moving = true;
	$("#modalCover").fadeOut("500", function() {
		if ($.browser.msie && parseFloat($.browser.version) <= 6)
			$("select").css("visibility", "visible");
		closeFlash.moving = false;
	});
	$("#bodyFlashOuter").animate({ top: "-357px" }, 1000, function() {
		$(this).html('<span id="flashVideo"></span>');
	});
	$(window).unbind("resize" , setCoverSize);
}

function setCoverSize() {
	var sw = document.body.scrollWidth;
	var ww = $(window).width();
	var sh = document.body.scrollHeight;
	var wh = $(window).height();
	$("#modalCover").height( sh > wh ? sh : wh ).width( sw > ww ? sw : ww );
}

/*
	* jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing
	*
	* Uses the built In easIng capabilities added In jQuery 1.1
	* to offer multiple easIng options
	*
	* Copyright (c) 2008 George McGinley Smith
	* Licensed under the MIT License:
	* http://www.opensource.org/licenses/mit-license.php
*/

/* JM : removed all but the easeOutBounce method to minimise the size of the file */
// t: current time, b: begInnIng value, c: change In value, d: duration

jQuery.extend(jQuery.easing,
{
	easeOutBounce: function(x, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	}
});