var forceIPhone = false;
var iPhone = false;
var testMode = false;
var enableGoogleAnalytics = true;
var siteName = 'Noisy Neighbors';

//var featuredSpotPath = "../video/reels/simpson_05_generic_with_poster_frame.mov";
var featuredSpotPath = "../video/reels/Groupon - Whales-H.264 LAN with Poster Frame.mov";  // 2/15/11

var aPageNavLinks = new Array();
aPageNavLinks['home'          ] = { name: 'home'          , left: 0  , top: 0, width: 66 , height: 27 };

aPageNavLinks['whatwedo'      ] = { name: 'whatWeDo'      , left: 66 , top: 0, width: 115, height: 27 };
aPageNavLinks['post'          ] = { name: 'post'          , left: 0  , top: 0  , width: 115, height: 27 };
aPageNavLinks['music'         ] = { name: 'music'         , left: 0  , top: 45 , width: 115, height: 27 };
aPageNavLinks['library'       ] = { name: 'library'       , left: 0  , top: 90 , width: 115, height: 27 };
aPageNavLinks['web'           ] = { name: 'web'           , left: 0  , top: 135, width: 115, height: 27 };

aPageNavLinks['whatwevedone'  ] = { name: 'whatWeveDone'  , left: 181, top: 0, width: 142, height: 27 };
aPageNavLinks['reels'         ] = { name: 'reels'         , left: 0  , top: 5  , width: 115, height: 27 };

aPageNavLinks['whoweare'      ] = { name: 'whoWeAre'      , left: 323, top: 0, width: 115, height: 27 };
aPageNavLinks['whereithappens'] = { name: 'whereItHappens', left: 438, top: 0, width: 143, height: 27 };
aPageNavLinks['latestbuzz'    ] = { name: 'latestBuzz'    , left: 581, top: 0, width: 103, height: 27 };
aPageNavLinks['contact'       ] = { name: 'contact'       , left: 683, top: 0, width: 91 , height: 27 };

aPageNavLayout = new Array();
aPageNavLayout = ['home', 'whatwedo', 'whatwevedone', 'whoweare', 'whereithappens', 'latestbuzz', 'contact'];

var aDeepLinks = new Array();
aDeepLinks['home'          ] = { page : 'home' };

aDeepLinks['whatwedo'      ] = { page : 'music', subDS : 'postContentDiv', subNL : 'postNavLink', subShortName : 'overview' };
aDeepLinks['post'          ] = { page : 'post' , subDS : 'postContentDiv', subNL : 'postNavLink', subShortName : 'overview' };
aDeepLinks['postoverview'  ] = { page : 'post' , subDS : 'postContentDiv', subNL : 'postNavLink', subShortName : 'overview' };
aDeepLinks['postspecial'   ] = { page : 'post' , subDS : 'postContentDiv', subNL : 'postNavLink', subShortName : 'special'  };
aDeepLinks['postcredits'   ] = { page : 'post' , subDS : 'postContentDiv', subNL : 'postNavLink', subShortName : 'credits'  };
aDeepLinks['postbrochure'  ] = { page : 'post' , subDS : 'postContentDiv', subNL : 'postNavLink', subShortName : 'brochure' };

aDeepLinks['music'         ] = { page : 'music', subDS : 'musicContentDiv', subNL : 'musicNavLink', subShortName : 'overview' };
aDeepLinks['musicoverview' ] = { page : 'music', subDS : 'musicContentDiv', subNL : 'musicNavLink', subShortName : 'overview' };
aDeepLinks['musicspecial'  ] = { page : 'music', subDS : 'musicContentDiv', subNL : 'musicNavLink', subShortName : 'special'  };
aDeepLinks['musiccredits'  ] = { page : 'music', subDS : 'musicContentDiv', subNL : 'musicNavLink', subShortName : 'credits'  };
aDeepLinks['musicbrochure' ] = { page : 'music', subDS : 'musicContentDiv', subNL : 'musicNavLink', subShortName : 'brochure' };

aDeepLinks['library'       ] = { page : 'library' };

aDeepLinks['web'           ] = { page : 'web' };

