//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);


//Rotates the main homepage image
var HomeSlideshow = 
{
	contentarray: [],
	imagenum: 0,
	topticksone: '',
	toptickstwo: '',
	bottomticksone: '',
	bottomtickstwo: '',	
	shortdur: '40.0',
	longdur: '80.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]);
		
		HomeSlideshow.topticksone = $('topticksone');
		HomeSlideshow.toptickstwo = $('toptickstwo');
		HomeSlideshow.bottomticksone = $('bottomticksone');
		HomeSlideshow.bottomtickstwo = $('bottomtickstwo');
		
		new Effect.Move(HomeSlideshow.topticksone, { x: -780, y: 0, mode: 'relative', transition: Effect.Transitions.linear, duration: HomeSlideshow.shortdur, afterFinish: HomeSlideshow.resetTicks.bindAsEventListener(HomeSlideshow.topticksone) });
		new Effect.Move(HomeSlideshow.toptickstwo, { x: -1560, y: 0, mode: 'relative', transition: Effect.Transitions.linear, duration: HomeSlideshow.longdur, afterFinish: HomeSlideshow.resetTicks.bindAsEventListener(HomeSlideshow.toptickstwo) });
		
		new Effect.Move(HomeSlideshow.bottomticksone, { x: 780, y: 0, mode: 'relative', transition: Effect.Transitions.linear, duration: HomeSlideshow.shortdur, afterFinish: HomeSlideshow.resetTicks.bindAsEventListener(HomeSlideshow.bottomticksone) });
		new Effect.Move(HomeSlideshow.bottomtickstwo, { x: 1560, y: 0, mode: 'relative', transition: Effect.Transitions.linear, duration: HomeSlideshow.longdur, afterFinish: HomeSlideshow.resetTicks.bindAsEventListener(HomeSlideshow.bottomtickstwo) });
	},
	
	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);
	},
	
	resetTicks: function(event)
	{
		if (this.getStyle('top') == '10px') { //If it's a top tick
			this.setStyle({left: '780px'});	
			new Effect.Move(this, { x: -1560, y: 0, mode: 'relative', transition: Effect.Transitions.linear, duration: HomeSlideshow.longdur, afterFinish: HomeSlideshow.resetTicks.bindAsEventListener(this) });
			
		} else {
			this.setStyle({left: '-780px'});	
			new Effect.Move(this, { x: 1560, y: 0, mode: 'relative', transition: Effect.Transitions.linear, duration: HomeSlideshow.longdur, afterFinish: HomeSlideshow.resetTicks.bindAsEventListener(this) });
			
		}
	}
}


//Object to control sidebar slider element
var HomepageButtons  = 
{
	init: function() 
	{
		Event.observe($('leftbutton'), 'mouseover', HomepageButtons.toggleLeft);
		Event.observe($('leftbutton'), 'mouseout', HomepageButtons.toggleLeft);
		Event.observe($('rightbutton'), 'mouseover', HomepageButtons.toggleRight);
		Event.observe($('rightbutton'), 'mouseout', HomepageButtons.toggleRight);
	},
	
	toggleLeft: function() 
	{
		$('leftbutton').toggleClassName('active');
	},
	
	toggleRight: function() 
	{
		$('rightbutton').toggleClassName('active');
	}
	
}
Event.observe(window, 'load', HomepageButtons.init);


//Object to control three main site section elements
var Sectionnav  = 
{
	currentpage: '',
	opera: '',
	
	init: function() 
	{
		//Disable the sliding drawers in Opera
		if (typeof window.opera != 'undefined') {
			Sectionnav.opera = true;
		} else {
			//We only need to setup the listeners for non-Opera browsers
			var c = $('chartermainlink');
			var cb = $('chartermainbox');
			Event.observe(c, 'mouseover', Sectionnav.scaleUp.bindAsEventListener(cb));
			Event.observe(c, 'mouseout', Sectionnav.scaleDown.bindAsEventListener(cb));
		
			var s = $('salesmainlink');
			var sb = $('salesmainbox');
			Event.observe(s, 'mouseover', Sectionnav.scaleUp.bindAsEventListener(sb));
			Event.observe(s, 'mouseout', Sectionnav.scaleDown.bindAsEventListener(sb));
	
			var m = $('managementmainlink');
			var mb = $('managementmainbox');
			Event.observe(m, 'mouseover', Sectionnav.scaleUp.bindAsEventListener(mb));
			Event.observe(m, 'mouseout', Sectionnav.scaleDown.bindAsEventListener(mb));
		}
	},
	
	scaleUp: function(event) {
		new Effect.Move(this, { duration: 0.7, x: 0, y: 0, mode: 'absolute' });
	},
	
	scaleDown: function(event) {
		new Effect.Move(this, { duration: 0.7, x: 0, y: 82, mode: 'absolute' });
	}
}
Event.observe(window, 'load', Sectionnav.init);
