var current_section;
Event.observe(document, 'dom:loaded', function() {
	$$('#nav li a').each(function(x) {
		x.onmouseover = function() { $(this).up('li').addClassName('over'); }
		x.onmouseout = function() { $(this).up('li').removeClassName('over'); }
		x.onclick = function() {
			if (current_section == $(this)) {
				$$('#nav li a').each(function(x) {
					x.up('li').removeClassName('over');
					x.up('li').removeClassName('selected');
				});
				
				new Effect.SlideUp('cascading-nav', {
					duration: .5,
					afterFinish: function() {
						current_section = null;	
					}
				});
			} else {
				$$('#nav li a').each(function(x) {
					x.up('li').removeClassName('over');
					x.up('li').removeClassName('selected');
				});
				$(this).up('li').addClassName('selected');
				
				var section = $(this).up('li').identify();
				$$('#nav-callouts a').invoke('hide');
				$(section + '-callout').show();
				
				// show the content in the cascading nav
				$$('#cascading-nav .section').each(function(x) { x.hide(); });
				var section = $(this).up('li').identify().replace('nav-', '') + '-content';
				$(section).show();
				
				// animate the cascading box
				current_section = $(this);
				if (!$('cascading-nav').visible()) {
					new Effect.SlideDown('cascading-nav', {
						duration: .5
					});
				}
			}
						
			return false;
		}
	});

	if ($('inline-nav')) {	
		var selected = $$('#inline-nav ul li').detect(function(li) { return li.hasClassName('selected'); });
		// subtract 16 to account for the 10px right margin and half the width of the arrow
		$('inline-arrow').setStyle({ left: (selected.positionedOffset()[0] + (selected.getWidth() / 2) - 16) + 'px' }).show();
	}
});


function get_flash_movie(name) {
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? window[name] : document[name];
}

function extractParamFromUri(uri, paramName) {
  if (!uri) {
    return;
  }
  var uri = uri.split('#')[0];  // Remove anchor.
  var parts = uri.split('?');  // Check for query params.
  if (parts.length == 1) {
    return;
  }
  var query = decodeURI(parts[1]);

  // Find url param.
  paramName += '=';
  var params = query.split('&');
  for (var i = 0, param; param = params[i]; ++i) {
    if (param.indexOf(paramName) === 0) {
      return unescape(param.split('=')[1]);
    }
  }
}