aDeepLinks['whatwevedone'  ] = { page : 'whatwevedone'};
aDeepLinks['commercials'   ] = { page : 'whatwevedone', subNL : 'reelsNavLink', subShortName : 'commercials'  };
aDeepLinks['trailers'      ] = { page : 'whatwevedone', subNL : 'reelsNavLink', subShortName : 'trailers'     };
aDeepLinks['sounddesign'   ] = { page : 'whatwevedone', subNL : 'reelsNavLink', subShortName : 'sounddesign'  };
aDeepLinks['nmss'          ] = { page : 'whatwevedone', subNL : 'reelsNavLink', subShortName : 'nmss'         };
aDeepLinks['funstuff'      ] = { page : 'whatwevedone', subNL : 'reelsNavLink', subShortName : 'funstuff'     };

aDeepLinks['whoweare'      ] = { page : 'whoweare', subDS : 'aboutBioDiv', subNL : 'aboutNavLink', subShortName : 'nn'  };
aDeepLinks['noisy'         ] = { page : 'whoweare', subDS : 'aboutBioDiv', subNL : 'aboutNavLink', subShortName : 'nn'  };
aDeepLinks['rob'           ] = { page : 'whoweare', subDS : 'aboutBioDiv', subNL : 'aboutNavLink', subShortName : 'ra'  };
aDeepLinks['gary'          ] = { page : 'whoweare', subDS : 'aboutBioDiv', subNL : 'aboutNavLink', subShortName : 'ga'  };
aDeepLinks['mercs'         ] = { page : 'whoweare', subDS : 'aboutBioDiv', subNL : 'aboutNavLink', subShortName : 'jm'  };
aDeepLinks['maria'         ] = { page : 'whoweare', subDS : 'aboutBioDiv', subNL : 'aboutNavLink', subShortName : 'me'  };
aDeepLinks['vanarden'      ] = { page : 'whoweare', subDS : 'aboutBioDiv', subNL : 'aboutNavLink', subShortName : 'sva' };

aDeepLinks['whereithappens'] = { page : 'whereithappens'};

aDeepLinks['latestbuzz'    ] = { page : 'latestbuzz'};

aDeepLinks['contact'       ] = { page : 'contact'};

aLinkShortcuts = new Array();
aLinkShortcuts['nn' ] = 'whoweare';
aLinkShortcuts['ra' ] = 'rob';
aLinkShortcuts['ga' ] = 'gary';
aLinkShortcuts['jm' ] = 'mercs';
aLinkShortcuts['me' ] = 'maria';
aLinkShortcuts['sva'] = 'vanarden';


var aPageTitles = new Array();
aPageTitles['home'          ] = "Purveyors Of Music & Noise";
aPageTitles['post'          ] = 'Audio Post';
aPageTitles['postoverview'  ] = 'Audio Post - Overview';
aPageTitles['postspecial'   ] = 'Audio Post - Special Projects';
aPageTitles['postcredits'   ] = 'Audio Post - Credits';
aPageTitles['postbrochure'  ] = 'Audio Post - Brochure';

aPageTitles['music'         ] = 'Music';
aPageTitles['musicoverview' ] = 'Music - Overview';
aPageTitles['musicspecial'  ] = 'Music - Special Projects';
aPageTitles['musiccredits'  ] = 'Music - Credits';
aPageTitles['musicbrochure' ] = 'Music - Brochure';

aPageTitles['library'       ] = 'Library';
aPageTitles['web'           ] = 'Web Design';
aPageTitles['whatwevedone'  ] = "What We've Done";
aPageTitles['commercials'   ] = 'Commercial Reel';
aPageTitles['trailers'      ] = 'Trailer Reel';
aPageTitles['sounddesign'   ] = 'Sound-Design Reel';
aPageTitles['nmss'          ] = 'NMSS Spot';
aPageTitles['funstuff'      ] = 'Fun Stuff';
aPageTitles['whoweare'      ] = 'Who We Are';
aPageTitles['nn'            ] = 'Who We Are';
aPageTitles['ra'            ] = 'Who We Are - Rob Arbittier';
aPageTitles['ga'            ] = 'Who We Are - Gary Adante';
aPageTitles['jm'            ] = 'Who We Are - James Mercs';
aPageTitles['me'            ] = 'Who We Are - Maria Elgar';
aPageTitles['sva'           ] = 'Who We Are - Steve Van Arden';
aPageTitles['whereithappens'] = 'Where It Happens';
aPageTitles['latestbuzz'    ] = 'Latest Buzz';
aPageTitles['contact'       ] = 'Contact';

