function changeLinks(id){

		//next and back buttons
		/*document.getElementById("button_back").onmouseover = function(){imgOn('button_back','.jpg');};
	
		document.getElementById("button_back").onmouseout = function(){imgOff('button_back','.jpg');};
	
		document.getElementById("button_next").onmouseover = function(){imgOn('button_next','.jpg');};
		
		document.getElementById("button_next").onmouseout = function(){imgOff('button_next','.jpg');};*/
	
		/*
		 This is the section just for the next and back buttons for inner pages.
		Start
		*/
		var divobj=$(id);
		
		var alist=divobj.getElementsByTagName("a"); //array containing the A elements within DIV
	
		for (var x=0; x<alist.length; x++){ //loop through each A element

				if(alist[x].getAttribute("rel") && alist[x].getAttribute("rel").substring(0,5) != "light" && alist[x].getAttribute("rel") != ""){
				
					alist[x].setAttribute("href", "#"); //replace URL with #
				
					alist[x].onclick=function(){
					
						browse(this.getAttribute("rel"), false);
						
					}//end onclick
				
					if(alist[x].getAttribute("rev")){
					
						alist[x].onclick=function(){browse(this.getAttribute("rel"), this.getAttribute("rev"));}//end onclick
					
					}//end if has rev
				
				}//end if has rel attr
				
		}//end inner for loop
	
	//}//end if browse function supported
		
}//end function

		/*
		 This is the section just for the next and back buttons for inner pages.
		End
		*/

function IsNumeric(sText)

{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }


function browse(section,page,xargs){  // SG|extra xargs for map/index initialization
	
		//if(document.getElementById("sessionSection").innerHTML != section){
		
			/*alert(document.getElementById("sessionSection").innerHTML);
		
			alert(section + ' ' + page);
			*/
			var prev = document.getElementById("navSection").innerHTML;
			var prev_page = document.getElementById("sessionPage").innerHTML;
			
			if($('a_' + prev_page)){Element.removeClassName('a_' + prev_page, 'selected');}
			
			if($('a_' + page)){Element.addClassName('a_' + page, 'selected');}
			
			//if($('div_' + section + '_body').style.display == 'none'
			//if(Element.hasClassName('a_' + section, 'invisible')) {	Element.removeClassName('a_' + section, 'invisible');		
			Element.addClassName('a_' + prev + 'invisible');
			
			if($('ad_' + section)){
			
			if($('div_' + $('ad_' + section).getAttribute('rel') + '_body')){ document.getElementById('navSection').innerHTML = section; 
			if(!document.getElementById('div_' + prev + '_body') && $('div_' + section + '_body').style.display == 'none'){new Effect.BlindDown('div_' + section + '_body', {duration: 0.9}); }
			else{if(prev != section) new Effect.Parallel( [ new Effect.BlindDown('div_' + section + '_body', {sync: true}), new Effect.BlindUp('div_' + prev + '_body', {sync: true}) ],{duration: 0.9});									}	}
			
			//new Effect.BlindDown('div_' + section + '_body');
		}
	
		document.getElementById("sessionSection").innerHTML = section;
		document.getElementById("sessionPage").innerHTML = page;								
	
		if(page.length>0 && IsNumeric(page)){//gallery   SG|20090122: turns out, IsNumeric("")==true
			var url = '/exhibitions/climatechange/includes/pages/content/' + section + '.php?page=' + page;}
		else{if($('div_' + document.getElementById("section").innerHTML + '_body'))
			{
			var li_list=$('div_' + document.getElementById("section").innerHTML + '_body').getElementsByTagName("li") //array containing the LI elements within the previous section UL
				for (var x=0; x<li_list.length; x++){ //loop through each LI element

					Element.removeClassName(li_list[x].getAttributeNode("id").value, 'selected');
					Element.addClassName(li_list[x].getAttributeNode("id").value, 'unselected');
						
				}//end turning off previous 
			
			}//end if 
			
			Element.removeClassName($('li_' + page), 'unselected');
			Element.addClassName($('li_' + page), 'selected');
			
			var url = '/exhibitions/climatechange/includes/pages/content/' + section + '/' + page + '.php?newpage=' + page; //alert(url);
		}

	if(url != document.getElementById('status').innerHTML)
		{
			document.getElementById('status').innerHTML = url;
			/*need code to handle nav tracking*/
			new Ajax.Updater('standby', url, {method:'get', asynchronous: false, evalScripts: false, onSuccess: fadeOutIn(section, page, 'innercontent', xargs)});  // SG|passing xargs along
    	
		}//end if the clicked link doesn't lead to this same page
}//end function: browse


