// Standard JavaScript - Copyright (C) 2007-2010 Charles A Upsdell, All Rights Reserved; www.upsdell.com
//
// This has JavaScript available to all pages.

//var oXmasPhoto = new cXmasPhoto ( 'ins_xmas_photo', 'img/pic/xmas', '.jpg', [ '01', '02', '03', '04', '06', '09', '10', '11', '12', '13' ], [ 'Seasons Greetings !', 'Happy Holidays !', 'Peace &bull; Love &bull; Joy' ] );

//	Function called when page has been loaded
function myOnLoad( )
{
startList( 'dropdown' );
myShowItem( 'submenu', ['hide_this1', 'list-item'], ['hide_this2', 'list-item']  );
if ( typeof(oXmasPhoto) != 'undefined' )
	oXmasPhoto.insertPhoto( -1 );
if ( typeof(myNewsAlertText) != 'undefined' )
  {
	if ( typeof(myNewsAlertFields) != 'undefined' )
		myNewsAlertFields();
	else
		myNewsAlert( 'ins_newsalert' );
  }
myRoar();
if ( typeof(myJavaScriptEnabled) != 'undefined' )
	myJavaScriptEnabled();
}


Array.prototype.random = function ()
{
if ( this.length > 0 )
	return this[ Math.floor( this.length * Math.random() ) ];
else
	return undefined;
} 


// Library function
function getElement ( id )
{
var element = null;
if ( (arguments.length == 0) || (id == "") )
	return( null );
if ( document.getElementById )
	element = document.getElementById( id );
else if ( document.all )
	element = document.all[id];
return( element );
}


// Library function
function myIsFlashInstalled ( )
{
	var isFlashInstalled = false;
	if ( typeof(isIE) == 'undefined' )
	  {
		if ( (navigator.plugins == null) || (navigator.plugins.length <= 0) )
			return ( isFlashInstalled );
		for ( var i = 0; i < navigator.plugins.length; ++i )
		  {
			if ( navigator.plugins[i].name.indexOf('Shockwave Flash') != 0 )
				continue;
			isFlashInstalled = true;
			break;
		  }
	  }
	else
	  {
		if ( window.ActiveXObject )
		  {
	    	var control = null;
		    try
			  {
		        control = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
		      }
			catch (e)
			  {
	        	;
			  }
		    if ( control )
		        isFlashInstalled = true;
		  }
	  }
	return( isFlashInstalled );
}


// If appropriate, insert news alert text
function myNewsAlert( id )
{
	if ( (arguments.length > 0) && (typeof(myNewsAlertText) != 'undefined') )
	  {
		var o = getElement( id );
		if ( o )
		  {
			var sHTML = '<div><p>';
			if ( typeof(myNewsAlertDate) != 'undefined' )
				sHTML += '<em class="date">' + myNewsAlertDate + '</em>: ';
			if ( typeof(myNewsAlertTitle) != 'undefined' )
				sHTML += '<em class="title">' + myNewsAlertTitle + '</em>: ';
			sHTML += myNewsAlertText;
			sHTML += '</p></div>\n';
			o.innerHTML = sHTML;
		  }
	  }
}

// Insert code to make tiger roar (only if Flash is installed)
function myRoar( id )
{
	if ( arguments.length < 1 )
		id = 'ins_roar';
	var o = getElement( id );
	if ( o == null )
		return;
	var urlArg = new cArgList ( 'roar' );
	if ( typeof(urlArg.roar) == 'undefined' )
		return;
	if ( !myIsFlashInstalled() )
		return;
	var sHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,0,0" id="roar" width="0" height="0">';
	sHTML += '<param name="movie" value="media/roar.swf" /><param name="quality" value="high" /><param name="loop" value="false" />';
	sHTML += '<embed src="media/roar.swf" loop="false" quality="high" width="0" height="0" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></embed>';
	sHTML += '</object>';
	o.innerHTML = sHTML;
}


