//Tell Netscape users to get a new browser
var BrowserSniff = 
{
	init: function()
	{
		var b = navigator.userAgent.toLowerCase();
		
		if (b.indexOf("netscape") != -1 || BrowserSniff.identifyBrowser() == false) 
		{
			alert ('Please upgrade to a more modern browser to view this site.');
		}
	},
	
	identifyBrowser: function() 
	{
		var agent = navigator.userAgent.toLowerCase();

  		if (typeof navigator.vendor != "undefined" && navigator.vendor == "KDE" && typeof window.sidebar != "undefined") {
    		return "kde";
  		
  		} else if (typeof window.opera != "undefined") {
  			var version = parseFloat(agent.replace(/.*opera[\/ ]([^ $]+).*/, "$1"));

    		if (version >= 7) {
      			return "opera7";
    		} else if (version >= 5) {
    	    	return "opera5";
   			}
    		
    		return false;
  		
  		} else if (typeof document.all != "undefined") {
    		if (typeof document.getElementById != "undefined") {
    		    var browser = agent.replace(/.*ms(ie[\/ ][^ $]+).*/, "$1").replace(/ /, "");

      			if (typeof document.uniqueID != "undefined") {
        			if (browser.indexOf("5.5") != -1) {
          				return browser.replace(/(.*5\.5).*/, "$1");
        			} else {
          				return browser.replace(/(.*)\..*/, "$1");
        			}
      			} else {
        			return "ie5mac";
      			}
    		}

    		return false;
  
  		} else if (typeof document.getElementById != "undefined") {
    		if (navigator.vendor.indexOf("Apple Computer, Inc.") != -1) {
      			if (typeof window.XMLHttpRequest != "undefined") {
        			return "safari1.2";
      			}

      			return "safari1";
    		} else if (agent.indexOf("gecko") != -1) {
      			return "mozilla";
    		}
  		}
  		
  		return false;
	}
}
Event.observe(window, 'load', BrowserSniff.init);

//To control the "current page" styles for the nav
var Highlight = 
{
	curpage: '',
	
	init: function()
	{	
		if ($('outercontainer')) {
			$('outercontainer').addClassName(Highlight.curpage);
		}	
	}
}


//Functions to control external links
var ExternalLinks = 
{
	init: function() 
	{
		var extLinks = $$('a.external');
		
		for (i=0; i<extLinks.length; i++)
		{
			Event.observe(extLinks[i], 'click', ExternalLinks.openNew.bindAsEventListener(extLinks[i]));	
		}
	},
	
	openNew: function(event) 
	{
		open(this.href);
		Event.stop(event);
	}
}
Event.observe(window, 'load', ExternalLinks.init);

//Functions to square up the columns
var EvenColumns = 
{
	init: function() 
	{
		var lheight = $('content').getHeight();
		var rheight = $('secondarycontent').getHeight();
		
		if (rheight > lheight)
		{
			if ($('outercontainer').hasClassName('home')) {
				var newheight = rheight - 210;
			} else {
				var newheight = rheight + 50;
			}
			$('content').setStyle({height: newheight+'px'}) 	
		}
	}

} 
Event.observe(window, 'load', EvenColumns.init);

//Functions to make sure the logo prints
var PrintLogo =
{
	init: function()
	{
		var logoimg = new Element('img', { 'class': 'logo', 'src': '/img/logo.gif' });
		var parentdiv = $('header');
		parentdiv.appendChild(logoimg);
	}
}
Event.observe(window, 'load', PrintLogo.init);


//Rotates the main homepage image
var HomeSlideshow = 
{
	contentarray: [],
	imagenum: 0,
	
	init: function() 
	{
		$('slideshow').update(HomeSlideshow.contentarray[HomeSlideshow.imagenum]);
		
		window.setTimeout(HomeSlideshow.fadeOut, 4000);
		var nextimagenum = HomeSlideshow.imagenum+1;
		$('bigslideshow-preload').update(HomeSlideshow.contentarray[nextimagenum]);
	},
	
	rotateContent: function()
	{
		HomeSlideshow.imagenum++;
		if (HomeSlideshow.imagenum >= HomeSlideshow.contentarray.length) { //Reset the counter if needed
			HomeSlideshow.imagenum = 0;
		}
		$('slideshow').update(HomeSlideshow.contentarray[HomeSlideshow.imagenum]);
		new Effect.Opacity('slideshow', { from: 0, to: 1, duration: 0.8 });
		
		var nextimagenum = HomeSlideshow.imagenum+1;
		$('bigslideshow-preload').update(HomeSlideshow.contentarray[nextimagenum]);
        window.setTimeout(HomeSlideshow.fadeOut, 5000);
		
	},
	
	fadeOut: function()
	{
		new Effect.Opacity('slideshow', { from: 1, to: 0, duration: 1.0 });
		window.setTimeout(HomeSlideshow.rotateContent, 1000);
	}
}
