$(function() {
	$(document).ready(function(){
		if ($('#player').length > 0) {//make it safe to load this file on pages without a "player" element just in case
			var player = $f("player", {src: "/videos/flowplayer/flowplayer.commercial-3.1.5.swf", wmode: 'opaque'}, {
				key: '#$ccedd24f37577389508',
				plugins:  {
					controls: {
						tooltips: {
							buttons: true
						}
					}
				},
				clip: {
					autoBuffering: true,
					onStart: function(clip) {
						_gaq.push(['_trackEvent', 'Videos', 'Play', clip.url]);
					},
					onPause: function(clip) {
						console.log("pause");
						_gaq.push(['_trackEvent', 'Videos', 'Pause', clip.url, parseInt(this.getTime())]);
					},
					onStop: function(clip) {
						_gaq.push(['_trackEvent', 'Videos', 'Stop', clip.url, parseInt(this.getTime())]);
					},
					onFinish: function(clip) {
						_gaq.push(['_trackEvent', 'Videos', 'Finish', clip.url]);
					}
				}
			});

			// setup button action. it will fire our overlay
			$("img[rel]").overlay({
				effect: 'apple',
				expose: '#000000',
				onLoad: function() {
					player.load();
				},
				onClose: function() {
					player.unload();
				}
			});
		}
	});
});
