/*	Film NZ 2005
		Site Scripts
		Created 270705 by DS 
		Last updated - See SVN
	
		Variable names preceeded by 'global_' are used by multiple functions/script files
*/
	
	// init global vars:
	var global_content_layers = new Array();
	var global_location_id;
	var global_interactive_href;
	var global_flash_available = false;
	var global_interactivemap_map = '';
	var global_minimap_map = '';
	var global_minimap_link = '';
	
	var global_ajax_good_enough=1;
	
	var agent = navigator.userAgent.toLowerCase();

	if (agent.indexOf("msie 5") != -1) {
		global_ajax_good_enough = 0;
	}
	
	// init global flash vars
	var global_flash_version = 0;
	var global_latest_flash_version = 10;
	var global_required_flash_version = 7; // moved up here to SIMPLIFY things =)
	var global_flash_version_DONTKNOW = -1;	// used by detect
	var global_flash_used = false; // used to track whether to generate flash help text or not	
	
	/* FOR TESTING PURPOSES ONLY!
	************************** */
	// var DMNETsession = 'Test value'; // 17.01.2007
	/* ********************** */
	
	var dmnid = DMNETsession; /* DEEPMETRIX LiveStats.NET */
	

	/*  INIT
	************************** */	

	function init(global_location_id, page_specific_function)
	{
		disableFirebugLogging();		
		
		if (document.getElementById) // once here for ALL functions
		{
			// Add IE8 stylesheet
			if ( whichbrowser.isIE8x )
			{
				var stylesheet = document.createElement('link');
				stylesheet.setAttribute('type', 'text/css');
				stylesheet.setAttribute('rel', 'stylesheet');
				stylesheet.setAttribute('media', 'screen');
				stylesheet.setAttribute('href', '/resources/styles/imported/filmnz_pc_ie8.css');				
				
				document.getElementsByTagName('head')[0].appendChild(stylesheet);
			}
			
			location_id = set_global_location_id();
			
			if (page_body_id > 5)
			{
				add_print_to_page_tools(); // shown on all pages except home page
			}
			else
			{
				match_panel_heights(); // homepage only
			}
			
			if ((page_body_id==19) && (!page_specific_function))
			{
				if(global_ajax_good_enough==1){
					new showcase();
				}
			}
			
			generate_minimap_and_location_info(location_id);		

			if (page_specific_function == 'interactivemap')
			{
				init_interactivemap(); // see filmnz-interactive-map.js
			}		
			if ((page_specific_function == 'locationsearch') || (page_specific_function == 'locationsearchresults'))
			{						
				init_locationsearch(page_specific_function);
			}						
		}
	}
	
	/*  FIREBUG
	************************** */		
	
	function disableFirebugLogging()
	{
		/* 
			If the (Firefox) Firebug console is open when the page is loaded, a hidden DIV is inserted between the HEAD and BODY elements.
			This DIV allows developers to use the console logger, but unfortunately also causes the horizontal UI resize to fail.
			
			1. output a polite warning message to any developers that have the console open on window.load
			2. remove the Firebug DIV
		*/
		
		var fb_id = '_firebugConsole';			
		
		if (window.console && window.console.firebug) 
		{		
			if ( document.getElementById )
			{	
				if ( document.getElementById( fb_id ) )
				{
					console.warn('Please note: console logging disabled - #' + fb_id + ' removed');
					document.getElementById( fb_id ).parentNode.removeChild( document.getElementById(fb_id) );										
				}			
			}
		}
	}
	
	/*  FLASH DETECTION
	************************** */	
	
	/* 	Note:
		Detection MUST be performed during page load.
		This is because the IE fork writes VB script to the page -
		if this was done post page load the page contents
		would be replaced with the script thereby erasing 
		the page content.		
	*/

	// Flash Version Detector  v1.2.1
	// documentation: http://www.dithered.com/javascript/flash_detect/index.html
	// license: http://creativecommons.org/licenses/by/1.0/
	// code by Chris Nott (chris[at]dithered[dot]com)
	// with VBScript code from Alastair Hamilton (now somewhat modified)
	
	
	function isDefined(property) {
	  return (typeof property != 'undefined');
	}
	function detect_flash_version() 
	{	  
	   var agent = navigator.userAgent.toLowerCase(); 
	   
	   // NS3 needs global_flash_version to be a local variable
	   if (agent.indexOf("mozilla/3") != -1 && agent.indexOf("msie") == -1) {
		  global_flash_version = 0;
	   }
	   
	   // NS3+, Opera3+, IE5+ Mac (support plugin array):  check for Flash plugin in plugin array
	   if (navigator.plugins != null && navigator.plugins.length > 0) {
		  var flashPlugin = navigator.plugins['Shockwave Flash'];
		  if (typeof flashPlugin == 'object') { 
			 for (var i = global_latest_flash_version; i >= 3; i--) {
				if (flashPlugin.description.indexOf(i + '.') != -1) {
				   global_flash_version = i;
				   break;
				}
			 }
		  }
	   }
	   // IE4+ Win32:  attempt to create an ActiveX object using VBScript
	   // Note: Flash detection run during page load, so that IE can output VB Script to page
	   else if (agent.indexOf("msie") != -1 && parseInt(navigator.appVersion) >= 4 && agent.indexOf("win")!=-1 && agent.indexOf("16bit")==-1) {
		  var doc = '<scr' + 'ipt language="VBScript"\> \n';
		  doc += 'On Error Resume Next \n';
		  doc += 'Dim obFlash \n';
		  doc += 'For i = ' + global_latest_flash_version + ' To 3 Step -1 \n';
		  doc += '   Set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash." & i) \n';
		  doc += '   If IsObject(obFlash) Then \n';
		  doc += '      global_flash_version = i \n';
		  doc += '      Exit For \n';
		  doc += '   End If \n';
		  doc += 'Next \n';
		  doc += '</scr' + 'ipt\> \n';
		  document.write(doc);
	   }
		  
	   // WebTV 2.5 supports flash 3
	   else if (agent.indexOf("webtv/2.5") != -1) global_flash_version = 3;
	
	   // older WebTV supports flash 2
	   else if (agent.indexOf("webtv") != -1) global_flash_version = 2;
	
	   // Can't detect in all other cases
	   else {
		  global_flash_version = global_flash_version_DONTKNOW;
	   }
	
	   return global_flash_version;
	}	
	
	function set_global_location_id()
	{
		/* 	SET LOCATION
			-	Read location number: <=5: home, >5: internal
			-	Homepage - set a number to lock location down, or to 0 to randomise location
			-	Refresh sequence is currently purely random
			-	Internal Pages - set a number to lock image down, or to -1 to randomise location
		*/		

		global_location_id = get_page_body_id();
		
		if (page_body_id == 0)
		{	
			// randomise homepage location
			set_new_page_body_id();	
			// get new id
			global_location_id = get_page_body_id();
		}				
		
		return global_location_id;		
	}	

	function get_page_body_id()
	{
		page_body = document.body;
		page_body_id = page_body.id.substring(9, page_body.id.length);
		
		return page_body_id;
	}	
	
	function set_new_page_body_id()
	{
		var options = 4;
		var random_location_id = Math.round(Math.random()*options);
		new_page_body_id = (random_location_id + 1);				
		
		// update css backgrounds
		page_body = document.body;
		page_body.id = ('location-' + new_page_body_id);				
	}
	
	function generate_minimap_and_location_info(global_location_id)
	{		
		flash_minimap_holder = document.getElementById('flash');				
		global_interactive_href = ('/map.html?location=' + global_location_id);		
		
		if (flash_minimap_holder) // flash_minimap_holder not present on t2a and t3 templates
		{			
			var DL = document.createElement('dl');		
			
			var DT = document.createElement('dt');	
			var DT_bold = document.createElement('strong');		
			var DT_text = document.createTextNode(locations[global_location_id][0]);		
				DT_bold.appendChild(DT_text);		
				DT.appendChild(DT_bold);		
				
				if (locations[global_location_id][0] != '') // if there is district data...
				{
					DL.appendChild(DT);					
				}
				
			var	DD_1 = document.createElement('dd');
				DD_1.className = 'desc';					
			var DD_1_text_1 = document.createTextNode(locations[global_location_id][4]);
			var DD_1_divider = document.createTextNode(', ');		
			var DD_1_text_2 = document.createTextNode(locations[global_location_id][1]);		
			
				DD_1.appendChild(DD_1_text_1);
				
				if (locations[global_location_id][1] != '') // if there is district data...
				{
					if (locations[global_location_id][4] != '') // if there is description data...
					{
						DD_1.appendChild(DD_1_divider);
					}
					DD_1.appendChild(DD_1_text_2);							
				}
				
				if ((locations[global_location_id][1] != '') || (locations[global_location_id][4] != ''))
				{
					DL.appendChild(DD_1);
				}
	
			var	DD_2 = document.createElement('dd');		
				DD_2.setAttribute('id', 'flash-container');
				
				if (!global_flash_available)
				{
					DD_2.className = 'noflash';
				}				
				
				DL.appendChild(DD_2);
				
				// output element so that flash can be written into DD_2
				flash_minimap_holder.appendChild(DL);
				
				DD_2_el = document.getElementById('flash-container');
				generate_minimap_map();
				
				if (global_flash_available)
				{				
					DD_2_el.innerHTML = global_minimap_map;
				}
				else
				{
					DD_2_el.appendChild(global_minimap_map);
				}
				
				generate_minimap_link(); // populates global_minimap_map. DD_3.appendChild(generate_minimap_link()) didn't work, nor using eval()
			var DD_3 = document.createElement('dd');
				DD_3.className = 'nav vert';	
				DD_3.appendChild(global_minimap_link);
				DL.appendChild(DD_3);				
			
			var DD_4 = document.createElement('dd');
				DD_4.className = 'nav vert';			
			var DD_4_href = document.createElement('a');		
				DD_4_href.setAttribute('href', ('/locations-gallery/image.html?ref=' + locations[global_location_id][5] + '&i=0')); // ref = image reference number
				DD_4_href_text = document.createTextNode('View gallery image');
				DD_4_href.appendChild(DD_4_href_text);
				DD_4.appendChild(DD_4_href);			
				DL.appendChild(DD_4);		
				
				// Link also applied to search anchor (restyled to link thumbnail image to gallery) (DS | 291105)
				search_form_anchor = document.getElementById('searchform');
				search_form_anchor.setAttribute('href', ('/locations-gallery/image.html?ref=' + locations[global_location_id][5] + '&i=0'));						
				search_form_anchor.className = 'a';
		}
	}
	
	function generate_minimap_map()
	{
		var minimap_map;
		
		if (global_flash_available)
		{
			//	Generate flash movie
			//	width: is fixed at maximum display size (1152x864 on homepage) and overridden with 100% via the CSS
			//	flashvars added as getURL cannot return a value [180508]	
			
				minimap_map = '';
				minimap_map += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="230" height="227">';
				minimap_map += '<param name="movie" value="/resources/flash/location_map.swf" />';
				minimap_map += '<param name="flashvars" value="id=' + global_location_id + '&href=' + global_interactive_href + '&dmnid=' + dmnid + '" />\n';							
				minimap_map += '<param name="quality" value="high" />';
				minimap_map += '<param name="scale" value="noborder" />'; 					    
				minimap_map += '<embed src="/resources/flash/location_map.swf" flashvars="id=' + global_location_id + '&href=' + global_interactive_href + '&dmnid=' + dmnid + '" quality="high" scale="noborder" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="230" height="227"></embed>';
				minimap_map += '</object>';		
		}
		else
		{
				minimap_map = document.createElement('img');
				minimap_map_filename = ('content-' + global_location_id + '.gif');
				minimap_map_path = '/resources/images/content/noflash/';
				minimap_map.setAttribute('src', (minimap_map_path + minimap_map_filename));
				minimap_map.setAttribute('width', 123);
				minimap_map.setAttribute('height', 226);
				minimap_map.setAttribute('alt', 'Region Map. ');	
		}
		
		global_minimap_map = minimap_map;
	}
	
	function generate_minimap_link()
	{	
		if (global_flash_available)
		{		
			var interactive_link_text = 'View interactive maps. ';
		}
		else
		{		
			var interactive_link_text = 'View information about Regions, Film Offices and Films made in NZ. '
		}
		
		var	minimap_link = document.createElement('a');			
			minimap_link.setAttribute('href', global_interactive_href); // add script on interactive map page to jump to anchor if flash not present
			minimap_link_text = document.createTextNode(interactive_link_text);
			minimap_link.appendChild(minimap_link_text);
			
			global_minimap_link = minimap_link;
	}
	
	function add_print_to_page_tools()
	{
		var DIV = document.getElementById('page-tools');		
		var UL = DIV.getElementsByTagName('ul')[0];
		
		//	LI_1 = hardcoded back to top link
		
		var LI_2 = document.createElement('li');
			LI_2.className = 'print';
			
		var LI_2_href = document.createElement('a');		
		var LI_2_href_text = document.createTextNode('Print this page')			
			LI_2_href.setAttribute('href', 'javascript:print_page()');
			LI_2_href.appendChild(LI_2_href_text);
			
			LI_2.appendChild(LI_2_href); 

			UL.appendChild(LI_2);	// updated 281105 now actually in correct place!			
	}
	
	function generate_safari_note()
	{
		// 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)	
		// Chop shop version for safari detection ;) for location search freetext tab issue		
		
		var ua = navigator.userAgent.toLowerCase(); 		
		
		this.isSafari = (ua.indexOf('safari') != - 1); 
		
		if (this.isSafari) 
		{
			var P = document.createElement('p');
				P.className = 'note';
			var P_text = document.createTextNode('Note: After entering a keyword or keywords, hit TAB to update your search terms. ');
				P.appendChild(P_text);
			var freetext_fieldset = document.getElementById('search-by-phrase');
			
			if (freetext_fieldset)
			{
				// field only exists on location search (not results)
				freetext_fieldset.insertBefore(P, freetext_fieldset.getElementsByTagName('div')[0]);
			}
		}
	}	
	
	g_content_layer_string_id = 'maphelp'; // Interactive Map Help Text
	
	function print_page()
	{
		if (g_content_layer_string_id != 'maphelp')
		{
			// this function is used by all pringt links
			// but tab_h3.printable is only going to happen on the interactive map page
			var tab_h3 = document.getElementById(g_content_layer_string_id).getElementsByTagName('h3')[0];
			tab_h3.className = 'printable';
		}
		window.print();			
	}	
	
	// init during page load
	global_flash_version = detect_flash_version();
	
	if (global_flash_version >= global_required_flash_version)
	{			
		global_flash_available = true;							
	}
	else if (global_flash_version < global_required_flash_version)
	{		
		global_flash_available = false;			
	}
	
