/* ==============================================================
	FRAW GENERIC JAVASCRIPT ROUTINES MODULE v0.1

	The purpose of this script is to provide additional function-
	ality to the main indexes of the FRAW web site.

	Copyright (C) 2009 Paul Mobbs/Free Range Network.
	
	Produced by Paul Mobbs/the electrohippie collective 2009
	Released under the Gnu General Public License v3.0 -- for a 
	copy of the license goto
	http://www.fraw.org.uk/gpl-3.html
	or see 
	http://www.gnu.org/licenses/
	
	This program is free software: you can redistribute it and/or 
	modify it under the terms of the GNU General Public License as 
	published by the Free Software Foundation, either version 3 of 
	the License, or (at your option) any later version.
	
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
	GNU General Public License for more details.
*/


// --------------------------------------------------------------

// KEY IDs ARRAY
// The Keys array provides the internal links used by certain 
// navigation functions.

var keys = new Array();

// FRAW site keys
keys[ 'about']			= '/about.shtml';
keys[ 'contact']		= '/contact.shtml';
keys[ 'copyright']	= '/copyright.shtml';
keys[ 'design']		= '/fraw_design.shtml';
keys[ 'help']			= '/navigating_fraw.shtml';
keys[ 'index']			= '/index.shtml';
keys[ 'keys']			= '/key_index.shtml';
keys[ 'search']		= '/search.shtml';
keys[ 'tree']			= '/site_index.shtml';
keys[ 'work']			= '/work_in_progress.shtml';

// free range project keys
keys[ 'campaigns']	= '/campaigns/index.shtml';
keys[ 'events']		= '/events/index.shtml';
keys[ 'projects']		= '/projects/index.shtml';
keys[ 'pubs']			= '/publications/index.shtml';
keys[ 'workshops']	= '/workshops/index.shtml';

// free range initiative keys
keys[ 'climate']		= '/projects/ebo/energy_and_climate.shtml';
keys[ 'eboinit']		= '/projects/ebo/energy_beyond_oil.shtml';
keys[ 'food']			= '/projects/ebo/liberation_gastronomy.shtml';
keys[ 'less']			= '/projects/ebo/less_is_a_four_letter_word.shtml';
keys[ 'tech']			= '/projects/ssp/limits_to_technology.shtml';