var aNavImgData = new Array();
aNavImgData['pageNavLink'] = { path  : 'assets/images/nav/',
							   prefix: 'btn_',
							   suffix: '.gif',
							   states: ['_off_out', '_off_over', '_on_out', '_on_over'] };

var aAttr = new Array();
aAttr['reelsNavLink'] = new Array();
aAttr['reelsNavLink']['offout' ] = { fontSize: '.9em', color: '#999' };
aAttr['reelsNavLink']['offover'] = { fontSize: '.9em', color: '#BBB' };
aAttr['reelsNavLink']['onout'  ] = { fontSize: '1em' , color: '#EEE' };
aAttr['reelsNavLink']['onover' ] = { fontSize: '1em' , color: '#EEE' };

aAttr['postNavLink'] = new Array();
aAttr['postNavLink']['offout' ] = { fontSize: '.9em', color: '#999' };
aAttr['postNavLink']['offover'] = { fontSize: '.9em', color: '#BBB' };
aAttr['postNavLink']['onout'  ] = { fontSize: '1em' , color: '#EEE' };
aAttr['postNavLink']['onover' ] = { fontSize: '1em' , color: '#EEE' };

aAttr['musicNavLink'] = new Array();
aAttr['musicNavLink']['offout' ] = { fontSize: '.9em', color: '#999' };
aAttr['musicNavLink']['offover'] = { fontSize: '.9em', color: '#BBB' };
aAttr['musicNavLink']['onout'  ] = { fontSize: '1em' , color: '#EEE' };
aAttr['musicNavLink']['onover' ] = { fontSize: '1em' , color: '#EEE' };

aAttr['aboutNavLink'] = new Array();
aAttr['aboutNavLink']['offout' ] = { fontSize: '.9em', color: '#999' };
aAttr['aboutNavLink']['offover'] = { fontSize: '.9em', color: '#BBB' };
aAttr['aboutNavLink']['onout'  ] = { fontSize: '1em' , color: '#EEE' };
aAttr['aboutNavLink']['onover' ] = { fontSize: '1em' , color: '#EEE' };

var aPlayers = new Array();
var aBGs = new Array();

var stat = new Array();
stat['chooseReel'     ] = true;
stat['portfolioFilled'] = false;

var aReelNames = ['commercials', 'trailers', 'sounddesign', 'nmss', 'funstuff'];

var aReels = new Array();
aReels['commercials'] = { title       : "Commercials",
						  divSubName  : "Commercials",
						  src         : "../video/reels/nn_marias_commercial_reel_1_h264_800Kbps_a3.mov",
						  numIndexes  : 9,
						  names       : new Array ("Old Navy 1",
						  						   "Old Navy 2",
												   "NATPE",
												   "Utah Labor Commission",
												   "US Postal Service",
												   "KCRW",
												   "Ortega",
												   "Kodak / Godzilla",
												   "Left Field"),
						  startTimes  : new Array (0,31,49,77,107,136,190,220,253) };
						  
aReels['trailers'   ] = { title       : "Trailers",
						  divSubName  : "Trailers",
						  src         : "../video/reels/nn_trailer_reel_a3-h.264-854x480-800kbps.mov",
						  numIndexes  : 9,
						  names       : new Array ("The Messenger",
						  						   "Ocean's 11",
												   "Charlie's Angels",
												   "Godzilla",
												   "London",
												   "The Messenger",
												   "Almost Famous",
												   "The Patriot",
												   "Pearl Harbor"),
						  startTimes  : new Array (0,79,114,148,261,311,368,405,421) };
						  					  
aReels['sounddesign'] = { title       : "Sound-Design",
						  divSubName  : "SoundDesign",
						  src         : "../video/reels/sound_design_reel.f4v",
						  numIndexes  : 4,
						  names       : new Array ("KCRW",
						  						   "US Postal Service",
												   "Utah Labor Commission",
												   "NATPE"),
						  startTimes  : new Array (0,57,82,112) };
						  
aReels['nmss'       ] = { title       : "NMSS",
						  divSubName  : "NMSS",
						  src         : "../video/reels/NMSS_20101108_MASTER_v8.2.h264-H.264_800Kbps.mov",
						  numIndexes  : 1,
						  names       : new Array ("'Enough'"),
						  startTimes  : new Array (0) };
						  
