!function($)
{
	
	var positions = {landing:{has4:{men1:{out:[-20,5],over:[-56,-86]},women1:{out:[-10,4],over:[-54,-85]},men2:{out:[-18,-9],over:[-64,-125]},women2:{out:[-16,-2],over:[-21,-122]}},has3:{men1:{out:[-3,-10],over:[-46,-86]},women1:{out:[1,-12],over:[-54,-85]},women2:{out:[0,-21],over:[0,-112]}},has2:{men1:{out:[58,-10],over:[58,-86]},women1:{out:[68,-12],over:[48,-85]}}},arena:{has4:{men1:{out:[8,8],over:[8,-32]},women1:{out:[8,3],over:[-8,-32]},men2:{out:[10,-2],over:[10,-36]},women2:{out:[8,0],over:[8,-48]}},has3:{men1:{out:[6,-28],over:[-2,-84]},women1:{out:[5,-34],over:[-4,-88]},women2:{out:[12,-34],over:[26,-96]}},has2:{men1:{out:[72,-42],over:[72,-108]},women1:{out:[72,-46],over:[72,-108]}}}};
	$videobox =JQ('#videobox');
	$videobox.hide();
	$(function()
	{
		for (var page in positions)
			for (var num_touts in positions[page])
				for (var position in positions[page][num_touts])
					$('div.product-touts.' + page + '.' + num_touts)
						.find('li.' + position)
							.find('img.tout')
								.css({
									left: positions[page][num_touts][position].out[0],
									top: positions[page][num_touts][position].out[1]
								})
							.end()
							.find('img.tout-over')
								.css({
									left: positions[page][num_touts][position].over[0],
									top: positions[page][num_touts][position].over[1]
								});
		
		$('div.product-touts div.touts ul li a')
			.mouseover(function(e)
			{
				$(this)
					.parent()
						.find('img.tout')
							.hide()
						.end()
						.find('img.tout-over')
							.show();
			})
			.mouseout(function(e)
			{
				$(this)
					.parent()
						.find('img.tout-over')
							.hide()
						.end()
						.find('img.tout')
							.show();
			});
		
		
		
		
		
		$('div.video-thumbnail a[data-guid]')
			.click(function(e)
			{
				e.preventDefault();
				
				var guid = $(this).attr('data-guid');
				console.log(document.getElementById('get_flash'));
				if (document.getElementById('get_flash')) {
				console.log("document.getElementById(brightcove_container).innerHTML>"+document.getElementById('brightcove_container').innerHTML);
				
				VC.create_player({
					'videoId': guid,
					'@videoId': guid,
					'width': 910,
					'autoStart': true
				});
				}
				$('#overlay')
					.css({
						height: (document.body.clientHeight + 40) + 'px'
					})
					.show();
				
				$('html,body')
					.animate({
						scrollTop: 0
					});
				
				$(window).trigger('video_overlay_opened');
			});
		
		$('#overlay')
			.appendTo('body')
			.find('#overlay_close')
				.click(function(e)
				{
					e.preventDefault();
					
					VC.bc_video_stop();
					$('#overlay').hide();
					//document.getElementById('brightcove_container').innerHTML='';
				});
		
		$('div.product-touts div.touts ul li a.hit-area')
			.click(function(e)
			{
				e.preventDefault();
				
				var $t = $(this);
				
				var section = $t.parents('div').hasClass('run-free')? 'run_free' : 'train_free';
				var gender = $t.parents('li').attr('class').match(/men|women/)[0];
				
				tracking.track({
					pageName: 'free>tout>' + section + '>' + gender,
					prop17: 'Landing Page',
					prop18: 'free',
					prop19: 'free'
				});
				
				delayClick($t);
			});
	});
	
	
	
	window.delayClick = function($anchor)
	{
		setTimeout(function()
		{
			window.location = $anchor.attr('href');
		}, 150);
	};
	
	window.showVideo = function(vid,thumb)
	{
		console.log("showVideo "+vid );
			tracking.track({
					pageName: 'free>arena>view_video',
					prop18: 'free',
					prop19: 'free_arena'
				});
			$videobox =JQ('#videobox');
			$videobox.html('');
			$videobox.append('');
			if (JQ.browser.safari) {
		    	$videobox.append('<div id="vbox"><a id="overlay_close2" onClick="javascript: hideVideo();" href="#">Close Video</a><video class="video-js" width="500" height="300" controls preload autoplay poster="'+thumb+'"><source src="'+vid+'" type=\'video/mp4; codecs="avc1.42E01E, mp4a.40.2"\' /></video></div>');
		    } else {
		      	$videobox.append('<div id="vbox"><a id="overlay_close2" onClick="javascript: hideVideo();" href="#">Close Video</a><div class="flashvid"><object id="flash_fallback_1" class="vjs-flash-fallback" width="500" height="300" type="application/x-shockwave-flash" data="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf"><param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" /><param name="allowfullscreen" value="true" /><param name="flashvars" value=\'config={"playlist":["'+thumb+'", {"url": "'+vid+'","autoPlay":true,"autoBuffering":true}]}\' /><img src="'+thumb+'" width="640" height="264" alt="Poster Image" title="No video playback capabilities." /></object></div></div>');
		    }
		    $videobox.show();
		    FreeArena.swf().pauseVideo()
		    
	};
	
	window.hideVideo = function()
	{
			console.log("window.hideVideo " );
			
			$videobox =JQ('#videobox');
			$videobox.html('');
			$videobox.hide();
		    
	};
	
}(jQuery);