// FRN Publications
keys[ 'pubs-e'] 		= '/publications/e-series/index.shtml';
keys[ 'e01'] 			= '/publications/e-series/e01/index.shtml';
keys[ 'e02'] 			= '/publications/e-series/e02/index.shtml';
keys[ 'e03'] 			= '/publications/e-series/e03/index.shtml';
keys[ 'e04'] 			= '/publications/e-series/e04/index.shtml';
keys[ 'e05'] 			= '/publications/e-series/e05/index.shtml';
keys[ 'e06'] 			= '/publications/e-series/e06/index.shtml';
keys[ 'e07'] 			= '/publications/e-series/e07/index.shtml';
keys[ 'e08'] 			= '/publications/e-series/e08/index.shtml';
keys[ 'e09'] 			= '/publications/e-series/e09/index.shtml';
keys[ 'e10'] 			= '/publications/e-series/e10/index.shtml';
keys[ 'pubs-f'] 		= '/publications/f-series/index.shtml';
keys[ 'f01'] 			= '/publications/f-series/f01/index.shtml';
keys[ 'pubs-g'] 		= '/publications/g-series/index.shtml';
keys[ 'g01'] 			= '/publications/g-series/g01/index.shtml';
keys[ 'g02'] 			= '/publications/g-series/g02/index.shtml';
keys[ 'pubs-j'] 		= '/publications/j-series/index.shtml';
keys[ 'j01'] 			= '/publications/j-series/j01/index.shtml';
keys[ 'j02'] 			= '/publications/j-series/j02/index.shtml';
keys[ 'j03'] 			= '/publications/j-series/j03/index.shtml';
keys[ 'j04'] 			= '/publications/j-series/j04/index.shtml';
keys[ 'pubs-o'] 		= '/publications/o-series/index.shtml';
keys[ 'o01'] 			= '/publications/o-series/o01/index.shtml';
keys[ 'o02'] 			= '/publications/o-series/o02/index.shtml';
keys[ 'o03'] 			= '/publications/o-series/o03/index.shtml';
keys[ 'o04'] 			= '/publications/o-series/o04/index.shtml';
keys[ 'o05'] 			= '/publications/o-series/o05/index.shtml';
keys[ 'o06'] 			= '/publications/o-series/o06/index.shtml';
keys[ 'o07'] 			= '/publications/o-series/o07/index.shtml';
keys[ 'o08'] 			= '/publications/o-series/o08/index.shtml';
keys[ 'o09'] 			= '/publications/o-series/o09/index.shtml';
keys[ 'o10'] 			= '/publications/o-series/o10/index.shtml';
keys[ 'o11'] 			= '/publications/o-series/o11/index.shtml';
keys[ 'pubs-q'] 		= '/publications/q-series/index.shtml';
keys[ 'q01'] 			= '/publications/q-series/q01/index.shtml';
keys[ 'q02'] 			= '/publications/q-series/q02/index.shtml';
keys[ 'pubs-s'] 		= '/publications/s-series/index.shtml';
keys[ 's01'] 			= '/publications/s-series/s01/index.shtml';
keys[ 's02'] 			= '/publications/s-series/s02/index.shtml';
keys[ 's03'] 			= '/publications/s-series/s03/index.shtml';
keys[ 'pubs-misc'] 	= '/publications/misc/index.shtml';
keys[ 'netcu'] 		= '/publications/misc/netcu/index.shtml';

// files and downloads section
keys[ 'files'] 		= '/files/index.shtml';

// FRN Projects
keys[ 'cltc']			= '/projects/cltc/index.shtml';
keys[ 'ebo']			= '/projects/ebo/index.shtml';
keys[ 'ehippies']		= '/projects/electrohippies/index.shtml';
keys[ 'outdoors']		= '/projects/outdoors/index.shtml';
keys[ 'ssp']			= '/projects/ssp/index.shtml';

// FRN Workshops
keys[ 'ws-climate']	= '/workshops/climate/index.shtml';
keys[ 'ws-ebo']		= '/workshops/ebo/index.shtml';
keys[ 'ws-futures']	= '/workshops/futures/index.shtml';
keys[ 'ws-food']		= '/workshops/food/index.shtml';
keys[ 'ws-foss']		= '/workshops/foss/index.shtml';
keys[ 'ws-indoors']	= '/workshops/the_great_indoors/index.shtml';
keys[ 'ws-less']		= '/workshops/less/index.shtml';
keys[ 'ws-linux']		= '/workshops/linux_install/index.shtml';
keys[ 'ws-outdoors']	= '/workshops/the_great_outdoors/index.shtml';
keys[ 'ws-power']		= '/workshops/renewable_power/index.shtml';
keys[ 'ws-tech']		= '/workshops/limits_to_tech/index.shtml';
keys[ 'ws-urban']		= '/workshops/the_urban_outdoors/index.shtml';

// FRN Workshop Virtual Presentations
keys[ 'vp-tech']		= '/workshops/limits_to_tech/virtual_presentation.shtml';

// FRN campaigns
keys[ 'browseralert'] = '/campaigns/browseralert/index.shtml';
keys[ 'simple']		= '/campaigns/simple/index.shtml';

// microsite section keys
keys[ 'dgg']			= '/dgg/index.html';
keys[ 'mei']			= '/mei/index.shtml';
keys[ 'meiarchive']	= '/mei/archive/index.shtml';
keys[ 'ecolonomics']	= '/mei/ecolonomics/index.shtml';
keys[ 'meievents']	= '/mei/events/index.shtml';
keys[ 'meiinfo']		= '/mei/background.shtml';
keys[ 'meipapers']	= '/mei/papers/index.shtml';
keys[ 'meitraining']	= '/mei/training/index.shtml';
keys[ 'mobbsey']		= '/mei/index.shtml';

