function registerPopup() {	
	if(document.getElementById('register')) {
		document.getElementById('register').onclick = function () {
			displayWindow('http://www.sonypictures.com/movies/thesocialnetwork/registration','',446,500);
			return false;
		}
	}
}

function facebookRecommend() {
	var containerDiv = document.getElementById('fbrecommend-iframe');
	var browserName = navigator.appName; 
	if(browserName == "Microsoft Internet Explorer") {
		containerDiv.innerHTML = '<div id="iewrapper"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fexample.com%2Fpage%2Fto%2Flike&amp;layout=button_count&amp;show_faces=false&amp;width=150&amp;action=recommend&amp;colorscheme=light&amp;height=35" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:150px; height:35px;" allowTransparency="true"></iframe></div>';
	} else {
		containerDiv.innerHTML = '<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fexample.com%2Fpage%2Fto%2Flike&amp;layout=standard&amp;show_faces=false&amp;width=226&amp;action=recommend&amp;colorscheme=light&amp;height=35" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:226px; height:35px;" allowTransparency="true"></iframe>';
	}
}

function openAbout() {	
	if ($("#overlayLayer2").is(":hidden")) {
		toggleAbout();	
		sCode.trackPageView('about.html','');
		//fix IE overlay sizing
		jQuery.each(jQuery.browser, function(i) {
			if ($.browser.msie && $.browser.version.substr(0,1)<7) {			 
				$("body, #overlayLayer2").css("width","100%").css("height",$(document).height()+"px").css("position","absolute");
				$("html").css("width","100%").css("height",$(document).height()+"px");
			}
		}); 
		$("#overlayLayer2, #overlayAbout").click(function () {
			closeAbout();								 
		});	
	}
}

function toggleAbout() {
	if ($("#overlayLayer2").is(":hidden")) {		
		$("#overlayLayer2").css("height","100%")
		$("#overlayLayer2, #overlayAbout").fadeIn("fast");	
	} else if($("#overlayLayer2").is(":visible")) {			
		$("#overlayLayer2, #overlayAbout").fadeOut("fast");
		$("#overlayLayer2").css("height","100%")			
	}
}

function closeAbout() {
	if ($("#overlayLayer2").is(":visible")) {	
		$("#overlayLayer2, #overlayAbout").fadeOut("fast");
		jQuery.each(jQuery.browser, function(i) {//fix IE overlay sizing
			if ($.browser.msie && $.browser.version.substr(0,1)<7) {
				$("body").css("width","auto").removeAttr("style");
				$("html").css("width","auto").removeAttr("style");
			}
		});       
	} 
}

function quoteRotation() {
	var curPos,
		nextPos;
	for(var i = 0, count = $('#quote div').length; i < count; i++) {
		if($('#quote div').eq(i).is(':visible')) {
			curPos = i;
		}
	}
	if( (curPos + 1) == $('#quote div').length ) {
		nextPos = 0; 
	} else {
		nextPos = curPos + 1;
	}
	$('#quote div').eq(curPos).hide();
	$('#quote div').eq(nextPos).fadeIn('slow');
}

function dimensionPopup() {
	var screenWidth  = window.screen.width,
		screenHeight = window.screen.height,
		width = 1280,
		height = 950;		
	if(screenHeight <= 1050) {
		height = screenHeight;
	}
	if(screenWidth < 1070) {
		width = 860;
	} else if(screenWidth >= 1070 && screenWidth < 1280) {
		width = 1070;
	} 
	
	$('#enter-the-site').bind('click', function() {
		var tracking = $(this).attr('rel');
		var type = $(this).attr('rev');
		if(type == 'outbound') {
			sCode.trackOutboundClick(this.href, tracking);
		} else {
			sCode.trackFeaturedContentClick(this.href, tracking);
		}
		//window.open(this.href, '', 'width=1060, height=1040, resizable=no, location=no, scrollbar=no, status=no, titlebar=no, toolbar=no, directories=no, fullscreen=no');
		if ( $.browser.webkit ) {
			window.open(this.href, '', 'width=' + screenWidth + ', height=' + screenHeight + ', left=0, top=0, resizable=no, scrollbars=yes, fullscreen=yes, location=no, status=no, titlebar=no, toolbar=no, directories=no');
			return false;
		} else {
			window.open(this.href, '', 'resizable=no, scrollbars=yes, fullscreen=yes, location=no, status=no, titlebar=no, toolbar=no, directories=no');
			return false;
		}
	});			
}	

function changeReleaseDate() {
	var d1 = new Date();
	var d2 = new Date("October 1, 2010 00:00:00");
	if(d1 > d2) {
		$('#sidebar h2').addClass('released');
	}
}

