function _() {
}

function show_section( section ) {
  Effect.BlindDown(section, {duration: 0.5});
  section_id = $(section).id;
  setTimeout("$('" + section_id + "_show_link').style.display = 'none';" +
             "$('" + section_id + "_hide_link').style.display = 'inline';",   500);
}
function hide_section( section ) {
  Effect.BlindUp(section, {duration: 0.5});
  section_id = $(section).id;
  setTimeout("$('" + section_id + "_show_link').style.display = 'inline';" +
             "$('" + section_id + "_hide_link').style.display = 'none';",     500);
}

function add_todo(text) {
  var li = document.createElement('li');
  li.innerHTML = text;
  $('todo_list').appendChild(li);
}

function add_or_remove_class_name( element, class_name, condition ) {
  if( condition ) { Element.classNames( element ).add(    class_name ); }
  else {            Element.classNames( element ).remove( class_name ); }
}


var redecorationRules = {
	'#main_content a' : function(element) {
		if( /^(http|https):/i.test(element.href) && element.href.indexOf($('root_link').href) && !( /^https:\/\/www.mmontheweb.net/i.test(element.href) ) ) {
		  if( /no_arrow/.test(element.className) ) {
		    
		  } else if( !( /[iI][mM][gG]/.test(element.lastChild.tagName) && /\/images\/offsite_link.gif/.test(element.lastChild.src) ) ) {
		    element.appendChild( document.createTextNode(' ') );
		    element.appendChild( Builder.node('img', {src: '/images/offsite_link.gif' }) );
	      element.target = '_blank';
		  }
		}
	}
}


// Move all primary page content into the main_content div before displaying the page
Behaviour.addLoadEvent( function() {
	var root = document.getElementsByTagName("body")[0];
	if( $('main_content') == null ) {
	  var div = document.createElement( "div" );
	  div.id = 'main_content';
	  $('content').appendChild( div );
	}

	var nodes = $("content").parentNode.childNodes;
	var len = nodes.length;
	for( i=0; i<len; i++ ) {
		switch( nodes[0].id ) {
		  case "todo":
		  case "header":
		  case "navigation":
			case "content":
			case "main_content":
				break;
				
			default:
			  $("main_content").appendChild( nodes[0] );
		}
	}
	root.style.display = "block";

  Behaviour.register(redecorationRules);
  Behaviour.apply();
} );

bulletin_images_loaded = false;
function load_bulletin_images() {
  for(i = 2; i<= bulletin_pages; i++) {
    img = document.createElement('img');
    img.src = image_root + i;
  }
  setTimeout("bulletin_images_loaded = true;", 5000);
}

bulletin_x = -1;
bulletin_page_label = false;
bulletin_dl_label = false;
function mouseover_bulletin() {
  if( bulletin_x == -1 ) {
    bulletin_x = Position.cumulativeOffset($('bulletin_img'))[0];
    bulletin_y = Position.cumulativeOffset($('bulletin_img'))[1];
    bulletin_w = $('bulletin_img').getWidth();
    bulletin_h = $('bulletin_img').getHeight();
  }
  Event.observe('bulletin_img', 'mousemove', flip_bulletin);
}
function mouseout_bulletin() {
  if(bulletin_page_label) {
    bulletin_page_label.style.display = "none";
  }
  if(bulletin_dl_label) {
    bulletin_dl_label.style.display = "none";
  }
  Event.stopObserving('bulletin_img', 'mousemove', flip_bulletin);
  $('bulletin_img').src = image_root + "1"
}
function flip_bulletin(e) {
  if( bulletin_images_loaded ) {
    pointer_x = Event.pointerX(e);
    page = Math.ceil((pointer_x-bulletin_x)/(bulletin_w/bulletin_pages));
    if(page == 0) {page = 1;}
    $('bulletin_img').src = image_root + page;
    if(!bulletin_page_label) {
      bulletin_page_label = document.createElement('span');
      bulletin_page_label.id = "bulletin_page_label";
      bulletin_page_label.style.left      = (bulletin_x + bulletin_w - 60) + "px";
      bulletin_page_label.style.top       = (bulletin_y + bulletin_h - 30) + "px";
      $('body').appendChild(bulletin_page_label);
    } else {
      bulletin_page_label.style.display = "inline";
    }
    bulletin_page_label.innerHTML = "Page " + page;
    if(!bulletin_dl_label) {
      bulletin_dl_label = document.createElement('span');
      bulletin_dl_label.id = "bulletin_dl_label";
      bulletin_dl_label.style.left      = (bulletin_x + 8) + "px";
      bulletin_dl_label.style.top       = (bulletin_y + 6) + "px";
      $('body').appendChild(bulletin_dl_label);
    } else {
      bulletin_dl_label.style.display = "inline";
    }
    bulletin_dl_label.innerHTML = "Click to download the current Bulletin";
  }
}

function show_if_present(e) {
  if( $(e) ) {$(e).show();}
}
function hide_if_present(e) {
  if( $(e) ) {$(e).hide();}
}

hhd_info_pointer = 0;
function show_hhd_info() {
  info_div = $('hhd_info');
  if(info_div.style.display == 'none') {
    $('hhd_group' ).innerHTML = hhd_info[hhd_info_pointer].group;
    $('hhd_events').innerHTML = hhd_info[hhd_info_pointer].events;
    $('hhd_times' ).innerHTML = hhd_info[hhd_info_pointer].times;
    hhd_info_pointer = (hhd_info_pointer + 1) % hhd_info.length;
    Effect.Appear('hhd_info', {duration: 0.5});
    setTimeout('show_hhd_info();', 5000);
  } else {
    Effect.Fade('hhd_info', {duration: 0.5});
    setTimeout('show_hhd_info();', 500);
  }
}

function loadRemoteScript( src ) {
	var script = document.createElement( 'script' );
	script.type = 'text/javascript';
	script.src = src;
	document.getElementsByTagName( 'head' )[0].appendChild( script );
}

loadRemoteScript( "/javascripts/navigation.js" );
