function changeLinks(id){

		if(Effect.Opacity && Ajax.Updater){
		
		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(this.getAttribute("rev")){
					
						alist[x].onclick=function(){browse(this.getAttribute("rel"), this.getAttribute("rev"));}//end onclick
					
					}//end if has rev
				
				}//end if has rel attr
				
			if(alist[x].className == 'pulse')
				{
					(alist[x]).onmouseover=function(){

						new Effect.Pulsate(this,{duration:2, from:.4, to:1, pulses:3});									
					
					}
				}
				
				if(alist[x].className == 'backbutton')
				{
				
					alist[x].onmouseover=function(){
				
						imgOn('button_back','.gif');
					
					}
				
					alist[x].onmouseout=function(){
				
						imgOff('button_back','.gif');
					
					}
				
				}
				
				if(alist[x].className == 'nextbutton')
				{
				
					alist[x].onmouseover=function(){
				
						imgOn('button_next','.gif');
					
					}
					
					alist[x].onmouseout=function(){
				
						imgOff('button_next','.gif');
						
					}
				
				}
				

		}//end inner for loop
		
	}//end if browse function supported
	
}//end function

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){
	//alert($('status').innerHTML);
if(page){
	
		if(IsNumeric(page)){
		
	
			var url = '/exhibitions/photo/saturn/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/photo/saturn/includes/pages/content/' + page + '.php?section=' + section;
		
		}
		
	
	}else{
	
		var url = '/exhibitions/photo/saturn/includes/pages/content/' + section + '.php';
		page = section;
		
	}
	
	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: true, evalScripts: true, onSuccess: fadeOutIn(section, page, 'innercontent')});
    	
    	
		}//end if the clicked link doesn't lead to this same page
}//end function: browse

function fadeOutIn(section, page, div_id) {

	if(section == "overview"){
		
		$('innercontentwrapper').morph('margin-top: 300px;');
		$('xbanner').morph('opacity: 0.0', {duration:0.2}); 
		$('hd_background_a').morph('opacity: 0.0', {duration:0.01}); 
		//new Effect.Opacity('hd_background_a', {duration:0.1, from:1.0, to:0.0});
	
	}else if(document.getElementById("hd_background_a").style.opacity != 1 && document.getElementById("innercontentwrapper").style.marginTop != "0px"){
				
		$('innercontentwrapper').morph('margin-top: 0px;', {
			afterFinish: function() {
				$('hd_background_a').morph('opacity: 1.0', {duration: 0.4}); 
				//new Effect.Opacity('hd_background_a', {duration:0.5, from:0.0, to:1.0});
				}
			});
		//$('hd_background_a').morph('opacity: 1.0', {duration: 3});
		$('xbanner').morph('opacity: 1.0'); 
		
	}
	
	new Effect.Opacity
				(div_id, {to: 0.0, from: 1.0, duration: 0.4, afterFinish: function()
					{	
					
						//setCookie('page', page, 1);
						//setCookie('amnh_detects_modern_browser', 1, 1);
						document.getElementById("sessionSection").value = section;
					  document.getElementById("sessionPage").value = page;
					
						if(IsNumeric(page)){
		
							var header_img_id = 'hd_gallery';
		
						}else{
		
							var header_img_id = 'hd_' + page;
							
						}
					
						if(!$(header_img_id)){ 
							
							//alert('asynch fail');					
							window.location = "/exhibitions/photo/saturn/?section=" + section + "&page=" + page;
						
						}else{
						
							$(div_id).innerHTML = $('standby').innerHTML;
							
								changeLinks(div_id);	
								new Effect.Opacity(div_id,{to: 1.0, from: 0.0, duration: 0.4});				
  						
							
						}
  				}
  			});
}//end function

function imgOn(id, extension) {
//alert(id);
	document.getElementById(id).src = '/exhibitions/photo/saturn/graphics/' + id + '_over' + extension;

}

function imgOff(id, extension) {

	document.getElementById(id).src = '/exhibitions/photo/saturn/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'));

}
