	/*
	JS
	--------------------------------------------------------------------------------------------
	@site			sho.com/nurse-jackie
	@file			Californication.js
	@author			ncavanagh
	@desc			Sets up a modular js library and Californication namespace.
	@depend			prototype, swfobject
	@note			removed some SHO library clones, referencing sho.core, sho.common instead
	
	/* =:Californication
	--------------------------------------------------------------------------------------------*/
	if(typeof Series =="undefined"){ var Series = new Object(); }
	Series.Helpers = [];
	Series.library = function()
	{ 
		var jsBase = "/site/californication/season3/js";
		var KEY_IN = '/site/californication/';
		var KEY_OUT = '.do';
		var TOKEN = '_';
		
		var library = 
		{
			global: [
				'SimpleVideo',
				'ExternalAd',
				'NextOn'
				
			],
			
			components: [
				'jsr_class',
				'protofish',
				'Slider'
			],
			
			feeds: [
				'VideoFeed',
				'RelatedVideos',
				'CommunityFeeds',
				'Boards',
				'SpecialFeatures'
			],
			
			video: [
				'brightcove',
				'title'
			],
			
			home: [
				'HomeUIHelp'
			],
			
			episodes: [
				'PhotoGallery',
				'EpisodeClips',
				'EpisodesUIHelp'
			],
			
			schedule: [
				'Schedule'
			],
			
			characters: [
				'CharactersUIHelp'
			],
			
			downloads: [
				'DownloadsUIHelp'
			]
			
		};
		
		
		/* =:Startup
		--------------------------------------------------------------------------------------------*/
		function init()
		{
			if( document.location.search.toString().indexOf('noscript') > -1 ) return;
			document.write( "\n" );
			loadModule ( library.global, 'global' );
			loadModule ( library.components, 'components' );
			loadModule ( library.feeds, 'feeds' );
			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
		}
		
	}();

	Series.library.deploy(); 
	
