// Effect.Transitions.easeInOutCubic=function(pos){if((pos/=0.5)<1)return 0.5*Math.pow(pos,3);return 0.5*(Math.pow((pos-2),3)+2);}

document.observe("dom:loaded", function() { 
	// Set main navigation element behaviour
	$('nav').select('li').each(function(element)
	{
		// Where element has children
		if(element.down('div'))
		{
			// Where element has been selected, display children
			if(element.hasClassName('on')) element.down('div').show();
			
			// Add behaviours
			element.down('a').observe('click', function(e)
			{
				// Cancel native event
				e.stop();
				
				// Alias relevant elements
				var current = e.target.up('li');
				
				// Where the current element is not selected
				if(!current.hasClassName('on'))
				{
					// Loop over siblings
					current.siblings().each(function(sibling)
					{
						// Where sibling is selected
						if(sibling.hasClassName('on'))
						{
							// Where the sibling has children or grandchildren, hide them
							sibling.select('div').each(function(descendant) {descendant.slideUp({duration:0.5});});
							// Remove on states
							sibling.removeClassName('on');
							sibling.select('li').each(function(descendant) {descendant.removeClassName('on');});
						}
					});
					// Add 'on' state to current
					current.addClassName('on');
					// Display children
					current.down('div').slideDown({duration:0.5});
				}
			});
		}
	});
  
  // browser hackage
  //-------------------------------------------------------
  if (Prototype.Browser.IE) {
    if (parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5)) == 6) {
      $$('body').each(function(e){ e.addClassName('ie6'); });
      $$('#nav .on, #nav .on+li').each(function(e){ e.setStyle({'border':'none'}); });
    }else if(parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5)) == 7){
      $$('body').each(function(e){ e.addClassName('ie7'); });
    };
  };
  
  // homepage partner slideshow
  //-------------------------------------------------------
	if($('partner-scroller'))
	{
		var partnerScroller = new Scroller('partner-scroller', {delay:2, slide_width:170});
	}
	//-------------------------------------------------------
  
  if ($$('a[href$="pdf"]')) {
    $$('a[href$="pdf"]').each(function(e) {
      if(!e.hasClassName('skip')) e.addClassName('pdf');
			e.observe('click', function(event) {
        window.open(e.href);
        Event.stop(event);
      });
    });
  };
  
  if ($$('a[href^="http"]')) {
    $$('a[href^="http"]').each(function(e) {
      e.addClassName('external');
    });
  };
  
  if ($('q')) {
    $('q').observe('focus', function(event) {
      this.up().addClassName('focus');
    }).observe('blur', function(event) {
      this.up().removeClassName('focus');
    });
  };
  
});

// email to a friend
Event.observe(document, 'dom:loaded', function()
{
	if($('sharing')) {
		try {
			$('sharing').down('li a.email').observe('click', function(event)
			{
				event.stop();
				
				var width  = 580;
				var height = 630;
				
				newwin = window.open(this.href, "emailafriend", "status=no,toolbar=no,resizable=yes,scrollbars=1,width="+width+",height="+height);
				if (window.focus) { newwin.focus(); }
			});
			$('sharing').down('li a.print').observe('click', function(event)
			{
        event.stop();
        window.print();
			});
		} catch(e) { if(console) console.log(e); }
	}
});

// Email protection
function u(a){var b=[],i=ac=c=c1=c2=0;while(i<a.length){c=a.charCodeAt(i);if(c<128){b[ac++]=String.fromCharCode(c);i++}else if((c>191)&&(c<224)){c2=a.charCodeAt(i+1);b[ac++]=String.fromCharCode(((c&31)<<6)|(c2&63));i+=2}else{c2=a.charCodeAt(i+1);c3=a.charCodeAt(i+2);b[ac++]=String.fromCharCode(((c&15)<<12)|((c2&63)<<6)|(c3&63));i+=3}}return b.join('')}function d(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";var c,o2,o3,h1,h2,h3,h4,bits,i=ac=0,dec="",tmp_arr=[];do{h1=b.indexOf(a.charAt(i++));h2=b.indexOf(a.charAt(i++));h3=b.indexOf(a.charAt(i++));h4=b.indexOf(a.charAt(i++));bits=h1<<18|h2<<12|h3<<6|h4;c=bits>>16&0xff;o2=bits>>8&0xff;o3=bits&0xff;if(h3==64){tmp_arr[ac++]=String.fromCharCode(c)}else if(h4==64){tmp_arr[ac++]=String.fromCharCode(c,o2)}else{tmp_arr[ac++]=String.fromCharCode(c,o2,o3)}}while(i<a.length);dec=tmp_arr.join('');dec=u(dec);return dec}function e(a){a=a.replace('--','==');a=a.replace('-','=');a=d(r(a));window.location=r('znvygb')+':'+a}function ri(){var a=new Array();var s="abcdefghijklmnopqrstuvwxyz";for(i=0;i<s.length;i++)a[s.charAt(i)]=s.charAt((i+13)%26);for(i=0;i<s.length;i++)a[s.charAt(i).toUpperCase()]=s.charAt((i+13)%26).toUpperCase();return a}function r(a){if(typeof rmap=='undefined')rmap=ri();s="";for(i=0;i<a.length;i++){var b=a.charAt(i);s+=(b>='A'&&b<='Z'||b>='a'&&b<='z'?rmap[b]:b)}return s}