// external keys
keys[ 'lili']			= 'http://www.lowimpact.org/';
keys[ 'gn']				= 'http://www.gn.apc.org/';


// KIOSK WINDOW GOBAL VARIABLE
var kioskWindow = null;


// --------------------------------------------------------------

// ONLOAD EXECUTION ROUTINE
// This routine is called by 'onload' from the BODY tag and 
// ensures that the page is being displayed in the 'top' window.
function execute()
{
	if( parent.frames[ 1])
	{
			parent.location.href = self.location.href;
	}
}


// --------------------------------------------------------------

// BROWSER ALERT TEST
// This routine checks the identity of the browser in order to  
// add additional information to the page for browsers that appear 
// to have a proprietary design.
function browser_alert()
{
	var idInfoString = new Array( "Microsoft", "MSIE", "Windows", "Macintosh", "Mac OS", "Safari", "Opera", "Chrome");
	var agent = navigator.userAgent; 
	var ptr = 0;

	// check for incidence of each ID string
	for( ptr = 0; ptr < idInfoString.length; ptr++) 
	{ 
		if( agent.indexOf( idInfoString[ ptr]) > -1) 
		{
			return( 1);
		}
	}
	return( 0);
}


// --------------------------------------------------------------

// ENABLE KIOSK/FULLSCREEN DISPLAY
// This function opens a new browser for the current locations using as 
// large a display area as possible.
function kiosk()
{
	var attribs = 'resizable=yes,scrollbars=yes,status=no,titlebar=no,location=no,personalbar=no,top=0,left=0,' +
						'outerHeight=' + screen.height + ',outerWidth=' + screen.width + ',alwaysRaised=yes';

	if( kioskWindow == null || kioskWindow.closed)
	{
		kioskWindow = window.open( window.location.href, 'FRAW Website -- Fullscreen Display', attribs);
	}
	else
	{
		kioskWindow.focus();
	}
}

// --------------------------------------------------------------

// FORM NAVIGATION ROUTINE
// This function takes a key string from the navigation form and 
// automatically forwards to the requested page.
function navigate( key)
{
	if( key == '' || key == undefined)
	{
		return;
	}
	if( keys[ key] == undefined)
	{
		alert( "Requested key '" + key + "' does not exist!");
		return;
	}
	else
	{
		window.location.href = keys[ key];
	}
}


// --------------------------------------------------------------

// KEY ID QUERY ROUTINE
// This routine is called automatically from a web page and tests
// the search object for a key parameter and then automatically 
// forwards to the requested file.
function query()
{
	var queryString = '';
	var strings = new Array();
	var key = '';
	var keyName = 'key';
	var param = new Array();

	queryString = window.location.search;
	queryString = queryString.toLowerCase();
	queryString = queryString.substr( 1);
	strings = queryString.split( '&');
	for( var i in strings)
	{
		if( keys[ strings[ i]] != undefined)
		{
				window.location.href = keys[ strings[ i]];
				return;
		}
		param = strings[ i].split( '=');
		if( keys[ param[ 1]] != undefined)
		{
				window.location.href = keys[ param[ i]];
				return;
		}
	}
}


// --------------------------------------------------------------

// WHAT AM I?
// This routine returns the identity string of the browser.
function whatami()
{
	var agent = navigator.userAgent; 
	var message = '\n\nYour browser SHOULD NOT trigger the "Browser Alert!" script.';

	// check for incidence of each ID string
	if( browser_alert()) 
	{
		message = '\n\nYour browser SHOULD trigger the "Browser Alert!" script.';
	}

	// show alert message
	alert( 'Browser identity --\n\n"' + agent + '"' + message);
}


// ==============================================================

// END OF SCRIPT

