window.onload = init; // note - parameter brackets absent: ()

var stylesheet_titles = new Array();
stylesheet_titles[1] = 'Text Size: Smallest';	
stylesheet_titles[2] = 'Text Size: Small';
stylesheet_titles[3] = 'Text Size: Regular';	
stylesheet_titles[4] = 'Text Size: Large';	
stylesheet_titles[5] = 'Text Size: Largest';

var smaller_function_link, larger_function_link;
// Global Flash Variables
var global_required_flash_version = 8; 
var global_latest_flash_version = 10;	
var global_flash_bgcolor = '#ffffff';

function init() 
{
	if (whichbrowser.isHiFi)
	{	
		add_print_tool();
		generate_resize_buttons();
		applyResize();	
		//flashprocess(); // Generate flash - disabled
	}
}
	
/*	## Extend Page Tools
	add_print_tool()
	Add extra functionality for Javascript-enabled users */

function add_print_tool() {
	if (document.getElementById) {
		// 	add extra functions to page tools list
		var page_tools = document.getElementById('print-tool');														

		// 	create print link
		var print_function_link = document.createElement('a');		
			print_function_link.setAttribute('href', '#');	
			print_function_link.onclick = function(){ window.print(); return false; }
		var print_function_link_text = document.createTextNode('Print page');
			print_function_link.appendChild(print_function_link_text); // a + text		

		var print_img = document.createElement('img');			
			print_img.setAttribute('src', '/fileadmin/templates/images/ui/tools/print.gif');		
			print_img.setAttribute('width', 22); // quotes added for ie - to test		
			print_img.setAttribute('height', 17); // quotes added for ie - to test				
			print_img.setAttribute('alt', '');

			print_function_link.appendChild(print_img); // a + img		
			// add new functions to page tools
			page_tools.appendChild(print_function_link);	
	}

}


/*	## Test for CSS
	based on http://www.quirksmode.org/dom/getstyles.html */

function test_for_css() {
	/* 	WARNING!! 
		If the 'Skip to Content' img is removed, this test will fail! */
	if (document.getElementsByTagName) {
		var pixel = document.getElementsByTagName('img')[0];
		
		css_enabled = false;
		
		if (pixel.currentStyle) { /* explorer - note explorer fork must come first! */
			var pixel_css_width = eval('pixel.currentStyle.width');
		} else if (document.defaultView.getComputedStyle) { /* mozilla */
			var pixel_css_width = document.defaultView.getComputedStyle(pixel, '').getPropertyValue("width");
		}

		// css will be enabled if pixel has been stretched to 2px wide by linked CSS file
		
		if ((pixel_css_width) && (pixel_css_width == '2px')) {
			css_enabled = true;
		}
	}
}

//	## generate_resize_buttons

function generate_resize_buttons() {
	test_for_css();	

	if ((document.getElementById) && (css_enabled)) {
		// 	add extra functions to page tools list
		var view_smaller = document.getElementById('view-smaller'); // Smaller link
		var view_larger = document.getElementById('view-larger'); // Bigger link

			smaller_function_link = document.createElement('a');		
			smaller_function_link.setAttribute('href', '#');	
		var smaller_button_link_text = document.createTextNode('Smaller');

		var smaller_img = document.createElement('img');			
			smaller_img.setAttribute('src', '/fileadmin/templates/images/ui/tools/smaller-arrow.gif');		
			smaller_img.setAttribute('width', 14); // quotes added for ie - to test		
			smaller_img.setAttribute('height', 6); // quotes added for ie - to test				
			smaller_img.setAttribute('alt', '');

			smaller_function_link.appendChild(smaller_img); // a + img
			smaller_function_link.appendChild(smaller_button_link_text); // a + text	
			view_smaller.appendChild(smaller_function_link); // div + link

// Add in 'Resize' image
		var resize_img = document.createElement('img');			
			resize_img.setAttribute('src', '/fileadmin/templates/images/ui/tools/text.gif');		
			resize_img.setAttribute('width', 51); // quotes added for ie - to test		
			resize_img.setAttribute('height', 12); // quotes added for ie - to test				
			resize_img.setAttribute('alt', '');		
			view_smaller.appendChild(resize_img); // div + resize image

			larger_function_link = document.createElement('a');		
			larger_function_link.setAttribute('href', '#');	
		var larger_button_link_text = document.createTextNode('Bigger');

		var larger_img = document.createElement('img');			
			larger_img.setAttribute('src', '/fileadmin/templates/images/ui/tools/bigger-arrow.gif');		
			larger_img.setAttribute('width', 16); // quotes added for ie - to test		
			larger_img.setAttribute('height', 6); // quotes added for ie - to test				
			larger_img.setAttribute('alt', '');

			larger_function_link.appendChild(larger_button_link_text); // a + text	
			larger_function_link.appendChild(larger_img); // a + img
			view_larger.appendChild(larger_function_link); // div + link
	}
}