aReels['funstuff'   ] = { title       : "Fun Stuff",
						  divSubName  : "FunStuff",
						  src         : "../video/reels/left_field.f4v",
						  numIndexes  : 1,
						  names       : new Array ("Country Demo"),
						  startTimes  : new Array (0) };
						  
var container;
var deepLink;

var bod;
var winCoords;
var docCoords;

var leftNavWidth = 165;
var topNavHeight = 157;
var reelsPlayerHBorder = 0;
var reelsPlayerVBorder = 0;
var contentPad = 20;

var ajaxOptions = new Object;
var current     = new Array();
current['page'] = 'home';

var aObjs = new Array();
aObjs['dbgDiv'         ] = new Array();
aObjs['page'           ] = new Array();
aObjs['pageNavLink'    ] = new Array();
// aObjs['pageSubMenu'    ] = new Array();

aObjs['reelsNavLink'   ] = new Array();
aObjs['reelsIndexes'   ] = new Array();

aObjs['postNavLink'    ] = new Array();
aObjs['postContentDiv' ] = new Array();

aObjs['musicNavLink'   ] = new Array();
aObjs['musicContentDiv'] = new Array();

aObjs['aboutNavLink'   ] = new Array();
aObjs['aboutBio'       ] = new Array();
aObjs['aboutBioDiv'    ] = new Array();
aObjs['portfolioSlot'  ] = new Array();

var numPortfolioSlots = 5;
var projectTypes = ['f', 't', 'a', 'c', 'i'];
var slotTitles = ['<br />Film', '<br />TV', '<br />Albums', '<br />Commercials', 'Interactive /<br />Special Venues'];

window.addEvent('domready', fnDomReady);
/*
function showReelTitle (which) {
	$('reelTitle_div').innerHTML = aReels[which].title;
}

function showReelSubIndexes (which) {
	$('reelSubIndexes_div').innerHTML = '';
	for (var i=0; i<aReels[which].numIndexes; i++) {
		var newLink = '<a href="javascript:vidJump(' + aReels[which].startTimes[i] + ')" class="reelSubIndex">' + aReels[which].names[i] +
						'</a>';
		var newDiv = new Element ('div', { id   : 'index' + i + '_div',
										   html : newLink });
		newDiv.addClass('reelSubIndex');
		newDiv.inject ($('reelSubIndexes_div'));
//		alert (aReels['commercials'].names[i] + ", " + aReels['commercials'].startTimes[i]);
	}
}
*/
function setReelsSubIndexes() {
	for (var r=0; r<aReelNames.length; r++) {
		var sn  = aReelNames[r];						// short name
		var dsn = aReels[aReelNames[r]].divSubName;		// div sub name
		var idn = 'reelsIndexes' + dsn + '_div';		// index div name
		$(idn).innerHTML = '';
		for (var i=0; i<aReels[sn].numIndexes; i++) {
			var newLink = '<a href="javascript:vidJump(' + aReels[sn].startTimes[i] + ')" class="reelSubIndex">' + aReels[sn].names[i] +
							'</a>';
			var newDiv = new Element ('div', { id   : 'index' + i + '_div',
											   html : newLink });
			newDiv.addClass('reelSubIndex');
			newDiv.inject ($(idn));
	//		alert (aReels['commercials'].names[i] + ", " + aReels['commercials'].startTimes[i]);
		}
		aObjs['reelsIndexes'][sn].resetHeight(); // necessary for sliding effect to work
	}
}

function buildObjArray(cat, objType) {
	$$('.' + cat).each(function(item) {
		switch (objType) {
			case 'Dbg'     : aObjs[cat] [divAbbrev(item.id, cat)] = new Dbg      (item.id, cat); break;
			case 'DivSet'  : aObjs[cat] [divAbbrev(item.id, cat)] = new DivSet   (item.id, cat); break;
			case 'Hideable': aObjs[cat] [divAbbrev(item.id, cat)] = new Hideable (item.id, cat); break;
			case 'NavLink' : aObjs[cat] [divAbbrev(item.id, cat)] = new NavLink  (item.id, cat); break;
			default: alert ('Bad Object Type: ' + objType); break;
		}
	});
}

function vidJump (t) {
	aPlayers['theater'].FLToActionScript( {func     : "jump",
										jumpTime : t });
}

