//	theme.js - Functions dealing with themes
//
//	Copyright (C) 2006-2009 Charles A Upsdell, All Rights Reserved; www.upsdell.com


// Initialization .................... executed when the page is starting to load

	// Set global contants
	var nDefaultTheme = 1;
	var isModernBrowser = true;

	// Set global values
	var Theme = new Array();

	// Initialize Theme array
	addTheme( 'white', '', '', '#fff' );
	addTheme( 'gray',  '_gray', 'theme_gray.css', '#999' );


// Global functions .................. called by other modules

function cTheme ( name, filename_suffix, css_file, background )
{
	this.name = name;
	this.filename_suffix = filename_suffix;
	this.css_file = css_file;
	this.background = background;
}

cTheme.prototype.loadCSS = function ()
{
	if ( this.css_file )
		document.writeln( '<link rel="stylesheet" type="text/css" href="' + this.css_file + '">' );
}

cTheme.prototype.selectHTML = function ( filename, style )
{
	var sHTML = '';
	if ( style == 'list' )
	  {
		for ( var i = 0; i < Theme.length; ++i )
		  {
			if ( i > 0 )
				sHTML += '&nbsp;';
			if ( Theme[i].name == this.name )
				sHTML += '<span class="current">' + this.name + '</span>';
			else
				sHTML += '<a href="' + filename + '" onclick="oState.gotoPage(\'' + filename + '\',null,\'' + Theme[i].name + '\');return(false);">' + Theme[i].name + '</a>';
		  }
	  }
	else
		alert( 'cTheme.selectHTML error, invalid style ' + style );
	return( sHTML );
}

function getThemeIndex ( name )
{
	for ( var i = 0; i < Theme.length; ++i )
	  {
		if ( Theme[i].name == name )
			return( i );
	  }
	return( -1 );
}


// Local functions ................... called by other modules

function addTheme ( name, filename_suffix, css_file, background )
{
	if ( arguments.length < 4 )
		alert( 'addTheme error: missing argument(s)' );
	else
	{
		if ( getThemeIndex(name) >= 0 )
			alert( 'addTheme error: you used theme "' + name + '" more than once.' );
		Theme[Theme.length] = new cTheme( name, filename_suffix, css_file, background );
	}
}



