	/*
	JS
	--------------------------------------------------------------------------------------------
	@site			sho.com/nurse-jackie
	@file			NurseJackie.js
	@author			ncavanagh
	@desc			Sets up a modular js library and NurseJackie namespace.
	@depend			prototype, swfobject
	
	/* =:nurseJackie
	--------------------------------------------------------------------------------------------*/
	if(typeof NurseJackie =="undefined"){ var NurseJackie = new Object(); }
	NurseJackie.Helpers = [];
	NurseJackie.library = function()
	{ 
		var jsBase = "/site/nursejackie/season1/js";
		var KEY_IN = '/site/nursejackie/';
		var KEY_OUT = '.do';
		var TOKEN = '_';
		
		var library = 
		{
			global: [
				'Cosmetics'
			],
			
			components: [
				//'Glider',
				'AjaxFeeds',
				'jsr_class'
			],
			
			home: [
				'HomeUIHelp',
				'unitpngfix'
			],
			
			video: [
				'VideoFeeds'
			],
			
			downloads: [
				'DownloadsUIHelp'
			],
			
			special_features: [
				'SpecialFeaturesUIHelp'
			],
			
			actor_bios: [
				'ActorBiosUIHelp'
			],
			
			episodes: [
				'EpisodesUIHelp'
			],
			
			schedule: [
				'Schedule'
			]
			
		};
		
		
		/* =:Startup
		--------------------------------------------------------------------------------------------*/
		function init()
		{
			if( document.location.search.toString().indexOf('noscript') > -1 ) return;
			document.write( "\n" );
			loadModule ( library.global, 'global' );
			loadModule ( library.components, 'components' );
			parseLocation();
		}
		
		function parseLocation()
		{  
			var urlStr = document.location.pathname;
			var str1 = urlStr.substr( urlStr.indexOf( KEY_IN ) + KEY_IN.length );
			var str2 = str1.substr( 0, str1.indexOf( KEY_OUT )).replace(/-/, '_');
			var path = str2.split('/');
			
			// check for flattened homepage
			if( document.location.pathname.indexOf('/index.html') !== -1 ){
				importModules ( ['home'] );
			}
											   
			else importModules ( path );
			
		}
		
		function importModules ( path )
		{  
			var m = "";
			for( var i=0; i<path.length; i++ ){
				m += path[i];
				if( typeof library[ m ] == "object" &&  library[ m ] !== null ){ 
					loadModule( library[ m ], path[0] );
				}
				m+=TOKEN;
			}
		}
		
		function loadModule( mod, package )
		{   
			package = ( package == false ) ? '' : '/' + package;
			for( var i=0; i<mod.length; i++) 
			{   
				document.write( '<script language="javascript" src="'+ jsBase + package + '/'+
							   			mod [i] + '.js"></script>'+"\n" );	
			}
		}
		
		
		/* Reveal public methods 
		-------------------------*/
		return {
		deploy:init
		}
		
	}();

	NurseJackie.library.deploy(); 
	