function update_resize_buttons(current_size) {
	var downsize_button = document.getElementById('view-smaller');
	var downsize_button_isEnabled = downsize_button.getElementsByTagName('a')[0];	
	var upsize_button = document.getElementById('view-larger');	
	var upsize_button_isEnabled = upsize_button.getElementsByTagName('a')[0];			
	
	// buttons use spans by default

	// if no sizeStyle retrievable, remove resize set
	if (current_size == 0) {

	} else if (current_size == 1) {
		// Disable smaller button (we canna get any smaller captain!)
		
		// update javascript action for upsize button
		larger_function_link.setAttribute('href', 'javascript:setActiveStyleSheet(' + (current_size + 1) + ')');								
		
		// update javascript action for downsize button
		smaller_function_link.removeAttribute('href');
		
	} else if ((current_size > 1) && (current_size < 5)) {
		// update javascript action for upsize button		
		larger_function_link.setAttribute('href', 'javascript:setActiveStyleSheet(' + (current_size + 1) + ')');		
		
		// update javascript action for downsize button
		smaller_function_link.setAttribute('href', 'javascript:setActiveStyleSheet(' + (current_size - 1) + ')');
	}	
	else if (current_size == 5) {
		// Disable bigger button (we canna get any bigger captain!)

		// update javascript action for upsize button
		larger_function_link.removeAttribute('href');

		// update javascript action for downsize button
		smaller_function_link.setAttribute('href', 'javascript:setActiveStyleSheet(' + (current_size - 1) + ')');	
	}

}

/*  ## 	StyleSwitcher (resize text)
		Enable/Disable and Cookies sections written by Paul Sowden
		http://www.idontsmoke.co.uk/ss/
		http://www.alistapart.com/stories/alternate/
	-------------------------------------------------------------- */

function setActiveStyleSheet(titleNumber) {
	// styles only persistent if cookies enabled, so all style changes applied via cookie	
	var i, a, main, title, current_size;
	
	// create/overwrite cookie so that style is persistent
	createCookie("style", titleNumber, 365);
	
	// read cookie - only apply new style if cookies enabled / styles persistent
	cookieSize = readCookie('style');
	//alert(cookieSize);
	
	if (cookieSize) {
		current_size = parseInt(readCookie('style'));	// retrieve and convert to number
	} else {
		current_size = 0;
	}
	
	// use cookie value to apply styling
	if (current_size != 0) {
		// match titleNumber to title stored in array
		title = stylesheet_titles[current_size];	
		
		// loop through all alternative stylesheets (identified by <link rel="stylesheet"...title="...">)
		// disable all alternative stylesheets
		// enable selected alternative stylesheet
		for (i=0; (a = document.getElementsByTagName("link")[i]); i++) {
			if (
				(a.getAttribute("rel").indexOf("style") != -1) // Is this a link to a style sheet?
				&& 
				(a.getAttribute("title")) // Is there a title attribute? (only preferred/alternate stylesheets have a title)
			) 
			{
				a.disabled = true; // disable all alternatives by default
				
				if (a.getAttribute("title") == title) { // if this is the preferred alternative
					a.disabled = false; // enable this alternative
				}
			}
		}
	}
	
	// update display of and actions triggered by resize buttons (remove button set if current_size == 0)
	update_resize_buttons(current_size);		
}

function applyResize() {
	var sizeStyle = readCookie("style");
	
	if (sizeStyle != null) { // if a style has been set, what is it?
		setActiveStyleSheet(sizeStyle); // enable this particular alternate stylesheet
	} else { // apply the default alternate stylesheet
		setActiveStyleSheet(3); // set size to default	
	}
}

/*  ## Read and Write Cookies
	http://www.quirksmode.org/js/cookies.html
	***************************************** */

function createCookie(name, value, days) 
{
	if (days) {
		var date = new Date();
		date.setTime(date.getTime() + (days*24*60*60*1000));
		var expires = '; expires = ' + date.toGMTString();
		var path = '; path=/';
	}
	else var expires = '';
	// path added 210705 as cookie may have been saved per page or folder
	document.cookie = name + ' = ' + value + expires + path;
}

function readCookie(name) {
	/* 	?? PC IE5x
	
		For some reason this function is failing in IE5x, 
		while the createCookie() function is working well.
		This issue is duplicated on other sites offering a test script.
		Could this be a problem with the test browser?
	*/
	
	var name_value = name + '='; // white space between quotes removed!
	var cookie_array = document.cookie.split(';');
	
	for (var i=0; i<cookie_array.length; i++) {
		var c = cookie_array[i];
		
		while (c.charAt(0) == ' ')
		{
			c = c.substring(1, c.length);				
		}
		if (c.indexOf(name_value) == 0) {
			return c.substring(name_value.length, c.length);
		}
		
  }
  return null;
}

/* 
	Browser Detect 08.06.2007
*/

//	VARIABLES

	var whichbrowser;
	
