/* --- Show Episode subnav on click */

function popUp(pg) { //turn on the popup window
	var marg = getOffset(940);
	var margpos = marg*-1;
	$('#popup-'+pg)
		.css('right',margpos+'px')
		.fadeIn(500);
}

function vanish(pg) { //Hide the popup window
	$('#popup-'+pg).fadeOut(500);
}

/* --- Determine Window Width */

function getOffset(obj) {
	var myWidth = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
	}
	//alert('Window: ' + myWidth + ', Object: ' + obj);
	var theOffset = ((myWidth-obj)/2)*-1;
	return(theOffset);
}

/* --- Horizontal Scrolling Page Content */	 

$(document).ready(function() {
	window.scroll(0,0);
	$('a[rel="external"]').attr('target','_blank');
	$("#press-digest-list").jScrollPane({ });
	$("#screenings-list").jScrollPane({ });
	$(".filmmakers-entry").jScrollPane({ });

	/**
	 * Most jQuery.localScroll's settings, actually belong to jQuery.ScrollTo, check it's demo for an example of each option.
	 * @see http://flesler.demos.com/jquery/scrollTo/
	 * You can use EVERY single setting of jQuery.ScrollTo, in the settings hash you send to jQuery.LocalScroll.
	 */

	$.localScroll.defaults.axis = 'x';

	//Unhide the content div
	$('#content').fadeIn(200);

	var nav = new Array();
		nav[0] = 'donald';
		nav[1] = 'trailer';
		nav[2] = 'marge';
		nav[3] = 'synopsis';
		nav[4] = 'press';
		nav[5] = 'contributors';
		nav[6] = 'filmmakers';
		nav[7] = 'screenings';
		nav[8] = 'dvd';
		nav[9] = 'contact';
	
	var widths = new Array();
		widths[0] = 930;
		widths[1] = 640;
		widths[2] = 930;
		widths[3] = 930;
		widths[4] = 930;
		widths[5] = 935;
		widths[6] = 990;
		widths[7] = 925;
		widths[8] = 930;
		widths[9] = 930;
		
	if(document.location.hash == '') {
		document.location.hash = '#trailer';
	}

	// Scroll initially if there's a hash (#something) in the url 
	$.localScroll.hash({
		target: '#content', // Could be a selector or a jQuery object too.
		queue:true,
		duration: 0,
		onBefore:function( e, anchor, $target ){
			for(var i=0; i<10; i++) {
				if(anchor.id != nav[i]) {
					$('#nav-'+nav[i]+' a').attr('id','');
					$('#subnav-'+nav[i]).css('display','none');
				} else {
					$('#nav-'+anchor.id+' a').attr('id','current');
					$('#subnav-'+nav[i]).css('display','block');
					this.offset = getOffset(widths[i]);
				}
			}
		},
	});
	
	/**
	 * NOTE: I use $.localScroll instead of $('#navigation').localScroll() so I
	 * also affect the >> and << links. I want every link in the page to scroll.
	 */
	$.localScroll({
		target: '#content', // could be a selector or a jQuery object too.
		queue:true,
		duration:1000,
		hash:true,
		onBefore:function( e, anchor, $target ){
			for(var i=0; i<10; i++) {
				if(anchor.id != nav[i]) {
					$('#nav-'+nav[i]+' a').attr('id','');
				} else {
					$('#nav-'+anchor.id+' a').attr('id','current');
					this.offset = getOffset(widths[i]);
				}
			}
		},
		onAfter:function( anchor, settings ){
			$('.subnav li a').attr('id','');
			$('.sub').css('display','none');
			$('#subnav-'+anchor.id).css('display','block');
		}
	});
	
	/*NEWSLETTER SIGNUP FORM*/
	$("input#email").focus(function(){
		$(this).val("");
	});
	$("input#go").hover(
		function(){ $(this).css('background-color','#adf6fc') .css('border-color','#adf6fc') .css('cursor','pointer'); },
		function(){ $(this).css('background-color','#fff06d') .css('border-color','#fff06d') .css('cursor','default'); }
	);
	$("form#newsSignup").submit(function() {
		var email = $("input#email").val();
		if((email == "") || (email == "REGISTER FOR UPDATES") || (email == "Valid E-Mail is Required.")) {
			$("input#email").focus();
			$("input#email").val("Valid E-Mail is Required.");
			return false;
		} else {
			var dataString = $(this).serialize();
			//window.alert(dataString);
			$("#signup-conf").load('include/email-newsletter.php?'+dataString);
			return false;
  		}
  	});
  	
  	/*DVD RESERVATION FORM*/
	$("input#dvd-name, input#dvd-email, input#dvd-zip").focus(function(){
		$(this).val("");
	});
	$("input#dvd-go").hover(
		function(){ $(this).css('background-color','#adf6fc') .css('border-color','#adf6fc') .css('cursor','pointer'); },
		function(){ $(this).css('background-color','#fff06d') .css('border-color','#fff06d') .css('cursor','default'); }
	);
	$("form#dvdSignup").submit(function() {
		var name = $("input#dvd-name").val();
		var email = $("input#dvd-email").val();
		var zip = $("input#dvd-zip").val();
		if((name == "") || (name == "Name") || (name == "- Required -")) {
			$("input#dvd-name").focus();
			$("input#dvd-name").val("- Required -");
			return false;
		} else if((email == "") || (email == "E-mail") || (email == "- Required -")) {
			$("input#dvd-email").focus();
			$("input#dvd-email").val("- Required -");
			return false;
		} else if((zip == "") || (zip == "ZIP Code") || (zip == "- Required -")) {
			$("input#dvd-zip").focus();
			$("input#dvd-zip").val("- Required -");
			return false;
		} else {
			var dataString = $(this).serialize();
			//window.alert(dataString);
			$("#dvd-message").load('include/email-dvd.php?'+dataString);
			return false;
  		}
  	});
	
});

/*--- Video Player Functions */

function playVideo(clip) {
	$(".vid-" + clip).slideToggle(500,
		function(){
			//determine the status of the toggle
			status = $("#trailer-splash").css('display');
			if(status == 'none') { objid = 'selected'; } else { objid = 'off'; }
			//show or hide objects based on status
			$("#circle-button").css('display',status);
			$("#" + clip + "-play a").attr('id',objid);
		}
	);
}
