var RecaptchaOptions = { 
	theme : 'blackglass', 
	tabindex : 2
};

var Cookie = {
	set: function(name, value, seconds) {
	  if(seconds) {
	    var d = new Date();
	    d.setTime(d.getTime() + (seconds * 1000));
	    var expiry = '; expires=' + d.toGMTString();
	  }
	  else {
	    var expiry = '';
	  }	
	  var returnIt = document.cookie = name + "=" + value + expiry + "; path=/";
	  return returnIt;
	},
	get: function(name){
	  var nameEQ = name + "=";
	  var ca = document.cookie.split(';');
	  for(var i = 0; i < ca.length; i++){
	    var c = ca[i];
	    while(c.charAt(0) == ' ')
	      c = c.substring(1,c.length);
	    if(c.indexOf(nameEQ) == 0) {
	      return c.substring(nameEQ.length,c.length);
	    }
	  }
	  return null;
	},
	unset: function(name){
	  Cookie.set(name,'',-1);
	}
};

var ClearHelper = Class.create({
	initialize: function(sEl) {
		this.els = $$(sEl);
		var clearer = "<div class='clear'></div>";
		for(var i = 0; i < this.els.length; i++) {
			this.els[i].insert({before: clearer});
		}
	}
});


/**
 * Adjust the navigation - add down arrow to inidicate drop down, center the the subnav, 
 * TODO: add hover to IE6
 **/
var NavHelper = Class.create({
	initialize: function(sEls) {
		this.els = $$(sEls);
		var isIE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
		//this.sfHover(sNav);
		for(var i = 0; i < this.els.length; i++) {
			var parent = this.els[i].up('li');
			var sibling = this.els[i].previous('a');
			parent.addClassName('has-child');
			var offset = -(this.els[i].getWidth() / 2) + (sibling.getWidth() / 2); // -(half of size of subnav) + (half of size of sibling)
			this.els[i].setStyle('margin-left: ' + offset + 'px');
			if(isIE6) {
				this.els[i].down('li').addClassName('first');
				this.sfHover(parent);
			}	
		}	
	},
	
	sfHover: function(el) {
		el.observe('mouseover', function(e) {
			el.addClassName('over');
		});
		el.observe('mouseout', function(e) {
			el.removeClassName('over');
		});	
	}	
});

var Intro = Class.create({
	initialize: function(sEl, sCopy, sTrigger) {
		this.el = $(sEl);
		this.el.setStyle("height: " + this.el.getHeight() + "px");
		this.copy = $(sCopy);
		this.createTrigger($(sTrigger));
	},
	
	createTrigger: function(el) {
		this.trigger = el.wrap('div', {'class': 'open'});
		this.trigger.setStyle('cursor: pointer');
		if(!$('display-intro')) {
			this.span = new Element('span', {'id': 'display-intro'});
			this.span.update('-');
			el.insert({before: this.span});
		}
		this.trigger.observe('click', this.__click.bindAsEventListener(this));
	},
	
	__click: function(e) {
		this.trigger.toggleClassName('open');
		if(this.trigger.hasClassName('open')) {
			this.span.update('-');
			this.copy.setStyle('display: block');
		}
		else {
			this.span.update('+');
			this.copy.setStyle('display: none');
		}
	}

});

document.observe('dom:loaded', function(e) {	
	var navhelper = new NavHelper('ul#nav li ul');
});