function isset(varname)  {
  if(typeof( window[varname] ) != "undefined") return true;
  else return false;
}

// function isset(varname){
//   return( typeof(window[varname] ) != 'undefined' );
// }

// function isset(variable_name) {
// 	try {
// 		if( typeof(eval(variable_name) ) != 'undefined' )
// 			if (eval(variable_name) != null)
// 				return true;
// 	}
// 	catch(e) {}
// 	return false;
// }

if( !isset('switchbg_enable') ) {
	var switchbg_enable = true;
}
if( !isset('switchbg_cycle') ) {
	var switchbg_cycle = true;
}
if( !isset('switchbg_random') ) {
	var switchbg_random = false;
}
if( !isset('switchbg_tickTime') ) {
	// var switchbg_tickTime = 100;
	var switchbg_tickTime = 200;
}

var switchbg_bgColors;
var switchbg_bgColorsSet = -1;
var switchbg_bgColorIndex = 0;

function startSwitchBGTimer() {
// 	if( ! switchbg_enable ) { return; }
	if( switchbg_enable ) {
		setTimeout( "startSwitchBGTimer()", switchbg_tickTime );
	}

	if( switchbg_cycle ) {
		switchbg_bgColorIndex++;
		if( switchbg_bgColorIndex == switchbg_bgColors.length ) {
			switchbg_bgColorIndex = 0;
		}
	}
	else if( switchbg_random ) {
		switchbg_bgColorIndex = Math.round(Math.random()*switchbg_bgColors.length+1);
	}

	switchBGColor( switchbg_bgColors[switchbg_bgColorIndex] );
}

function returnObjById( id ) { 
    if (document.getElementById) 
        var returnVar = document.getElementById(id); 
    else if (document.all) 
        var returnVar = document.all[id]; 
    else if (document.layers) 
        var returnVar = document.layers[id]; 
    return returnVar;
}

function switchBGColor( color ) {
	//document.getElementById('masthead').style.backgroundColor = switchbg_bgColors[Math.round(Math.random()*switchbg_bgColors.length+1)];
	//document.getElementById('rap').style.backgroundColor = switchbg_bgColors[Math.round(Math.random()*switchbg_bgColors.length+1)];
	if( document.body ) {
		document.body.style.backgroundColor = color;
	}
	else if( document.getElementsByTagName ) {
		var body = document.getElementsByTagName('body');
		if( body.item(0) ) {
			body.item(0).style.backgroundColor = color;
		}
		else {
			body.style.backgroundColor = color;
		}
	}
	//else if( document.childNodes[0].childNodes[1] ) {
	//	document.childNodes[0].childNodes[1].style.backgroundColor = color;
	//}
}

function toggleSwitchBGTimer( name, textOn, textOff ) {
	if( document.all ) {
		d = document.all[name];
	}
	else {
		d = document.getElementById(name);
	}

	if( switchbg_enable == false ) {
		switchbg_enable = true;
		startSwitchBGTimer();
		d.innerHTML = textOn;
	}
	else {
		switchbg_enable = false;
		d.innerHTML = textOff;
	}
}

function changeColorSet() {
// 	if( ! switchbg_enable ) { return; }
	switchbg_bgColorsSet++;
	switchbg_bgColorIndex = 0;
	if( switchbg_bgColorsSet == 3 ) {
		switchbg_bgColorsSet = 0;
	}
	if( switchbg_bgColorsSet == 1 ) {
		switchbg_bgColors=Array('#dc1400','#dc2800','#dc3c00','#dc5000','#dc6400','#dc7800','#dc8c00','#dca000','#dcb400','#dcc800','#dcdc00','#c8dc00','#b4dc00','#a0dc00','#8cdc00','#78dc00','#64dc00','#50dc00','#3cdc00','#28dc00','#14dc00','#00dc00','#00dc14','#00dc28','#00dc3c','#00dc50','#00dc64','#00dc78','#00dc8c','#00dca0','#00dcb4','#00dcc8','#00dcdc','#00c8dc','#00b4dc','#00a0dc','#008cdc','#0078dc','#0064dc','#0050dc','#003cdc','#0028dc','#0014dc','#0000dc','#1400dc','#2800dc','#3c00dc','#5000dc','#6400dc','#7800dc','#8c00dc','#a000dc','#b400dc','#c800dc','#dc00dc','#dc00c8','#dc00b4','#dc00a0','#dc008c','#dc0078','#dc0064','#dc0050','#dc003c','#dc0028','#dc0014','#dc0000');
	}
	if( switchbg_bgColorsSet == 2 ) {
		switchbg_bgColors=Array('#3333ff','#3333ff','#3333ff','#33ff33','#33ff33','#33ff33','#ff3333','#ff3333','#ff3333');
	}
	else {
		switchbg_bgColors=Array('#3399ff','#3896fa','#3c93f6','#4190f1','#4b89e7','#4f86e3','#5483de','#5980d9','#5d7dd5','#627ad0','#6b73c7','#7070c2','#756dbd','#7e67b4','#8364af','#8861aa','#8c5da6','#96579c','#9b5497','#9f5193','#a94b89','#ad4785','#b24480','#bc3e76','#c03b72','#c5386d','#c5386d','#c03b72','#bc3e76','#b24480','#ad4785','#a94b89','#9f5193','#9b5497','#96579c','#915aa1','#8861aa','#7e67b4','#756dbd','#6b73c7','#6776cb','#5d7dd5','#5980d9','#5483de','#4b89e7','#468cec','#4190f1','#3c93f6','#3896fa','#3399ff');
	}
	//var switchbg_bgColors=Array('#0099ff','#0595fb','#0b91f7','#1689ef','#1b85eb','#2181e7','#267ce2','#2c78de','#3174da','#3c6cd2','#4168ce','#4764ca', '#525cc2','#5758be','#5c54ba','#674bb1','#6d47ad','#7243a9','#783fa5','#83379d','#883399','#8d2f95','#98278d','#9e2389','#a31f85','#ae167c','#b41278','#b90e74','#be0a70','#c4066c','#c90268','#be0a70','#b90e74','#b41278','#ae167c','#a31f85','#9e2389','#98278d','#8d2f95','#883399','#83379d','#7d3ba1','#7243a9','#6d47ad','#674bb1','#5c54ba','#5758be','#525cc2','#4c60c6', '#4168ce','#3c6cd2','#3670d6');
}

changeColorSet();
startSwitchBGTimer();