// Library function
function myScrollTo ( left, top )
{
	if ( arguments.length < 1 )
		left = 0;
	if ( arguments.length < 2 )
		top = 0;
	var value = true;
	if ( typeof(window.scrollTo) != 'undefined' )
	  {
	 	window.scrollTo( left, top );
		value = false;
	  }
	return( value );
}


// If local file, reveal item; else if IE 5 or 6, hide item
function myShowItem ( arglist )
{
for ( var i = 0; i < arguments.length; ++i )
  {
	if ( arguments[i] instanceof Array )
	  {
		myShowItem ( arguments[i][0], arguments[i][1] );
	  }
	else
	  {
		var sID = arguments[i];
		var sDisplayType = 'block';
		if ( (arguments[i+1] !== undefined) && !(arguments[i+1] instanceof Array) )
			sDisplayType = arguments[++i];
		if ( String(window.location).indexOf('file:') == 0 )
		  {
			var o = getElement( sID );
			if ( o )
			  {
				o.style.display = sDisplayType;
				o.style.color = 'green';
			  }
		  }
		else if ( typeof(isIE5or6) == 'undefined' )
		  {
			continue;
		  }
		else
		  {
			var o = getElement( sID );
			if ( o )
				o.style.display = 'none';
		  }
	  }
  }
}


// cXmasPhoto Class Constructor
function cXmasPhoto ( id, prefix, suffix, aImage, aGreetings )
{
this.$name = 'cXmasPhoto';
this.id = id;
this.prefix = prefix;
this.suffix = suffix;
this.aImage = aImage;
this.aGreetings = aGreetings;
}
// Method to insert image
cXmasPhoto.prototype.insertPhoto = function ( nCurrentPhoto )
{
var $name = 'insertPhoto';
if ( typeof(this.testPhotos) != 'undefined' )
	this.testPhotos();
var o = getElement( this.id );
if ( o )
  {
	var nPhoto;
	do
	  {	nPhoto = Math.floor( this.aImage.length * Math.random() );
	  } while ( nPhoto == nCurrentPhoto );
	var sPhoto = this.aImage[ nPhoto ];
	if ( sPhoto.indexOf('/') == -1 )
		sPhoto = this.prefix + sPhoto;
	if ( (this.suffix != '') && (sPhoto.indexOf('.') == -1) )
		sPhoto += this.suffix;
	var sHTML = '<p class="image"><img src="' + sPhoto + '" class="photo" onclick="oXmasPhoto.insertPhoto(' + nPhoto + ')" title="Holiday scene: click for another" alt="Holiday scene: click for another" /></p>\n';
	if ( this.aGreetings.length > 0 )
	  {
		var sGreetings = this.aGreetings.random();
		sHTML += '<p class="caption"><span class="caption">&nbsp;';
		var nColour = 0;
		for ( var i = 0; i < sGreetings.length; ++i )
		  {
			if ( sGreetings.charAt(i) == ' ' )
				sHTML += ' ';
			else
			  {
				var sText = sGreetings.charAt(i);
				if ( sText == '&' )
				  {
					for ( ++i; i < sGreetings.length; ++i )
					  {
						sText += sGreetings.charAt(i);
						if ( sGreetings.charAt(i) == ';' )
							break;
					  }
				  }
				sHTML += '<span class="c' + (nColour++ %4) + '">' + sText + '</span>';
			  }
		  }
		sHTML += '&nbsp;</span></p>\n';
	  }
	o.innerHTML = sHTML;
  }
}


// Library function
function startList ( id_list )
{
if ( typeof(isIE5or6) != 'undefined' )
  {
	for ( var i = 0; i < arguments.length; ++i )
	  {
		var id = arguments[i];
		navRoot = document.getElementById(id);
		if ( navRoot == null )
			continue;
		for ( var j = 0; j < navRoot.childNodes.length; ++j )
		  {
			node = navRoot.childNodes[j];
			if (node.nodeName=="LI")
			  {
				node.onmouseover=function() { this.className+=" over"; }
				node.onmouseout=function() { this.className=this.className.replace(" over", ""); }
			  }
		  }
	  }
  }
}

