/* 
-----------------------------------------------------------------
	NZNT
	shared.js
	
	Load and launch site functions (old DS version)
	Created 29.06.2007 by DS
	Last Updated: See SVN	
	
	Includes these updates:	
	* Safari onload fix 16.08.2007
	* $class fix 17.05.2007	
-----------------------------------------------------------------
*/

//	Load additional functions

	var imported_scripts = '';	
	var scripts = new Array();	

	scripts[0] = ('/resources/scripts/imported/nznt.js');
	scripts[1] = ('/resources/scripts/imported/styleswitcher.js');
	scripts[2] = ('/resources/scripts/imported/flash.js');
	scripts[3] = ('/resources/scripts/imported/browserdetect.js'); 
	// NOTE: browserdetect.js needs to load LAST for Safari to load the others. 
	// This could be because this script contains the only function that executes automatically, without waiting for an external call (from shared.js)
	// (browserdetect.js does not trigger any errors in the Safari JS console)

	for (var i=0; i<scripts.length; i++)
	{
		imported_scripts += ('\n<script type="text/javascript" src="' + scripts[i] + '"></script>' + '\n');	
	}
	
	document.write(imported_scripts);	

	window.onload = init;
	window.onresize = function() { if (whichbrowser.isHiFi) { widenInterface();} };
	

// DOM shorthand wrappers - these are MR's but are probably ok
	
	/**
	* getElementById
	* @return DomElement
	*/
	function $id(id) {
		return document.getElementById(id);
	}
	
	/**
	* getElementsByClassName
	* @return DomElement if single result, else array of DomElements 
	  updated by MR 17.05.2007 */ 
	function $class(name) {
		var result = new Array();
		var target = new RegExp("(^|\\s)" + name + "(\\s|$)");
		var elements = document.getElementsByTagName("*");
		var length = elements.length;
		var current;
		for (var i=0; i<length; i++) {
			current = elements[i];
			if (target.test(current.className)) {
				result.push(current);
			}
		}
		return (result.length > 1) ? result : result[0]; }
	
	/**
	* getElementsByTagName
	* @return DomElement if single result, else collection of DomElements
	*/
	function $tag(name) {
		result = document.getElementsByTagName(name);
		return (result.length > 1) ? result : result[0]; 
	}
	
//	GLOBAL EDITABLE VARIABLES
	var global_js_folder = '/resources/scripts/imported/';
	var global_required_flash_version = 8; 
	var global_latest_flash_version = 10;	
	var global_flash_bgcolor = '#ffffff';
	var global_add_flash_file_extension = false; // add .swf automatically, without specifying as part of the file path	

// trigger conditional functions
	
	function init()
	{	
		if (whichbrowser.isHiFi)
		{	
			widenInterface(); 

			if (cssIsEnabled())
			{
				addStyleSwitcherButton();
				applyResize();
			}		
			
			makeFauxLinks();
			enhanceTextFields();				
			createImgRollovers();			
			addMediaPlayers(); // Library section	
			inlineJavascriptTest();
			inlineFlashTest();
			checkDeleteLinks();
			
			if ($id('st-add-edit-podcast') || $id('st-add-edit-video'))
			{
				enhanceForm();
			}	
		}
	}	