/* 
	Homepage functions
	Added 20.07.2009
*/

/*	
	browserdetect.js
	===============================================================
	Push Play 2008 - 	Browser Detection
	
	Created 20.05.2008 by DS	
	Last Updated: See SVN		
	_______________________________________________________________
*/	

//	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);
		this.isOmniweb     = (ua.indexOf('omniweb') != - 1);
		this.isOpera       = (ua.indexOf('opera') != -1);
		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.isIE4x = ((this.isIE) && (this.versionMajor == 4));		
		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);	
		this.isIE8x = (this.isIE && this.versionMajor == 8);	
		this.isIE8up = (this.isIE && this.versionMajor >= 8);		
		
		// detect ns version
		this.isNS6x = (this.isNS && this.versionMajor == 6);
	
		// detect opera version
		this.isOpera6 = ((this.isOpera) && (this.versionMajor <= 6));	
		
		this.isSafari2 = ((this.isSafari) && (this.versionMajor <= 419.3));
		
		// Supported browsers for Push Play 2008: IE6+, FF2+, Safari 2+	
		if ((this.isIE6up) || ((this.isSafari) && (this.versionMajor >= 412)) || ((this.isFirefox) && (this.versionMajor >=2)))
		{		
			this.isHiFi = true;					
		}	
		else
		{	
			this.isHiFi = false;						
		}
	}

	// init
	whichbrowser = new detectbrowser();

