// JavaScript Document
// FF Bugfix
window.onunload = function(){};
//Media SubMenu
$(document).ready(function() {
	$('.plusNav li').children("ul").stop(true, true).animate({
		opacity: 'hide'
	}, 0, function() {
		//Animation Completes
	});
	$('.plusNav li').hover(function() {
		$(this).children("ul").stop(true, true).animate({
			opacity: 'toggle'
		}, 250, function() {
			//Animation Completes
		});	
	});
});

//Home Tweet Scroll
$(document).ready(function() {
		$('#tweetLeft').click(function() {
			if($("#homeTweet").position().left < 0 && !$("#homeTweet").is(":animated")) {
				$('#homeTweet').animate({
					left: '+=546'
				}, 500, function() {
				});
				return false;
			}
			if($("#homeTweet").position().left === 0 ) {
				$('#homeTweet').animate({
					left: '+=6'
				}, 50, function() {
				});
				$('#homeTweet').animate({
					left: '-=6'
				}, 300, function() {
				});
				return false;
			}
			else {
				return false;
			}
		});
});
$(document).ready(function() {
		$('#tweetRight').click(function() {
			if($("#homeTweet").position().left > -1172 && !$("#homeTweet").is(":animated")) {
				$('#homeTweet').animate({
					left: '-=546'
				}, 500, function() {
				});
				return false;
			}
			if($("#homeTweet").position().left = -1172 && !$("#homeTweet").is(":animated")) {
				$('#homeTweet').animate({
					left: '-=6'
				}, 50, function() {
				});
				$('#homeTweet').animate({
					left: '+=6'
				}, 300, function() {
				});
				return false;
			}
			else {
				return false;
			}
		});
});


//Hide/Show legal
$(document).ready(function() {
	//hide search div
	$("#footerLegalText").hide();
	//displays legal text on click
	$("#viewLegal").click(function() {
		$("#footerLegalText").slideToggle(250);
		return false;
	});
})


// Animated Page Scroll
$(document).ready(function() {
	$('.scrollable').click(function() {
	   var clickedLink = $(this).attr("href");
	   var scrollAnchor = $(clickedLink).offset().top;
	   $("html:not(:animated),body:not(:animated)").animate({ scrollTop: scrollAnchor}, 700 );
	   return false;
	});
});

// Colorbox Activation
$(document).ready(function(){
	$("a[rel='homeGallery']").colorbox({initialWidth:200, initialHeight:75, opacity:0.75});
	$("#signIn a").colorbox({initialWidth:200, initialHeight:75, innerWidth:548, innerHeight:317, opacity:0.75, scrolling:false, href:"/html/signIn.html"});
	$("#language a").colorbox({initialWidth:300, initialHeight:75, innerWidth:500, innerHeight:112, opacity:0.75, scrolling:false});
	$("a.featuredTrailerLink").colorbox({innerHeight:443, innerWidth:720, opacity:0.75, iframe:true});
	$("a[rel='videoGallery']").colorbox({innerHeight:443, innerWidth:720, opacity:0.75, iframe:true});
	//$("#preOrderLink a").colorbox({initialWidth:200, initialHeight:75, innerWidth:612, innerHeight:394, opacity:0.75, scrolling:false, href:"/html/preOrder.html"});
	$(".linkHoF").colorbox({innerHeight:300, innerWidth:600, opacity:0.75, initialWidth:500, initialHeight:100, iframe:true, scrolling:false});
});

//Automatically open media based on URL (this is for external linking)
$(document).ready(function(){
	if (window.location.href.indexOf("?") != -1) {	
		var urlQuery = location.search;
		urlQuery = urlQuery.replace('?', '');
		var mediaLinked = urlQuery.split('=');
		if (mediaLinked == "preorder"){
			$("#preOrderLink a").colorbox({initialWidth:200, initialHeight:75, innerWidth:612, innerHeight:394, opacity:0.75, scrolling:false, href:"/html/preOrder.html", open:true});
		}
		else {
			$('#' + mediaLinked).colorbox({initialWidth:200, initialHeight:75, opacity:0.75, open:true});
		}
	}
	else {
		return false;
	}
});
