//overlayPlayer config+
feedUrl = "http://www.sonypictures.com/previews/movies/residentevilretribution.xml";  //Enter vide XML here
autocloseToggle = true;
htmlVideoScreenshot = "#";
htmlVideoMP4Lo = "http://flash.sonypictures.com/video/intl/global/movies/residentevilretribution/ResidentEvil5_ITR-A_Eng_EAGL.mp4";
htmlVideoMP4Hi = "http://flash.sonypictures.com/video/intl/global/movies/residentevilretribution/ResidentEvil5_ITR-A_Eng_EAGL.mp4";

// share configuration
share.url = "ResidentEvil-Movie.com";
share.title = "Resident Evil Retribution";
share.description = "Watch the Trailer Now! #ResidentEvil http://www.ResidentEvil-Movie.com";
share.tweet = "Watch the Trailer Now! #ResidentEvil http://www.ResidentEvil-Movie.com";




var SplashUI = function() {
	
	// PRIVATE
	
	// any special styling that need to be done on load should be in this function
	function initStylesAndMethods() {	
		Cufon.replace('.cufon', { fontFamily: 'Trajan Pro'});
		
		if(typeof popUpsAndTrackingFunctions != 'function') {
			$('a[rel="external"]').bind('click', function() {
				window.open($(this).attr('href'), '_blank');
				return false;
			});
		}
	}
	
	// use it only if you want to animate things
	function animation() {
	}
	
	// opens full screen window for the immersive - only used when enter the site button is active
	function enterTheSite() {
		$('#title-treatment').bind('click', function() {
			var link = '#';  //enter href here for Enter the Site button; if exist.
			window.open(link, '');
			sCode.trackFeaturedContentClick(link, 'entersite_keyart');
			//window.open(link, '', 'fullscreen=yes, scrollbars=yes, resizable=no, status=no, directories=no, toolbar=no');
			/*if(typeof sCode == 'object') {
				if($(this).attr('id') == 'title-treatment') {
					sCode.trackFeaturedContentClick(link, 'entersite_button');
				}	else {
					sCode.trackFeaturedContentClick(link, 'entersite_keyart');
				}			
			}*/
			return false;
		});
	}
	
	// video that goes into enter the site button - only used when enter the site button is active
	function embedVideo($width, $height) {
		var flashvars = {};
		var params = {
			wmode: 'opaque',
			allowscriptaccess: true
		};	
		var attributes = {};
		swfobject.embedSWF('media/video.swf', 'enterthesite-video', $width, $height, '10', '', flashvars, params, attributes);
	}
	
	// plays videos with rel tag that starts with "playvideo". To play specific clip, add dash then number. Example: rel="playvideo-3144"
	function playVideos() {
		$('#menu a[rel^="playvideo"]').bind('click', function() {
			var clipId = $(this).attr('rel').split('-')[1];
			if(document.getElementById('enterthesite-video')) {
				document.getElementById('enterthesite-video').pause();
			} 
			if(clipId) {
				openOverlay(clipId);				
			} else {
				openOverlay();
			}
			return false;
		});
	}
	
	//opens the overlay player and plays a specified clip
	function autoPlay(clipId) {
		var autoPlayTrailer = setTimeout("openOverlay(" + clipId + ");", 5000);
		$('#menu, a').bind('click', function(){
			clearTimeout(autoPlayTrailer);
		});			
	}
	
	function connectAndShare(e) {
		$('#connect-share').bind('click', function(e) {				
			if (!$('#connect-share-extras').is(':animated')) {
				if($('#connect-share-extras').is(':hidden')) {
					connectAndShareSlide();
				} else {	
					$('#share').fadeTo('', 0.3);
					$('#connect-share-extras').slideToggle('normal', function() {
						$('#connect-share').removeClass('connect-expanded');
						$('#arrow').hide();						
					});	
				}			
				return false;
			}
		});			
		
		// hover state binded to li element.
		$('#connect-share').hover(
			function () { 
				$(this).addClass('connect-hover'); 
			}, function () { 
				$(this).removeClass('connect-hover');
			}
		);
		
		// stops triggering the events binded to parent DOM elements
		$('#connect li a, #share li a, #getglue-container').bind('click', function(e) {
			e.stopPropagation();
		});	
				
		// share integration
		$('#share li a').bind('click', function() {
			if($('#connect-share-extras').is(':hidden')) {						
				connectAndShareSlide();		
			} else {
				share.send($(this).attr('rel'));	
				if(typeof sCode == 'object') {
					sCode.trackOutboundClick($(this).attr('href'), $(this).attr('class'));				
				}
			}
			return false;
		});			
	}
	
	// sliding animation for connect and share section, apply this when slided state is the default layout
	function connectAndShareSlide() {
		$('#connect-share').addClass('connect-expanded');					
		$('#arrow').show();
		$('#share').fadeTo('', 1);
		$('#connect-share-extras').slideToggle();
	}
	
	function embedTicketsWidget($widgetDivId, $width, $height) {
		var flashvars;
		var params = {
			allowscriptaccess:"always",
			allowfullscreen:"true",
			base:"media/",
			wmode:"transparent",
			salign: "left"
		};					
		var attributes = {
			id: $widgetDivId
		};										
		swfobject.embedSWF(params.base + "sa_widget.swf", $widgetDivId, $width, $height, "9.0.115", "", flashvars, params, attributes);
	}
	
	function registerPopup() {
		$('#register').bind('click', function() {
			window.open(this.href, '', 'width=446, height=500, scrollbars=no, resizable=no');
			return false;
		});
	}
	
	function shareFade() {
	$('#share').fadeTo('', 0.3);
	}
	
	function openConnectAndShare() {
		$('#connect-share').trigger('click');
	}
	
	//fix for cufon flash of unstyled text(fout)
	function fixFoutBeforeCufon() {
		$('<style type="text/css">.cufonised { text-indent : -9000px; } .submenu, #maincontent > ul > li { display: none; } </style>').appendTo('head');
	}
	function fixFoutAfterCufon() {
		$('.cufonised').removeClass('cufonised');
	}
	
	// PUBLIC/PRIVILEGED 

	// Only include the functions that are going to get used
	this.init = function() {
		fixFoutBeforeCufon()
		//animation();
		initStylesAndMethods();
		fixFoutAfterCufon()
		//enterTheSite();
		//embedVideo(232,94);
		playVideos();		
		autoPlay();
		//connectAndShare();
		//openConnectAndShare();
		//embedTicketsWidget('getticketswidget', 257, 335);
		//registerPopup();			
	}	
		
}

var fwbSplash = new SplashUI();

$(function() {	
	fwbSplash.init();
});


/**************** FLASH DATA ******************/

var playerId = 'flashcontent';

var flashvars = {};


var params = {
	base:'media/',
	allowscriptaccess:"always",
	allowfullscreen:"true",
	wmode:"opaque"
};

var attributes = {
};
//v = swfobject.getFlashPlayerVersion();
//alert(v.major+'.'+v.minor+'.'+v.release);
swfobject.embedSWF("media/preloader.swf", playerId, 675 , 410, "10,0,0,0", null, flashvars, params, attributes);

