
var submenus = null;
var body = null;
var pageid = null;
var timeout_submenu = null;

function default_submenu() {
	window.clearTimeout(timeout_submenu);
	timeout_submenu = window.setTimeout('show_submenu(pageid);',0.01);
}

function show_submenu ( menu ) {
	for ( var i = 0, len = submenus.length ; i < len ; i ++ )
		if (submenus[i].id == menu )
			body.id = menu;
}

function fizzbuzz ( ) {
	var output = iteration = '';
	for ( var i = 1 ; i <= 100 ; i++ ) {
		iteration = '';
		if ( i % 3 == 0 ) iteration += 'fizz';
		if ( i % 5 == 0 ) iteration += 'buzz';
		if (iteration=='') iteration = i.toString();
		output += (output==''?'':' | ') + iteration;
	}
	return ( output );
}

function swapem ( x, y ) {
	x ^= y;
	y ^= x;
	x ^= y;
	return [x,y];
}

var collected_links = [];
var current_link = null;

function make_printable_links() {

	// Get all document links and put them into global variable without duplicates
	var all_content_links = $$('#content a');
	all_content_links.each( function(item){ if(item.href!='') collected_links.push ( item.href ); });
	collected_links = collected_links.uniq();

	// Build ordered-list of links
	var link_content = '';
	for ( var i = 0, len = collected_links.length ; i < len ; i ++ ) {
		link_content += '<li>'+collected_links[i]+'</li>';
		current_link = i;

		// Find links in the document and add their corresponding index
		all_content_links.each( function(item){
			if (item.href == collected_links[current_link] && item.href!='') {
				new Insertion.After(item, '<sup class="print_only">' + (current_link+1).toString() + '</sup>')
			}
		});
	}

	if ( link_content != '' ) {
		new Insertion.Before ( 'copyright', '<p class="print_only"><h3 class="print_only">Links in this page</h3><ol class="print_only">' + link_content + '</ol></p>' );
	}

}

window.onload = function ( ) {
	make_printable_links();


	submenus = $$('#submenu ul');
	body = $$('body')[0];
	pageid = body.id;
	show_submenu ( body.id );
	$$('#content_wrapper','#heading_wrapper','#breadcrumbs').each(function(item){
		item.onmouseover = default_submenu;
	});
}
