var globalLib =
{
	flash_functions :
	{
		init : function()
		{
			/* setup dynamic loading */	
			$.xLazyLoader({
			    js: 'http://1.scripts.sesamehost.com/scripts/jquery.flash_1.3.js',
			    name: 'flash',
			    success: function(){
					// Define the default configuation values
					// followed by individual module configuration.
					// Values for individual modules will override the defaults
					
					var flashModules = {
						
						defaults: {			
							'width': 500,
							'height': 300,
							'src': 'http://media.sesamehost.com/flash/',//default location of all Sesame flash mods
							'wmode': 'transparent',
							'flashvars': {
								'autoPlay': 'false', // change value to 'true'to play on start
								'thisColor': '0x' + '639CCE' // change global hex color (default=639CCE)
							},
							'express': 'flash/playerProductInstall.swf',
							'version':'9'
						},
					
					modules: [
					  // Define the configuration values for each flash module.
					  // Change item values in any 'flashvars' section to false to omit,
					  // Add any value to override the default value in flashModuleDefaults.
					  
					  // Individual Emergency Care Animations //-----------------------------------------------
					  {name: 'general-soreness', config: {'width': 200, 'height': 150}},
					  {name: 'headgear', config: {'width': 200, 'height': 150}},
					  {name: 'loose-appliance', config: {'width': 200, 'height': 150}},
					  {name: 'loose-bracket', config: {'width': 200, 'height': 150}},
					  {name: 'loose-wire', config: {'width': 200, 'height': 150}},
					  {name: 'poking-wire', config: {'width': 200, 'height': 150}}
  					  // End of animations
					]
					};
					
					// Loop through the defined modules 
					// and do flash replacement for any that are on the current page
					for (var j = flashModules.modules.length - 1; j >= 0; j--){
						var module = flashModules.modules[j];
						// combine default config settings with individual module config settings
						var modConfig = $.extend({}, flashModules.defaults, module.config);
						// combine default flashvars with module flashvars
						modConfig.flashvars = $.extend(flashModules.defaults.flashvars, module.config.flashvars);
						modConfig.src = modConfig.src + module.name + '.swf';
						$('#flash-' + module.name).flash(modConfig);
					}
					
			    }
			});
		
		}//end flash init
	}//end flash functions
	
	//Basic HTML and utility functions
//---------------------------------------------------------------------------------
	,html_functions :
	{
		init : function() 
		{
			// Some effects rely on an element to be initially hidden,
			// but we only hide them if the user has javascript
			$('.jshide').addClass('hide');

			//Toggle functions
			//---------------------------------------------------------------------------------
			// Show only when javascript is available
			$('#toggle-links').css('display','block');
		
			//hide lists first!
			//$('#toggle-content li div').css('display','none');	
			$('#toggle-content dl').hide();	
		
			//toggle
			function toggleInfoContent(id){
				if($(id).css('display') != 'none'){
				  $(id).fadeOut('fast');
		  		  $('.back-to-top').addClass('hide');
				}else{
				  //$("#toggle-content li div").hide();
				  $("#toggle-content dl").fadeOut('fast');
				  $(id).fadeIn('slow');
				  $('.back-to-top').removeClass('hide');
				}
			}
			$("#toggle-links").bind('click', function(e) {
				var target = e.target, // e.target grabs the node that triggered the event.
				$target = $(target);  // wraps the node in a jQuery object
				var id = $target.attr('href')
			    if (target.nodeName === 'A') {
			    	toggleInfoContent(id);
				}
			    return false;
			});
			
			// Emergency Care toggle //----------------------------------
			//hide items first!
			$('#toggle-emergency div p').hide();
			
			//toggle
			function toggleEmergency(id){
				if($(id).css('display') != 'none'){
					$(id).animate({opacity: 'toggle'}).parent().animate({width: '80px',height: '60px'});
				}else{
					$(id).animate({opacity: 'toggle'}).parent().animate({width: '200px',height: '150px'});
				}
			}
			$("a.toggle-div").bind('click', function(e) {
				var target = e.target, // e.target grabs the node that triggered the event.
				$target = $(target);  // wraps the node in a jQuery object
				var id = $target.attr('href')
				if (target.nodeName === 'A') {
					toggleEmergency(id);
				}
				return false;
			});
						
			//end toggle functions

		}//end HTML init
	}//end HTML functions
	
}
	
//JQuery Setup
$(function(){
	globalLib.html_functions.init();
	//--initialize on-demand library items
	if($("div[id^='flash-']", "div[id^='video']")){//load flash functions
		globalLib.flash_functions.init();
	}
});//end document.ready
