function loadjscssfile(filename, filetype){
 if (filetype=="js"){ //if filename is a external JavaScript file
  var fileref=document.createElement('script')
  fileref.setAttribute("type","text/javascript")
  fileref.setAttribute("src", filename)
 }
 else if (filetype=="css"){ //if filename is an external CSS file
  var fileref=document.createElement("link")
  fileref.setAttribute("rel", "stylesheet")
  fileref.setAttribute("type", "text/css")
  fileref.setAttribute("href", filename)
 }
 if (typeof fileref!="undefined")
  document.getElementsByTagName("head")[0].appendChild(fileref)
}


function changeLinks(id, header_img_id){

		// for IE5.5/6
		// http://www.youngpup.net/projects/sleight/
		/*if(pngAlpha){alert('hi');
		var src = $(header_img_id).src;
		$(header_img_id).style.visibility = "hidden";
		

		var div = document.createElement("DIV");
			div.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizing='scale')"
			div.style.width = $(header_img_id).width + "px";
			div.style.height = $(header_img_id).height + "px";
			$(header_img_id).replaceNode(div);
		$(header_img_id).style.visibility = "visible";

		}*/
		
		//for multimedia page
		if(header_img_id == 'hd_multimedia'){
		
var so = new SWFObject("/exhibitions/horse/media/horse.swf", "horse1", "270", "245", "8", "#7A1A16;");
					so.addParam("quality", "high");
					so.addParam("play", "false");
					so.addParam("menu", "true");
					so.addParam("scale", "showall");
					so.write("horseinsideview");

  var so = new SWFObject("/exhibitions/horse/media/enduringpt1.swf", "horse2", "270", "245", "8", "#7A1A16;");
					so.addParam("quality", "high");
					so.addParam("play", "false");
					so.addParam("menu", "true");
					so.addParam("scale", "showall");
					so.write("enduring1");

   var so = new SWFObject("/exhibitions/horse/media/enduringpt2.swf", "horse3", "270", "245", "8", "#7A1A16;");
					so.addParam("quality", "high");
					so.addParam("play", "false");
					so.addParam("menu", "true");
					so.addParam("scale", "showall");
					so.write("enduring2");
   
   var so = new SWFObject("/exhibitions/horse/media/enduringpt3.swf", "horse4", "270", "245", "8", "#7A1A16;");
					so.addParam("quality", "high");
					so.addParam("play", "false");
					so.addParam("menu", "true");
					so.addParam("scale", "showall");
					so.write("enduring3"); 
		
	}
		//temporarily disabled until work out IE6 issues
		if(document.getElementById("pngType").value != 'pngAlpha11111'){
		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
				
			/*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')
				//can use Builder to add a node here?? 
				{
				
					alist[x].onmouseover=function(){
				
						imgOn('button_back','.png');
					
					}
				
					alist[x].onmouseout=function(){
				
						imgOff('button_back','.png');
					
					}
				
				}
				
				if(alist[x].className == 'nextbutton')
				{
				
					alist[x].onmouseover=function(){
				
						imgOn('button_next','.png');
					
					}
					
					alist[x].onmouseout=function(){
				
						imgOff('button_next','.png');
						
					}
				
				}
				
		}//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){
	
	document.body.style.cursor = 'progress';
	var css = section;
	
	if(page){
	
		if(IsNumeric(page)){
		
	
			var url = '/exhibitions/horse/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/horse/includes/pages/content/' + page + '.php?section=' + section;
		
		}
		
	
	}else{
		
		var url = '/exhibitions/horse/includes/pages/content/' + section + '.php?section=' + section;
		page = section;
		css = 'util';
		
	}
	//alert(css);
	

	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: false, onSuccess: fadeOutIn(section, page, 'innercontent', css)});
    	
		}//end if the clicked link doesn't lead to this same page
}//end function: browse


function fadeOutIn(section, page, div_id, css) {

	new Effect.Opacity
				(div_id, {to: 0.0, from: 1.0, duration: 0.6, beforeStart: function() {
				
				//if(pngAlpha){alert('sofarsoogood');}
				},
				afterFinish: function()
					{	
					
									if(pngAlpha){//alert('pngAlphy');
									}else{

						loadjscssfile('/exhibitions/horse/css/' + css + '_.css', 'css');
}

						document.getElementById("sessionSection").value = section;
					  document.getElementById("sessionPage").value = page;
											

					
						
						var header_img_id = 'hd_' + section;
						
						if(IsNumeric(page)){
		
							header_img_id = 'hd_gallery';
		
						}
						
						if(!IsNumeric(page) && page != section){
		
							header_img_id = 'hd_' + page;
							
						}



						if(!$(header_img_id)){ 






										
							window.location = "/exhibitions/horse/?section=" + section + "&page=" + page;
						
						}else{
						
							$(div_id).innerHTML = $('standby').innerHTML;
							
							
								
							
								changeLinks(div_id, header_img_id);	
								
								
								
								new Effect.Opacity(div_id,{to: 1.0, from: 0.0, duration: 0.4, afterFinish: function (){
							
									//GOOGLE TRACKER
									pageTracker._trackPageview("/exhibitions/horse/?section=" + section + "&page=" + page); 
									document.body.style.cursor = 'default';
									
								//loadjscssfile('/exhibitions/horse/css/util.css', 'css');
				
								/*document.getElementById("shd").style.visibility = "hidden";
								if(
								document.getElementById("shd").name != "hd_" + section){
								
									document.getElementById("shd").src = "/exhibitions/horse/graphics/hd_" + section + ".png";
									document.getElementById("shd").name = "hd_" + section;
								
								}*/
								
								}
								
								});				
  						
							
						}
  				}
  			});
}//end function

function imgOn(id, extension) {
	if(!pngAlpha){
	document.getElementById(id).src = '/exhibitions/horse/graphics/' + id + '_over' + extension;}
}

function imgOff(id, extension) {
if(!pngAlpha){	document.getElementById(id).src = '/exhibitions/horse/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'));

}

// 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;
}