function initFlash() {
	var reelPlayerArgs = {
		divId       : "theaterPlayer_div",
		shortName   : "theater",
		autoHide    : false,
		flashPath   : "assets/flash/nnMediaPlayer1_a3.swf",
		flashWidth  : "100%",
		flashHeight : "100%",
		flashMinVer : "9.0.0" };
	
	var reelFlashVars   = {	shortName  : "theater",
							playerMode : "v",
							autoStart  : "false",
							plVisible  : "true",
							debugMode  : "false",
							initSrc    : featuredSpotPath };
	
	var reelFlashParams = { play             : "true",
							wmode            : "transparent",
							allowFullScreen  : "true",
							allowScriptAccess: "always",
							scale            : "noscale",
							salign           : "tl" };
							
	reelPlayerArgs.autoHide = (aObjs['page'][current['page']].div.hasClass('theater')) ? false : true;

	aPlayers['theater'] = new Player(reelPlayerArgs, reelFlashVars, reelFlashParams);
}

function fnDomReady() {	// alert ('Currently testing new functionality.  Please be patient.');

	if (testMode) {
		enableGoogleAnalytics = false;

		$('dbg_div')           .setStyle('display', 'block');
		$('theater_div')       .setStyle('background-color', '#FF0');
		$('theaterPlayer_div') .setStyle('background-color', '#00F');
		$('theaterDetails_div').setStyle('background-color', '#F00');
		$('dbg_div').addEvent('mousedown', function() {
			aPlayers['theater'].obj.SetURL(escape('../../assets/video/2012 NCM Trlr-2Mbps 16x9.mov'));
		});
	}

	bod = document.getElement('body');
	winCoords = window.getCoordinates();
	docCoords = bod.getCoordinates();
			
	if (forceIPhone || (navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
		iPhone = true;
		$('iPhone_div').setStyle('visibility', 'visible');
	} else {
		window.onresize = resized;
	}
	
	container = new Container ( { id : 'container_div', bgPath : 'assets/images/backgrounds/nn_background_1920x1200_a1.gif' } );
	deepLink  = new DeepLink();
	
	buildObjArray('dbgDiv'         , 'Dbg'     );
	buildObjArray('pageNavLink'    , 'NavLink' );
//	buildObjArray('pageSubMenu'    , 'Hideable');
	buildObjArray('reelsNavLink'   , 'NavLink' );
	buildObjArray('reelsIndexes'   , 'Hideable');
	buildObjArray('postNavLink'    , 'NavLink' );
	buildObjArray('postContentDiv' , 'DivSet'  );
	buildObjArray('musicNavLink'   , 'NavLink' );
	buildObjArray('musicContentDiv', 'DivSet'  );
	buildObjArray('aboutNavLink'   , 'NavLink' );
	buildObjArray('page'           , 'DivSet'  );
	buildObjArray('aboutBioDiv'    , 'DivSet'  );
	
	for (var i=0; i<numPortfolioSlots; i++) {
		aObjs['portfolioSlot'][i] = new Slot('portfolio', i);
		aObjs['portfolioSlot'][i].div.inject ('portfolio_div');
	}

	resized();
	
	initFlash();
	
	gotoDeepLink();
	
	$('loading_div').setStyle('display', 'none');
	$('topNav_div' ).setStyle('display', 'block');
	
//	showReelTitle      ('commercials');
//	showReelSubIndexes ('commercials');
	
	if (enableGoogleAnalytics) {
		aObjs['dbgDiv']['google'].init ("Google Analytics Are Enabled");
	} else {
		aObjs['dbgDiv']['google'].init ("Google Analytics Are Disabled");
	}
}

function showPostBrochure() {
    var postPDF = new PDFObject({ 
      url: 'assets/pdf/nn_post_onesheet_v2.pdf',
      pdfOpenParams: { navpanes: '0' }
    }).embed('post_pdf');
/*	var hasIt = postPDF.get("pluginTypeFound");
	if (hasIt) {
		alert ('yes');
	} else {
		alert ('no');
	} */
}

function showMusicBrochure() {
    var musicPDF = new PDFObject({ 
      url: 'assets/pdf/nn_music_onesheet_v2.pdf',
      pdfOpenParams: { navpanes: '0' }
    }).embed('music_pdf'); 
}
