// JavaScript Document
var win= null;
function NewWindow(mypage,myname,w,h,scroll){
    var winl = (screen.width-w)/2;
    var wint = (screen.height-h)/2;
    var settings  ='height='+h+',';
        settings +='width='+w+',';
        settings +='top='+wint+',';
        settings +='left='+winl+',';
        settings +='scrollbars=1';
        settings +='resizable=0';
    win=window.open(mypage,myname,settings);
    if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
$(document).ready(function() {
	$('.con').hide(0);
	$('#logo').hide(0);
	$('.navbar').hide(0);
	$('.navbartop').hide(0);
	$('.amusic').hide(0);
	abhide();
	$('.con').css('left', -4620);
	abintro(1000);
	$('.nav1, #synopsis').click(
	function() {
		abhide();
		$('.con').animate({left: '-770px'}, 1000);
			$('.synopsis').show(0);
			cblock('asynopsis');
	});
	$('.nav2').click(
	function() {
		abhide();
		$('.con').animate({left: '-1540px'}, 1000);
		$('.castcrew').show(0);
		cblock('acastcrew');
	});
	$('.nav3').click(
	function() {
		abhide();
		$('.con').animate({left: '-2310px'}, 1000);
		$('.press').show(0);
		cblock('apress');
	});
	$('.nav4').click(
	function() {
		abhide();
		$('.con').animate({left: '-3080px'}, 1000);
		$('.production').show(0);
		cblock('aproduction');
	});
	$('.nav5').click(
	function() {
		abhide();
		$('.con').animate({left: '-3850px'}, 1000);
		$('.gallery').show(0);
		cblock('agallery');
	});
	$('.nav6').click(
	function() {
		abhide();
		$('.con').animate({left: '-4620px'}, 1000);
		$('.trailers').show(0);
		cblock('atrailers');
	});
	$('.omega').click(
	function() {
		abhide();
		abintro(0);
	});
	$('.galleryt').click(
	function() {
		var bid = $(this).attr('id');
		$('.gback').css('display', 'none');
		$('.gback').stop(true, true).fadeOut(0);
		$('.galleryt').removeClass('gallerytc');
		$('#' + bid).addClass('gallerytc');
		var burl = 'url(gallery/gallery_' + bid + '.jpg)';
		$('.gback').css('background-image', burl);
		$('.gback').stop(true, true).fadeIn(1800);
	});
	$('.theading').click(
	function() {
		if ($(this).attr('id') == 'T1') {
			var turl = 'trailer_large.html';
			var wsize = 'width=730, height=510';
		} else if ($(this).attr('id') == 'T2') {
			var turl = 'trailer_medium.html';
			var wsize = 'width=700, height=400';
		} else if ($(this).attr('id') == 'T3') {
			var turl = 'trailer_small.html';
			var wsize = 'width=700, height=400';
		}
		window.open(turl, 'Among Brothers Trailer', wsize);
	});
	$('.qtheadings').click(
	function() {
		window.open('http://www.apple.com/quicktime/download/', '_blank');
	});
	$('.aradiop').click(
	function() {
		var song = $('#aradio').get(0);
		song.play();
	});
	$('.aradiopa').click(
	function() {
		var song = $('#aradio').get(0);
		song.pause();
	});
	$('.amusic').click(
	function() {
		if ($('#amusic').get(0).paused) {
		$('#amusic').get(0).play();
		$('.amusic').removeClass('amusicp');
		} else {
		$('#amusic').get(0).pause();
		$('.amusic').addClass('amusicp');
		}
	});
	document.getElementById('amusic').addEventListener('ended', 
	function() {
		$('#amusic').get(0).currentTime = 0;
	}, false);
});
function abhide() {
	$('.homenbc').stop().css('height', 0);
	$('.homenbc').stop().hide(0);
	$('.homenbc h1').stop().css('display', 'none');
	$('.nbclogo').stop().css('display', 'none');
	$('.nbctext').stop().css('display', 'none');
	$('.homenbc a').stop().css('display', 'none');
	$('.homelaurel').stop().css('height', 0);
	$('.homelaurel').stop().hide(0);
	$('.homelaurelh').stop().css('display', 'none');
	$('.homelaurellist').css('display', 'none');
	$('.ccontentcon').stop().css('display', 'none');
	$('.omega').stop().show(0);
	$('.synopsis').css('display', 'none');
	$('.castcrew').css('display', 'none');
	$('.press').css('display', 'none');
	$('.procution').css('display', 'none');
	$('.gallery').css('display', 'none');
	$('.gback').css('display', 'none');
	$('.gback').stop().css('background-image', '');
	$('.galleryt').removeClass('gallerytc');
	$('.trailers').css('display', 'none');
	$('.cheading').css('display', 'none');
	$('.ccontentcon').animate({height: '0px'}, 0);
	$('#aintro').get(0).pause();
	$('#asynopsis').get(0).pause();
	$('#acastcrew').get(0).pause();
	$('#apress').get(0).pause();
	$('#aproduction').get(0).pause();
	$('#agallery').get(0).pause();
	$('#atrailers').get(0).pause();
}
function abintro(ldelay) {
	var hll = 6;
	var hlld = 300;
	$('.omega').css('display', 'none');
	var _img = new Image();
	var url = $('#abback').attr('src');
	$(_img).one('load', 
	function() {
	$('#load').delay(ldelay).hide(0, 
	function() {
	  $('.con').show(0, 
	  function() {
		$('#logo').show(0);
		$('.amusic').show(0);
		$('#amusic').get(0).play();
		$('.con').animate({left: '0px'}, 1000, 
		  function() {
			  $('.homelaurel').show(0);
			  $('.homenbc').show(0);
			  $('.homelaurel').animate({height: '325px'}, 800, 
			  function() {
				  $('.homelaurelh').fadeIn(800, 
					  function() {
						  $('.homelaurellist').each(function(index, element) {
							$(element).stop().delay(hlld*index).fadeIn(hlld);
						});
					  });
					  $('.homenbc').delay(hlld*hll).animate({height: '135px'}, 800, 
					  function() {
						  $('.homenbc h1').fadeIn(300, 
						  function() {
							  $('.nbclogo').fadeIn(300, 
							  function() {
								  $('.nbctext').fadeIn(300, 
								  function() {
									  $('.homenbc a').fadeIn(300, 
									  function() {
										  $('#aintro').get(0).play();
									  });
								  });
							  });
						  });
					  });
			  });
		  });
	  $('.navbar').show(0);
	  $('.navbartop').show(0);
	  });
	});
	}).attr('src', url);
};
function cblock(paudio) {
	$('.cheading').delay(750).fadeIn(1000, 
	function() {
		$('.ccontentcon').show(0);
		$('.ccontentcon').stop().animate({height: '275px'}, 1000, 
		function() {
			$('#' + paudio).get(0).play();
		});
	});
};
