/* 
	init.js
	===============================================================
	The New Zealand Film Archive	
	Calls Functions
	
	Created 14.04.2009 by DS
	Last Updated: See SVN	
	
	#t-* used to apply template level override of shared styles
	#st-* used to apply sub template level override of shared styles	
	
	To sort, search for '@'		
	Debugging is via the Firebug console: console.debug
  ===============================================================
*/

/*	
	@ global vars
  ---------------------------------------------------------------
	_______________________________________________________________
*/			


	// global SWFOBJECT embed preferences
	var flash_src = false; 						
	var flash_width = '0';				
	var flash_height = '0';
	var flash_reqdVersion = '9.0.124'; // 99 for testing, else 9.0.124
	var flash_containerId = '';		
	var flash_expressInstaller = false;											
	var flash_attributes = {};				
	var flash_params = {}; 	
			flash_params.salign = 'lt';
			flash_params.base = '/resources/ui/media/';			
	var flash_vars = {}; 				
	var flash_custom_args = {};
			flash_custom_args.flash_warningContainerId = 'flash-warning-global';	

/*	
	@ $(document).ready
  ---------------------------------------------------------------
	Functions to initialise when the DOM has loaded
	_______________________________________________________________
*/			

	var isHiFi = false;
	whichbrowser = new Object();	
	whichbrowser.isHiFi = false;
	var platform = '';

	$(document).ready(
		function() 
		{			
			$.globals = {};		
			
			$.globals.isHiFi = false;		
			$.globals.isFirefox2 = false;
			$.globals.isFirefox2up = false;			
			$.globals.isFirefox3up = false;
			$.globals.isIE = false;	
			$.globals.isIE6 = false;
			$.globals.isIE6up = false;			
			$.globals.isIE7 = false;
			$.globals.isIE7up = false;		
			$.globals.isIE8up = false;					
			$.globals.isSafari = false;
			$.globals.isSafari3down = false;
			$.globals.isSafari3up = false;		
			$.globals.isSafari4up = false;
				
			$.globals.isHiFi = detect_browser();
			platform = detect_platform();					
		
			if ($.globals.isHiFi)
			{				
				firebug_console_check();		
				
				// Add stylesheets for x-browser compatibility
				
				if ( ( $.globals.isSafari3up ) && ( platform == 'win' ) )
				{
					attach_stylesheet('/resources/ui/styles/imported/browser/screen-win-safari.css', 'screen');
				}			
				if ( ( $.globals.isFirefox2 ) && ( platform == 'win' ) )
				{
					attach_stylesheet('/resources/ui/styles/imported/browser/screen-win-ff2.css', 'screen');
				}							
				if ( ( $.globals.isSafari3up ) && ( platform == 'mac' ) )			
				{
					attach_stylesheet('/resources/ui/styles/imported/browser/screen-mac-safari.css', 'screen');
				}		
				if ( ( $.globals.isFirefox2up ) && ( platform == 'mac' ) )						
				{
					attach_stylesheet('/resources/ui/styles/imported/browser/screen-mac-ff.css', 'screen');
				}								
			
				//console.debug( "$('body').attr('id') = ", $('body').attr('id') );									
				
				var body_id = $('body').attr('id');
				
				// faux noscript, to work around noscript nesting/validation issues
				$('.noscript')
				.addClass('access');
				
				if ( body_id.indexOf('t-calendar') == -1 )
				{
					// global SWFOBJECT test
					// SWFOBJECT Flash [warning, no expressInstall]						
					flash_customEmbed(flash_src, flash_containerId, flash_width, flash_height, flash_reqdVersion, flash_expressInstaller, flash_vars, flash_params, flash_attributes, flash_custom_args);																	
				}
				
				switch ( body_id )
				{
					case 't-calendar-month' :				
						//console.debug('calendar_tooltip_listeners()');
						calendar_tooltip_listeners();				
						break;
						
					case 't-home' :	
					
						// override global SWFOBJECT embed preferences
						
						// add insert-point hook for embed - but only if Flash is available
						if ((swfobject.hasFlashPlayerVersion(flash_reqdVersion)) && (flash_browser.supports_basicSwfobjectEmbed))
						{
							$('#logo .print')
							.attr('id', 'print-logo');						
						}
										
						// override global SWFOBJECT embed preferences
								flash_src = '/resources/ui/media/logo_405x35.swf';						
								flash_width = '405';				
								flash_height = '35';
								flash_containerId = flash_createContainer(flash_reqdVersion, 'flash-logo-embed', 'after', 'print-logo', '', '');			
								flash_params.wmode = 'transparent';	// allow bg pattern to show in bg														
								
								flash_advancedEmbed(flash_src, flash_containerId, flash_width, flash_height, flash_reqdVersion, flash_expressInstaller, flash_vars, flash_params, flash_attributes, flash_custom_args);																	
				
						break;
						
					case 't-news' :
						listener_content_news_hover();				
						break;
				}			
				
				flash_inline();				
				
				enable_tablesorting();
				
				enhance_enlargement_sets();
				
				listener_textfields();
				simple_tooltip();			
				listener_lightbox('.enlargement'); // after tooltip, in order to access link 'data'						
				button_print();																	
				add_link_arrows();							
				add_curves();
							
				// IE fixes
				ie_backtotop_patch();			
				ie_keyboard_access();				
	
				// preloaders - LAST!
				listener_fg_hover_states_incl_preload('button img');		
				listener_fg_hover_states_incl_preload('#signup a img');					
				listener_fg_hover_states_incl_preload('#tools a img');	
				listener_fg_hover_states_incl_preload('.tabbed-nav a img');				
				preload_bg_images();
				
			} // end hifi if
		} // end fn
	); // end ready
