// Home Page JavaScript - Copyright (C) 2007-2011 Charles A Upsdell, All Rights Reserved; www.upsdell.com
//
// This has JavaScript needed only by the home and test pages


if ( typeof(cFilenameList) != 'undefined' )
	var myXmasPhoto = new cFilenameList( [ '01..21' ], 'img/pic/', 'xmas', '.jpg', 'ins_xmas_photo', 'textSplit randomStack' );
if ( typeof(myXmasPhoto) != 'undefined' )
  {
	myXmasPhoto.aCaption = [ 'Seasons Greetings !', 'Happy Holidays !', 'Peace &bull; Love &bull; Joy' ];
	myXmasPhoto.sOnClickMethod = 'myXmasPhoto.insertPhoto';
	myXmasPhoto.sImageFormat = '<p class="image"><img src="%0" class="photo" onclick="%1()" title="%2: click for another" alt="%2: click for another image" /></p>\n';
	myXmasPhoto.sImageTitle = 'Holiday scene';
	myXmasPhoto.sCaptionCharStyles = [ 'c0', 'c1', 'c2', 'c3' ];
	myXmasPhoto.sCaptionFormat = '<p class="caption"><span class="caption">&nbsp;%0&nbsp;</span></p>\n';
  }

cFilenameList.prototype.toImageHTML = function ( nImage )
{
if ( arguments.length < 1 )
	nImage = this.stack.draw();
var sImage = this.name( nImage );
var sTitle = this.text( nImage );
if ( sTitle === undefined )
	sTitle = this.sImageTitle;
return this.sImageFormat.blend( sImage, this.sOnClickMethod, sTitle );
}

cFilenameList.prototype.toCaptionHTML = function ( sCaption )
{
if ( arguments.length < 1 )
	sCaption = this.aCaption.random();
if ( sCaption == '' )
	return '';
var sFormattedCaption = '';
if ( (typeof(this.sCaptionCharStyles) == 'undefined') || (this.sCaptionCharStyles.length == 0) )
  {
	sFormattedCaption = sCaption;
  }
else
  {
	var nClass = 0;
	var nClasses = this.sCaptionCharStyles.length;
	for ( var i = 0; i < sCaption.length; ++i )
	  {
		if ( sCaption.charAt(i) == ' ' )
			sFormattedCaption += ' ';
		else
		  {
			var sChar = sCaption.charAt(i);
			if ( sChar == '&' )
			  {
				for ( ++i; i < sCaption.length; ++i )
				  {
					sChar += sCaption.charAt(i);
					if ( sCaption.charAt(i) == ';' )
						break;
				  }
			  }
			sFormattedCaption += '<span class="' + this.sCaptionCharStyles[nClass%nClasses] + '">' + sChar + '</span>';
			++nClass;
		  }
	  }
  }
return this.sCaptionFormat.blend( sFormattedCaption );
}

cFilenameList.prototype.insertPhoto = function ( )
{
var o = getElement( this.id );
if ( o == null )
	return;
var sHTML = this.toImageHTML();
sHTML += this.toCaptionHTML();
o.innerHTML = sHTML;
}

// 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 class="alert"><p>';
		if ( typeof(myNewsAlertDate) != 'undefined' )
			sHTML += '<em class="date">' + myNewsAlertDate + '</em><span class="colon">:</span> ';
		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;
if ( typeof(cArgList) == 'undefined' )
	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;
}