//	FUNCTIONS	

	function detectbrowser() 
	{
		// Browser Detect  v2.1.6
		// documentation: http://www.dithered.com/javascript/browser_detect/index.html
		// license: http://creativecommons.org/licenses/by/1.0/
		// code by Chris Nott (chris[at]dithered[dot]com)	
		
		var ua = navigator.userAgent.toLowerCase(); 
		
		// browser engine name
		this.isGecko       = (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);   
		
		// browser name
		this.isKonqueror   = (ua.indexOf('konqueror') != -1); 
		this.isSafari      = (ua.indexOf('safari') != - 1); // Intro #owners DIV
		this.isOmniweb     = (ua.indexOf('omniweb') != - 1);
		this.isOpera       = (ua.indexOf('opera') != -1); // Crew Profiles Info DIV
		this.isIcab        = (ua.indexOf('icab') != -1); 
		this.isAol         = (ua.indexOf('aol') != -1); 
		this.isIE          = (ua.indexOf('msie') != -1 && !this.isOpera && (ua.indexOf('webtv') == -1) ); 
		this.isMozilla     = (this.isGecko && ua.indexOf('gecko/') + 14 == ua.length);
		this.isFirefox    = (ua.indexOf('firefox/') != -1);
		this.isNS          = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && !this.isOpera && !this.isSafari && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) );
		
		// spoofing and compatible browsers
		this.isIECompatible = ( (ua.indexOf('msie') != -1) && !this.isIE);
		this.isNSCompatible = ( (ua.indexOf('mozilla') != -1) && !this.isNS && !this.isMozilla);	
	
		// rendering engine versions
		this.geckoVersion = ( (this.isGecko) ? ua.substring( (ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14) ) : -1 );
		this.equivalentMozilla = ( (this.isGecko) ? parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) ) : -1 );
		this.appleWebKitVersion = ( (this.isAppleWebKit) ? parseFloat( ua.substring( ua.indexOf('applewebkit/') + 12) ) : -1 );
		
		// browser version
		this.versionMinor = parseFloat(navigator.appVersion); 	
	
	   // correct version number
		if (this.isGecko && !this.isMozilla) {
		  this.versionMinor = parseFloat( ua.substring( ua.indexOf('/', ua.indexOf('gecko/') + 6) + 1 ) );
		}
		else if (this.isMozilla) {
		  this.versionMinor = parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) );
		}
		else if (this.isIE && this.versionMinor >= 4) {
		  this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
		}
		else if (this.isKonqueror) {
		  this.versionMinor = parseFloat( ua.substring( ua.indexOf('konqueror/') + 10 ) );
		}
		else if (this.isSafari) {
		  this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('safari/') + 7 ) );
		}
		else if (this.isOmniweb) {
		  this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('omniweb/') + 8 ) );
		}
		else if (this.isOpera) {
		  this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera') + 6 ) );
		}
		else if (this.isIcab) {
		  this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab') + 5 ) );
		}
		
		this.versionMajor = parseInt(this.versionMinor); 
		
		// dom support
		this.isDOM1 = (document.getElementById);
		this.isDOM2Event = (document.addEventListener && document.removeEventListener);
		
		// css compatibility mode
		this.mode = document.compatMode ? document.compatMode : 'BackCompat';
		
		// platform
		this.isWin    = (ua.indexOf('win') != -1);
		this.isWin32  = (this.isWin && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1 || ua.indexOf('xp') != -1) );
		this.isMac    = (ua.indexOf('mac') != -1);
		this.isUnix   = (ua.indexOf('unix') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1)
		this.isLinux  = (ua.indexOf('linux') != -1); 
		
		// detect ie version
		this.isIE5x = (this.isIE && this.versionMajor == 5);
		this.isIE55 = (this.isIE && this.versionMinor == 5.5);
		this.isIE5up = (this.isIE && this.versionMajor >= 5);
		this.isIE6x = (this.isIE && this.versionMajor == 6);
		this.isIE6up = (this.isIE && this.versionMajor >= 6);
		this.isIE7x = (this.isIE && this.versionMajor == 7);	
		this.isIE7up = (this.isIE && this.versionMajor >= 7);		
		
		// detect ns version
		this.isNS6x = (this.isNS && this.versionMajor == 6);
	
		// detect opera version
		this.isOpera6 = ((this.isOpera) && (this.versionMajor <= 6));	
		
		// opera
		this.isAnyOpera = ((this.isOpera) && (this.versionMajor >= 6));	
		this.isOpera7orBelow = ((this.isOpera) && (this.versionMajor <= 7));			
				
		if ((this.isIE5x) || (this.isOpera7orBelow) || (this.isSafari))
		{		
			this.isHiFi = false;		
		}		
		else
		{
			this.isHiFi = true;			
		}
	}
	
	whichbrowser = new detectbrowser();	
    
	// process flash files - disabled
	//function flashprocess() {
	//	var flashcontainer = document.getElementById('flash');
	//	if (flashcontainer) {
	//		generateFlash('flash', flashFileName, flashWidth, flashHeight, '', '', '');				
	//	} 
	//}