//overlayPlayer config
feedUrl = "http://www.sonypictures.com/previews/movies/thesocialnetwork.xml"; 
autocloseToggle = true; 
singlevideoToggle = false; 
//callbackToggle = true; 
//parentSwf = "flashcontent";
//clipName = 1757;
//clipName = 1800;
useQAplayer = true; 

//iPad/iPhone Sniffer
/*
if (navigator.userAgent.indexOf('iPad') != -1){
	window.location = './ipad/';
} else if((navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod')!= -1)) {
	window.location = './iphone/';
}
*/
var flashversion = "10.0.32.18";

if(typeof(swfobject)=='object' && swfobject.hasFlashPlayerVersion(flashversion)){
	
	var head = document.getElementsByTagName('head');
	var flashstyle = document.createElement('style');
	var css = '#flashcontent p, #flashcontent h1 {display: none}';

	flashstyle.setAttribute('type','text/css');
	

	if(head[0]){
		if(flashstyle.styleSheet){//cause you can't put text in the webstandards way in ie
			flashstyle.styleSheet.cssText = css;
		}else{
			flashstyle.appendChild(document.createTextNode(css));
		}
		head[0].appendChild(flashstyle);
	}
}

function flashcontentembed() {
	var flashvars = {};
		
	var params = {
		allowscriptaccess: 'always',
		wmode: 'opaque',
		base: 'media/',
		allowFullScreen: 'true',
		menu: false,
		bgcolor: '#000000'
	};
 
	var attributes = {
		id: 'flashcontent',
		name: 'flashcontent'
	};
											 
	swfobject.embedSWF('media/sa_widget.swf', 'flashcontent', "259", "303", "10.0.32.18", '', flashvars, params, attributes);
}



$(function() {
	/*registerPopup();
	flashcontentembed();
	changeReleaseDate();
	
	carousel.carouselId = '#carousel';
	carousel.type = 'circular';
	carousel.itemsDisplayed = 5;
	carousel.speed = 200;
	carousel.init();

	$('#prev').click(function() {
		carousel.goPrev();	
	}); 
	
	$('#next').click(function() {
		carousel.goNext();
	});						

	
	setInterval('quoteRotation()', 5000);
	
	$('li#quote div').hide();
	$('li#quote div').eq(0).show();
	
	//var autoPlay = setTimeout(openOverlay, 5000);
	
	$("body").prepend('<div id="overlayLayer2"></div><div id="overlayAbout"><iframe src="about.html" frameborder="0" width="632" height="358"></iframe></div>');
	$("#overlayLayer2").css("display","none").css("position","fixed").css("z-index","100").css("width","100%").css("opacity","0.7").css("background-color","#000").css("top","0").css("left","0").css("overflow","hidden").css("outline","none");

	jQuery.each(jQuery.browser, function(i) {
		if ($.browser.msie && $.browser.version.substr(0,1)<7) {			 
			$("#overlayLayer2").css("display","none").css("position","absolute").css("z-index","100").css("width","100%").css("height",$(document).height()+"px").css("opacity","0.7").css("background-color","#000").css("top","0").css("left","0").css("overflow","hidden");
			$('#overlayAbout').css("display","none").css('position', 'absolute').css("z-index","200").css("left","50%").css("margin-left","-330px");
		}
	});

	$('#trailer-and-video').bind('click', function() {		
		if($('#trailer-menu').is(':hidden')) {
			$('#trailer-and-video').addClass('trailer-current');
		} else {			
			$('#trailer-and-video').removeClass('trailer-current');
		}
		$('#trailer-menu').slideToggle();
		return false;
	});
	
	      	$('#select-language-button').bind('click', function() {                   
                        if($('#select-language').is(':visible')) {
                                    $('#select-language-button').removeClass('select-language-current');
                        } else {                          
                                    $('#select-language-button').addClass('select-language-current');
                        }
                        $('#select-language').slideToggle();
                        return false;
            });

	
	$('#trailer-menu li a').bind('click', function() {
		var id = $(this).attr('rel');
		openOverlay(id);
		return false;
	});	
	
	$('#about').bind('click', function() {
		clearTimeout(autoPlay);
		if(!$('#overlayLayer').is(':visible')) {
			openAbout();
		}
		return false;
	});
	
	$('#itrailer').bind('click', function() {
		window.open(this.href, '', 'width=640, height=395, resizable=no, location=no, scrollbar=no, status=no, titlebar=no, toolbar=no, directories=no, fullscreen=no');
		return false;
	});
	*/
	dimensionPopup();

});