function fadeOutIn(section, page, div_id, xargs){  // SG|extra xargs for map/index initialization

	new Effect.Opacity
				(div_id, {to: 0.0, from: 1.0, duration: 0.4, afterFinish: function()
					{	

						var header_img_id = 'hd_' + page;
						
						if(page.length>0 && IsNumeric(page)){  //  SG|20090122: turns out, IsNumeric("")==true
		
							header_img_id = 'hd_gallery';
		
						}
						
						if(!$(header_img_id)){ 
							
							//alert(header_img_id);
							window.location = "/exhibitions/climatechange/?section=" + section + "&page=" + page;

							// SG|index...1 line
							initializeIndex(section,page,xargs);
							//  ...end|SG						
						}else{
						
							$(div_id).innerHTML = $('standby').innerHTML;
							
								//GOOGLE TRACKER
							
							
								//changeLinks(div_id, header_img_id);	
								changeLinks(div_id);	

								// SG|index...2 lines
								jQuery('#standby').empty();  // having duplicate IDs confuses everything...
								initializeIndex(section,page,xargs);
								// ... end|SG
								
								//new Effect.Opacity(div_id,{to: 1.0, from: 0.0, duration: 0.4, afterFinish: pageTracker._trackPageview("/exhibitions/climatechange/?section=" + section + "&page=" + page)});				
								new Effect.Opacity(div_id,{to: 1.0, from: 0.0, duration: 0.4});				
							
						}
  				}
  			});
}//end function

function imgOn(id, extension) {
	if(!pngAlpha){
	document.getElementById(id).src = '/exhibitions/climatechange/graphics/' + id + '_over' + extension;}
}

function imgOff(id, extension) {
if(!pngAlpha){	document.getElementById(id).src = '/exhibitions/climatechange/graphics/' + id + extension;}
}
   
      function setCookie(name,value,days) {
   
       if (days) {
   
         var date = new Date();
   
         date.setTime(date.getTime()+(days*24*60*60*1000));
   
         var expires = ";expires="+date.toGMTString();
   
       } else {
   
         expires = "";
   
       }
   
       document.cookie = name+"="+value+expires+";path=/";
  
      }
  
       
  
      function readCookie(name) {
  
       var needle = name + "=";
  
       var cookieArray = document.cookie.split(';');
  
       for(var i=0;i <cookieArray.length;i++) {
  
         var pair = cookieArray[i];
  
         while (pair.charAt(0)==' ') {
  
           pair = pair.substring(1, pair.length);
  
         }
  
         if (pair.indexOf(needle) == 0) {
  
           return pair.substring(needle.length, pair.length);
  
         }
  
       }
  
       return null;
  
      }
      
function returnVisit(){

	alert(readCookie('section'));

}
// SG|index: new function startIndex
//    checks to make sure that the datafiles are loaded, then proceeds to initializeIndex
function startIndex(s) {
	if (!JSONloaded) {
		var jtime = setInterval(function(){startIndex(s); clearInterval(jtime);},1000);
	} else {
		initializeIndex(s);
	}
}

// SG|index:  new function initializeIndex
//   this looks at the section s and does index initialization accordingly; functions are in exfunctions.js
function initializeIndex(s,p,x) {
	switch(s) {
		case "exindex":
			indexinit(x);    // function defined in exfunctions.js
			break;
		case "exmap":
			mapinit(x);		// function defined in exfunctions.js
			break;
		default:
			highlightPageTopics(s,p);   // function defined in exfunctions.js
			break;
	}
}
//  ...end|SG

// 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)


function BrowserDetect() {
   var ua = navigator.userAgent.toLowerCase(); 

   // browser engine name
   this.isGecko       = (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);
   this.isAppleWebKit = (ua.indexOf('applewebkit') != -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 || ua.indexOf('firebird/') != -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);
   
   // specific browser shortcuts
   this.isNS4x = (this.isNS && this.versionMajor == 4);
   this.isNS40x = (this.isNS4x && this.versionMinor < 4.5);
   this.isNS47x = (this.isNS4x && this.versionMinor >= 4.7);
   this.isNS4up = (this.isNS && this.versionMinor >= 4);
   this.isNS6x = (this.isNS && this.versionMajor == 6);
   this.isNS6up = (this.isNS && this.versionMajor >= 6);
   this.isNS7x = (this.isNS && this.versionMajor == 7);
   this.isNS7up = (this.isNS && this.versionMajor >= 7);
   
   this.isIE4x = (this.isIE && this.versionMajor == 4);
   this.isIE4up = (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.isIE4xMac = (this.isIE4x && this.isMac);
}
var browser = new BrowserDetect();

// if IE5.5+, IE6 on Win32, then display PNGs with AlphaImageLoader
if ((browser.isIE55 || browser.isIE6x) && browser.isWin32) {
	var pngAlpha = true;
// else, if the browser can display PNGs normally, then do that
} else if ((browser.isGecko) || (browser.isIE5up && browser.isMac) || (browser.isOpera && browser.isWin	&& browser.versionMajor >= 6) || (browser.isOpera && browser.isUnix && browser.versionMajor >= 6) || (browser.isOpera && browser.isMac	&& browser.versionMajor >= 5) || (browser.isOmniweb && browser.versionMinor >= 3.1) || (browser.isIE6up) || (browser.isIcab && browser.versionMinor >= 1.9) || (browser.isWebtv) || (browser.isSafari) || (browser.isDreamcast)) {
	var pngNormal = true;
}

