// share config
share.url = 'http://www.thesmurfs-movie.net';
share.title = 'The Smurfs';
share.tweet = 'Check out The Smurfs! http://www.thesmurfs-movie.net';
share.description = 'THE SMURFS movie: a family comedy in 3D starring Hank Azaria, Neil Patrick Harris, and George Lopez. The beloved Smurfs are forced out of their world and into ours by the evil Gargamel.';

//overlayPlayer config
feedUrl = "http://www.sonypictures.net/movies/thesmurfs/thesmurfs_video.xml";
autocloseToggle = true;
clipName = 1757;
callbackToggle = false;

//autoplay trailer
var playTrailer = openOverlay();
		
var TAKEOVER = {
	open: function() {
		$('body').prepend('<div id="takeover-layer"></div><div id="takeover"></div>');
		$('#takeover-layer').css('opacity', '0.7');
		swfobject.embedSWF('media/takeover-video.swf', 'takeover', '800', '448', '10', '', {}, { wmode: 'opaque' }, {});
	},
	
	close: function() {
		$('#takeover').hide();
		$('#takeover-layer').fadeOut();
	}, 
	
	activateSite: function() {
		this.close();
		swfobject.embedSWF('media/videoButton.swf', 'enterthesite-video', '232', '87', '10', '', {}, { wmode: 'opaque' }, {});
	}
}

function videoClose() {
	TAKEOVER.activateSite();
}

function videoEnd() {
	TAKEOVER.activateSite();
}

var SplashUI = function() {
	
	// PRIVATE
	
	// any special styling that need to be done on load should be in this function
	function initStyles() {
		Cufon.replace('.cufon', { textShadow: '1px 1px #434d50', fontFamily: 'Futura Std' });
		Cufon.replace('#subtitle-p1', {fontFamily: 'Interstate-Black' });
		Cufon.replace('#connect li a span',  { textShadow: '1px 1px #cacac9', fontFamily: 'helveticaNeue' });
		//$('#enterthesite, #connect, #getglue-container').corner('3px');
	}
	
	// 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() {
		$('.entersite_keyart, #enterthesite').bind('click', function() {
			window.open('http://www.thesmurfs-movie.net/site/', '', 'height=760,fullscreen=yes, scrollbars=yes, resizable=no, status=no, directories=no, toolbar=no');
		});
	}
	
	//add tracking to game overlay
	
	function gameOverlay(){
		$('#register').bind('click', function(){
			if (isOmnitureExists())
			{
				sCode.trackPageView("playgames.html", '');  
			}
			return true;
		});
	}
	
	// video that goes into enter the site button - only used when enter the site button is active
	function embedVideo() {
		var flashvars = {};
		var params = {
			wmode: 'opaque',
			allowscriptaccess: true
		};	
		var attributes = {};
		swfobject.embedSWF('media/videoButton.swf', 'enterthesite-video', '232', '87', '10', '', flashvars, params, attributes);
	}
	
	// opens the overlay player
	function watchTrailer() {
		$('#watch-trailer').bind('click', function() {
			openOverlay();
			// use the code below when video is in the enter the site button
			//document.getElementById('enterthesite-video').pause();
			return false;
		});
	}
	
	function connectAndShare() {
		$('#connect-share').bind('click', function() {
			clearTimeout(playTrailer);
			if (!$('#connect-share-extras').is(':animated')) {
				if($('#connect-share-extras').is(':hidden')) {
					connectAndShareSlide();
				} else {		
					$('#share').fadeTo('', 0.3,function(){
						
						if($('#connect-share').hasClass('connect-hover')){				
							$('#share').css('background-image','url(images/share.jpg)');
						}
						else
						{
							$('#share').css('background-image','url(images/share2.jpg)');
						}
					});
					
					$('#connect-share-extras').slideToggle(null,function(){
						$('#connect-container').parent().parent().css('padding', '0px').parent().css('padding', '0px');
						$('#connect-share').removeClass('connect-expanded');
						$('#connect-share p.cufon').css('margin-top', '0');
						$('#arrow').hide();
						$('#share').css('margin','0 0 0 -1px');
					});	
				}			
				return false;
			}
		});
		
		// hover state binded to li element.
		$('#connect-share').hover(
			function () { 
				$(this).addClass('connect-hover');
				$('#share').css('background-image','url(images/share.jpg)');
			}, function () { 
				$(this).removeClass('connect-hover');
				
				if($('#connect-share-extras').is(':hidden')) {						
					$('#share').css('background-image','url(images/share2.jpg)');
				}
				else
				{
					$('#share').css('background-image','url(images/share.jpg)');
				}
			}
		);
		
		// stops triggering the events binded to parent DOM elements
		$('#share li a, #connect li a').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-container').corner('3px').parent().corner('4px').parent().css('padding', '1px').corner('4px').parent().css('padding', '1px').corner('4px');
		$('#connect-share').addClass('connect-expanded');					
		$('#share').css('margin','0 0 0 -2px');
		$('#connect-share p.cufon').css('margin-top', '0px');
		$('#arrow').show();
		$('#share').fadeTo('', 1);
		$('#share').css('background-image','url(images/share.jpg)');
		$('#connect-share-extras').slideToggle();
	}
	
	function registerPopup() {
		$('#register').bind('click', function() {
			window.open(this.href, '', 'width=446, height=500, scrollbars=no, resizable=no');
			return false;
		});
	}
	
	function gamePopup() {
		$('#potion-commotion').bind('click', function() {
			clearTimeout(playTrailer);
			window.open(this.href, '', 'width=620, height=510, scrollbars=no, resizable=no');
			return false;
		});
	}
	function quizPopup() {
		$('#take-smurf-quiz').bind('click', function() {
			clearTimeout(playTrailer);
			window.open(this.href, '', 'width=600, height=400, scrollbars=no, resizable=no');

			return false;
		});
	}
	//Configure pop up window. Must include global common.js
/*function windowPop(){
	var links = document.getElementsByTagName('a');	
	for(i=0;i<links.length;i++){
		if (links[i].getAttribute('rel')=="popup"){
			links[i].onclick = function(){
				clearTimeout(playTrailer);
                if(!displayWindow(this.href)){
						alert('Please disable your popup blocker and try again.');
				}else{displayWindow(this.href,"forgot_password",620,510,"directories=0,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0");
                }
				return false;
			}
		}
	}
}*/
	
	// PUBLIC/PRIVILEGED 

	// Only include the functions that are going to get used
	this.init = function() {
		initStyles();
		//animation();
		enterTheSite();
		embedVideo();
		watchTrailer();
		connectAndShare();
		//connectAndShareSlide();
		//registerPopup();
		gamePopup();
		quizPopup();
		//windowPop();
		gameOverlay();
	}	
	
}

var blaSplash = new SplashUI();

$(function() {	
	blaSplash.init();
	//TAKEOVER.open();	
});