/*	
   @ match_panel_heights()
	 @ getPadding()
	 @ getStyle()
   ---------------------------------------------------------------
	 Match height of bottom panels on homepage.
	 
	 More info:
	 - /_documentation/updates.htm
	 - http://www.quirksmode.org/dom/getstyles.html
	 - http://www.howtocreate.co.uk/tutorials/javascript/domcss
	   (getComputedStyle and currentStyle are not supported by 
			Safari 2-, Konqueror 3.4- or Tkhtml Hv3)
   _______________________________________________________________
*/			

	function match_panel_heights()
	{		
		if (!whichbrowser.isSafari2)
		{
			var output = '';
			var panels = new Array();
			
			panels[0] = new Array();
			panels[0]['container'] = document.getElementById('intro');					
			panels[0]['body'] = new Array();
			panels[0]['body']['child'] = panels[0]['container'].getElementsByTagName('div')[0];			
			panels[0]['body']['child_outer_height'] = panels[0]['body']['child'].offsetHeight;				
			panels[0]['body']['child_pad_height'] = getPadding(panels[0]['body']['child'], 'v');				
			panels[0]['body']['child_inner_height'] = ( panels[0]['body']['child_outer_height'] - panels[0]['body']['child_pad_height'] );	
			
			panels[1] = new Array();
			panels[1]['el'] = document.getElementById('promos');					
			panels[1]['body'] = new Array();
			panels[1]['body']['child'] = panels[1]['el'].getElementsByTagName('div')[0];			
			panels[1]['body']['child_outer_height'] = panels[1]['body']['child'].offsetHeight;				
			panels[1]['body']['child_pad_height'] = getPadding(panels[1]['body']['child'], 'v');				
			panels[1]['body']['child_inner_height'] = ( panels[1]['body']['child_outer_height'] - panels[1]['body']['child_pad_height'] );						

			panels[2] = new Array();
			panels[2]['el'] = document.getElementById('promos');						
			panels[2]['body'] = new Array();																	
			panels[2]['body']['child'] = panels[2]['el'].getElementsByTagName('div')[1]; //alert( panels[2]['el'].getElementsByTagName('div')[1].className ); -- newsandupdates
			panels[2]['body']['child_outer_height'] = panels[2]['body']['child'].offsetHeight;				
			panels[2]['body']['child_pad_height'] = getPadding(panels[2]['body']['child'], 'v');						
			panels[2]['body']['child_inner_height'] = ( panels[2]['body']['child_outer_height'] - panels[2]['body']['child_pad_height'] );						
														
			// find out what the max height is
			var panel_max_height = 0;		
			for (var p=0; p<panels.length; p++)
			{
				//alert( panels[p]['body']['child_inner_height'] );
				
				if ( panels[p]['body']['child_outer_height'] > panel_max_height )
				{
					panel_max_height = panels[p]['body']['child_outer_height'];
					tallest_panel = p;
				}
			}				
					
			// set a min-height equal to the max height		
			
			for (var p=0; p<panels.length; p++)
			{					
				// calculate the new .panel .body height						
				// the nested div height must be increased by this amount, less any vertical padding on this element	
				
				// calculate the browser-dependent adjustment
				
				// default
				browser_panel_top_up = 0;
				
				// tallest panel is #0 or #2
				if ( (tallest_panel == 1) && (p != 1) )
				{
					browser_panel_top_up -= 3; // offset bottom margin of .feature li a (panel 1)									
				}
						
				if ( p == 0 )
				{
					if ((whichbrowser.isIE) && (whichbrowser.isIE6x || whichbrowser.isIE7up)) // ie7
					{
						browser_panel_top_up += 1;
					}
					else if (whichbrowser.isSafari) // s4
					{						
						browser_panel_top_up += 1;	
					}							
				}	
							
				/*
				if (whichbrowser.isFirefox) // ff2/3
				{		
					browser_panel_top_up -= 3;			
				}			
				else if ((whichbrowser.isIE) && (!whichbrowser.isIE7up)) // ie6
				{
					browser_panel_top_up -= 3;
				}
				else if ((whichbrowser.isIE) && (whichbrowser.isIE7up)) // ie7
				{
					browser_panel_top_up -= 2;
				}						
				else if (whichbrowser.isSafari) // s3, gc
				{						
					browser_panel_top_up -= 2;		
				}		
				*/

				// the reqd height_increase is the max height less the panel outer_height, with a browser-specific adjustment			
				panels[p]['body']['child_height_increase'] = ( panel_max_height - panels[p]['body']['child_outer_height'] + browser_panel_top_up );	
				
				// the new height will be applied to the inner div, so is the old inner_height - the pad_height + the height difference
				panels[p]['body']['child_new_height'] = ( panels[p]['body']['child_inner_height'] + panels[p]['body']['child_height_increase'] );	
				
				var newValue = ( panels[p]['body']['child_new_height'] + 'px' );
				
				// 'prop' the panel open by assigning a min-height to the .panel .body	
				if ((whichbrowser.isIE) && (!whichbrowser.isIE7up))
				{					
					// height for IE6
					panels[p]['body']['child'].style.height = newValue;
				}
				else
				{
					// min-height for everyone else					
					panels[p]['body']['child'].style.minHeight = newValue;		
				}							

				/*
				Test output
				output += '<ul style="background:white;">';
				output += '<li>Panel #' + p + ' (Panel #' + tallest_panel + 'is tallest @ ' + panel_max_height + 'px)</li>';
				output += '<li>child classname = ' + panels[p]['body']['child'].className + '</li>';
				output += '<li>child_inner_height = ' + panels[p]['body']['child_inner_height'] + '</li>';
				output += '<li>child_pad_height = ' + panels[p]['body']['child_pad_height'] + '</li>';
				output += '<li>child_height_increase = ' + panels[p]['body']['child_height_increase'] + '</li>';
				output += '<li>.' + panels[p]['body']['child'].className + '.style.minHeight = ' + ( panels[p]['body']['child_new_height'] ) + 'px' + '</li>';
				output += '</ul>';		
				*/				
			}
			
			// document.getElementById('main').innerHTML += output; // test output
		}
	}	
	
	function getPadding(el, type)
	{
		if ((whichbrowser.isIE) || (whichbrowser.isOpera))
		{
			// NOTE: IE6/7 cannot deal with padding set in em units, so the CSS contains this workaround for IE6/7: ems converted to px
			
			if (type == 'h')
			{			
				padding = (getStyle(el, 'paddingLeft') + getStyle(el, 'paddingRight'));
			}
			else if (type == 'v')
			{	
				padding = (getStyle(el, 'paddingTop') + getStyle(el, 'paddingBottom'));
			}			
		}
		else
		{
			if (type == 'h')
			{			
				padding = (getStyle(el, 'padding-left') + getStyle(el, 'padding-right'));
			}
			else if (type == 'v')
			{	
				padding = (getStyle(el, 'padding-top') + getStyle(el, 'padding-bottom'));
			}				
		}
	
		return padding;		
	}
	
	function getStyle(el,styleProp)
	{	
		var x = el;
		
		if (x.currentStyle)
		{
			var y = x.currentStyle[styleProp];
		}
		else if (window.getComputedStyle)
		{
			var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
		}
		return parseInt(y); // eg 13px -> 13
	}		

