//-------------------------------------------------------
// Home page slides
//-------------------------------------------------------
var visible_slide = 1;
var rotation_timeout = null;
var SLIDE_DELAY = 5000;
var SLIDES_PAUSED = false;
function show_slide(slide_number) {
  if(SLIDES_PAUSED) return;
  if (slide_number == visible_slide) return;
  
  new Effect.Parallel([
    new Effect.Appear('homepage-slide-'+slide_number, {duration: 0.5, sync: true}),
    new Effect.Fade('homepage-slide-'+visible_slide, {duration: 0.5, sync: true})
  ], {queue:'end'});
  
  $('slide-selector-'+slide_number).addClassName('active');
  $('slide-selector-'+visible_slide).removeClassName('active');
  visible_slide = slide_number;
  rotate_slides();
}

function rotate_slides() {
  var next_slide = (visible_slide == 3 ? 1 : visible_slide + 1);
  if (rotation_timeout != null) clearTimeout(rotation_timeout);
  rotation_timeout = setTimeout('show_slide('+next_slide+')', SLIDE_DELAY);
}

function pause_slides(){
    if(SLIDES_PAUSED){
        SLIDES_PAUSED = false;
        $('play_pause').src = '/images/pause.gif'
        rotate_slides();
    } else {
        SLIDES_PAUSED = true;
        $('play_pause').src = '/images/play.gif'
    }
}

//-------------------------------------------------------
// Home page Logos
//-------------------------------------------------------

var visible_logo = 1;
var logo_timeout = null;
var LOGO_DELAY = 5000;

function fancy_show_logo(logo_number) {
  if (logo_number == visible_logo) return;
  
  new Effect.Parallel([
    new Effect.Appear('logo-'+logo_number, {duration: 0.5, sync: true}),
    new Effect.Fade('logo-'+visible_logo, {duration: 0.5, sync: true})
  ], {queue:'end'});
  
  visible_logo = logo_number;
  rotate_logos();
}

function fancy_rotate_logos() {
  var next_logo = (visible_logo == num_logos ? 1 : visible_logo + 1);
  if (logo_timeout != null) clearTimeout(logo_timeout);
  logo_timeout = setTimeout('fancy_show_logo('+next_logo+')', LOGO_DELAY);
}

Rotator = {
  index: -1,
  hold: 1000,
  fade: 250,
  framelength: 5500,
  rotate: function() {
    elements = $$('.logo_rotator .logo');
    
    if (this.index >= 0)
      this.index = (this.index + 1) % elements.length;
    else
      this.index = 0;
    
    this.nextIndex = (this.index + 1) % elements.length;
    
    $$('.logo_rotator .logo').each(function(e) { e.hide() });
    $$('.logo_rotator .logo')[this.index].show();
  },
  start: function() {
    document.observe("dom:loaded", function() {
      Rotator.rotate();

      window.setInterval(
        function() {
          Rotator.rotate();
        },
        Rotator.framelength
      );
    });
    
    this.cycleLength = this.hold + this.fade;
  }
}

// Drop down stuff

//Check if we're in IE 6
var agt				= navigator.userAgent.toLowerCase();
var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie6    = (is_ie && agt.indexOf("msie 6.")!=-1 );    

// Activate background image caching on IE6 to prevent image flicker
if (is_ie6) {
	document.execCommand('BackgroundImageCache', false, true);
}

sfHover = function() {
	var sfEls = document.getElementById("navigation").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}

if (window.attachEvent) window.attachEvent("onload", sfHover);

// get params from the URL
function getParams() {
	var params = new Object();
	var h = window.location.href;	
	var rs = h.split("?");
	if (rs[1]) {
		var s = rs[1];
		var nvs = s.split("&amp;");
		for (var i = 0; i < nvs.length; i++) {
			var nv = nvs[i].split("=");
			var pname = unescape(nv[0].split("+").join("%20"));
			var pvalue = unescape(nv[1].split("+").join("%20"));
			params[pname] = pvalue;
		}
	}
	return params;
}

function rotate_logos()
{
  if (is_ie)
    Rotator.start();
  else
    fancy_rotate_logos();
}
