$(document).ready()
{
//Launch Video
	
	$('.launch_video').click(function()
	{
		// Google Analytics Event Tracking for Video
        _gaq.push(['_trackEvent', 'Videos', 'Play', 'About Credit Sesame']);

        // This might be a workaround for iPhones
		/*if (navigator.mimeTypes ["application/x-shockwave-flash"]==undefined){
			window.open('http://www.youtube.com/v/sjrAIU7RCLE');
			return false;
		}*/
		
		$('<div id="video_overlay"><iframe title="About Credit Sesame" class="youtube-player" type="text/html" width="844" height="500" src="http://www.youtube.com/v/sjrAIU7RCLE?rel=0&amp;hd=1;autoplay=1" frameborder="0" style="display:block; margin-bottom:15px"></iframe></div>').appendTo('body').append('<div class="close"></div>').append('<a href="https://secure.creditsesame.com/signup1#ad=video-pop-get-startd"><img src="http://csesamewww.s3.amazonaws.com/landing/button-get-started-free.png" /></a>').fadeIn('fast');

		//Append the page transparent overlay
		$('body').append('<div id="page_overlay"></div>');
		var vph = $(window).height() / 2;
		var vpw = $(window).width() / 2;
		var vbh = $('#video_overlay').height() /2;
		var vbw = $('#video_overlay').width() /2;
		var hoffsetval = vph - vbh - 15 + 'px';
		var woffsetval = vpw - vbw - 15 + 'px';
		$('#video_overlay').css({'top' : hoffsetval, 'left' : woffsetval, 'visibility': 'visible'});
		return false
	});
	
	
	
//Close Video
	$('#video_overlay .close').live('click', function(){
		$(this).parent().fadeOut('fast', function(){
			$('#video_overlay').remove();
		});
		$('#page_overlay').fadeOut('fast', function(){
			$(this).remove();
		});		
	})
	
	$(document).click(function(){
	    if($('#video_overlay').is(':visible')){
	    	$('#video_overlay').fadeOut('fast', function(){
	    		$('#video_overlay').remove();
	    	});
			$('#page_overlay').fadeOut('fast', function(){
				$(this).remove();
			});		
	    }
	})
};
