/**
 * 
 * Copyright (c) 2011 BPG Interactive
 * http://bpg.tv
 * 
 **/

(function($){
	$(document).ready(function() { 
		
		$('a.lightbox[rel]').overlay({ mask: '#000000', left: '50%', top: '50%' });
		
		
		// trailer (desktop only)
		$('a.sony-player').click(function(e) {
			e.preventDefault();
			window.displayShare = true;
			openOverlay();
		});
		
		
		 ///////////////////////////////////////////////////
		// Wallpaper screen size detection
		
		if( screen.width < 801 && screen.height < 801) {
			$('#downloads.lightbox em.wpS').css('display','inline-block');
		} else if (screen.width < 1025 && screen.height < 1025 ) {
			$('#downloads.lightbox em.wpM').css('display','inline-block');
		} else if (screen.width < 1281 && screen.height < 1281 ) {
			$('#downloads.lightbox em.wpL').css('display','inline-block');
		} else {
			$('#downloads.lightbox em.wpXL').css('display','inline-block');
		}
		
		
		 ///////////////////////////////////////////////////
		// intro animation
		
		function intro() {
			var header = $('header#title h1');
		
			setTimeout(function() { 
				header.fadeIn(6000, function(){
					$('a#url').fadeIn(3000);
				});
			}, 3000);
		}
		
		intro();
		
		// start animation if switched back to landscape mode
		// (if animation has already run this has no effect)
		window.onorientationchange = function() {
			if(window.orientation == 90 || window.orientation == -90)
				intro();
		}
		
		 ///////////////////////////////////////////////////
		// tracking
		
		if(window.sCode) {
			$('a.button-watch').add('a#watch').click(function() {
				window.sCode.trackVideo('meninblack3_trailer', 'start');
			});
		
			$('a.button-downloads').click(function() {
				window.sCode.trackPageView('downloads.php');
			});
		
			$('a#itunes').click(function() {
				window.sCode.trackOutboundClick($(this).attr('href'), 'itunes');
			});
		
			$('a#url').click(function() {
				window.sCode.trackOutboundClick($(this).attr('href'), 'secret_link');
			});
			
			// twitter
			if(window.twttr) {
				twttr.events.bind('tweet', function(event) {
				    window.sCode.trackOutboundClick('twitter.com', 'tweet');
				});
			}
		}
		
		
		
	});
})(jQuery);
