
	/*
	JS
	--------------------------------------------------------------------------------------------
	@site				sho.com/site
	@project			sho (970)
	@package			n/a
	@file				lib.js
	@modified			10.02.09
	@author				dpaul
	@desc				Sets up a modular js lib and sho namespace for sho.com
	@note				Added support for 3rd party use.
	@note				Define global/common packages to import in the layout file, not here.
	
	/* =:sho
	--------------------------------------------------------------------------------------------*/
	var sho = {}; sho.settings = {};
	sho.Library = function()
	{ 
		var LIVE_URL = 'http://www.sho.com';
		var JS_BASE = "/site/sho/js/com/sho";
		var JS_SELF = '/site/sho/js/lib.js';
		var KEY_IN = '/site/!/';
		var KEY_OUT = '.do';
		var TOKEN = '_';
		var GLOBAL_PACKAGE; 
		 
		
		var lib = 
		{
			core: [
				'Debugger',
				'Sugar',
				'Utils',
				'Cosmetics',
				'Overlay',
				'NiftyJavaBombs'
			],
			common: [
				'Navigation',
				'Membership',
				'Dialogs',	
				'SimpleVideo'	
			],
			components: [
				'Calendar',
				'DropDownMenu',
				'DateMenu',
				'Glider',
				'SelectionMatrix',
				'Tabs'
			],
			forms : [
				'Validation',
				'FieldLimiter'
			],
			global: [
				'Backgrounds',
				'Scaffolding',
				'MoviesModule'
			],
			ecards:[
				'FormHelp'
			],
			home:[
				'Carousel',
				'RSSTicker'
			],
			movies:[
				'AToZList',
				'InfoBox',
				'MoviesPage'
			],
			schedules_channel:[
					'HDModule',
					'ChannelData',
				'Channel'
			],
			schedules_grid:[
					'ChannelData',
					'ProductInfo',
					'GridSlider',
				'Grid'
			],
			schedules_product:[
					'PhotoGallery',
				'Product'
			],
			schedules_ondemand:[
					'OnDemandModel',
					'OnDemandController',
					'OnDemandView',
				'OnDemand'
			],
			series:[
				'Pager',
				'HomePage'
			]
					
		};
		
		/* =:Private
		----------------------------------------------------------------------------------------*/
		function initialize()
		{
			if( document.location.search.toString().indexOf('noscript') > -1 ) return;
			doThirdPartyCheck();
			
			document.write( "\n\t" );
			parseScriptParams();
			parseLocation();
		}
		
		function doThirdPartyCheck()
		{
			// if hosted on third party server, set flag to use absolute javascript paths
			sho.settings.isLocal = ( document.location.port == '8080' || ([
				'dev.sho.com', 'qa.sho.com', 'posting.sho.com', 'www.sho.com'
			]).join(' ').indexOf( document.location.host ) > -1 ) ? true : false;
		}
		
		function parseScriptParams()
		{
			$$('head script[src]').findAll(function(s)
			{
				// find the the <script> element that links to this file
				return s.src.match(JS_SELF);
				
			}).each(function(s)
			{
				var modules = [];
				// pull out the params stashed on the end
				if( s.src.match(/\?.*load=([a-z,1-9]+)/)){
		    		modules = s.src.match(/\?.*load=([a-z,1-9]+)/)[1].split(',');
				}
				// load each module that is specified 
				modules.each(function(m){
					loadModule(lib[m],m)
				});
		    });
		}
		
		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('/');
			importModules ( path );	
		}
		
		function importModules ( path )
		{
			var m = "";
			for( var i=0; i<path.length; i++ )
			{
				m += path[i];
				if( typeof lib[ m ] == "object" &&  lib[ m ] !== null )
				{ 
					var module = lib[ m ];
					var package = GLOBAL_PACKAGE == undefined ?
						path[0] : GLOBAL_PACKAGE;
					
					loadModule( module, package );
					
				}
				m+=TOKEN;
			}
		}
		
		function loadModule( mod, p )
		{ 
			var prefix = sho.settings.isLocal ? '' : LIVE_URL;
			var package = ( p == false ) ? '' : '/' + p;
			for( var i=0; i<mod.length; i++)
			{
				document.write((['',
				'<script language="javascript" src="', prefix, JS_BASE, package , '/',
					mod[i], '.js"></script>',"\n\t",
				'']).join(''))
			}
		}	
		
		/* =:Reveal as Public
	 	----------------------------------------------------------------------------------------*/
		return { 
			init:initialize
		}
		
	}();
	
	sho.Library.init(); 
	
	/* No surrender, No delete! */
	