var bSetHeaderWhite = false;

//--------------------------------------------------------------

var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;

if (checkIt('konqueror'))
{
	browser = "Konqueror";
	OS = "Linux";
}
else if (checkIt('safari')) browser = "Safari"
else if (checkIt('omniweb')) browser = "OmniWeb"
else if (checkIt('opera')) browser = "Opera"
else if (checkIt('webtv')) browser = "WebTV";
else if (checkIt('icab')) browser = "iCab"
else if (checkIt('msie')) browser = "Internet Explorer"
else if (!checkIt('compatible'))
{
	browser = "Netscape Navigator"
	version = detect.charAt(8);
}
else browser = "An unknown browser";

if (!version) version = detect.charAt(place + thestring.length);

if (!OS)
{
	if (checkIt('linux')) OS = "Linux";
	else if (checkIt('x11')) OS = "Unix";
	else if (checkIt('mac')) OS = "Mac"
	else if (checkIt('win')) OS = "Windows"
	else OS = "an unknown operating system";
}

function checkIt(string)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}



//--------------------------------------------------------------


// original setup
function initialSetup()
{
	var item;
	item = document.getElementById( 'sectionBodyTD' );
	item.style.background="white";
	item.style.color=GetComplement( item.style.background );
 	
	item = document.getElementById( 'sectionText' );
	setInnerHTML( "home.htm", item, false );

	item = document.getElementById( 'bottomLeftTD' );
	item.style.background="red";
	item.style.color=GetComplement( item.style.background );

	// do header
	item = document.getElementById( 'sectionHeaderTD' );
	item.style.background="yellow";
	item.style.color=GetComplement( item.style.background );

	item = document.getElementById( 'middleBottomTD' );
	item.style.background="yellow";
	item.style.color=GetComplement( item.style.background );

	item = document.getElementById( 'middleTopTD' );
	item.style.background="blue";
	item.style.color=GetComplement( item.style.background );

	item = document.getElementById( 'sectionHeaderText' );
	bSetHeaderWhite = true;
	setInnerHTML( "homeHeader.htm", item, false );
	item.style.color="black";
	item = document.getElementById( 'HeaderText' );
	item.style.color="black";
			
	if( browser=="Internet Explorer")
	{
		item = document.getElementById( 'iconArea' );
		item.innerHTML = "&#178";
	}

}

function setContent( section )
{
	var item;

	item = document.getElementById( 'sectionBodyTD' );
	item.style.verticalAlign="middle";

	//get html from file
	item = document.getElementById( 'sectionText' );
	setInnerHTML( section + ".htm", item, false );

	// do header
	item = document.getElementById( 'sectionHeaderText' );
        setInnerHTML( section + "Header.htm", item, true );

	switch( section )
	{
		case "home":
			item = document.getElementById( 'HeaderTextRight' );
                        item.innerHTML = "home";
		break;
		case "originals":
			item = document.getElementById( 'HeaderTextRight' );
                        item.innerHTML = "originals";

		break;
		case "covers":
			item = document.getElementById( 'HeaderTextRight' );
                        item.innerHTML = "covers";
	
		break;
		case "gear":
			item = document.getElementById( 'HeaderTextRight' );
                        item.innerHTML = "gear";
		break;
		case "about":
			item = document.getElementById( 'HeaderTextRight' );
                        item.innerHTML = "about";
		break;
	}

	// do colors
	//RandomizeColors();


			if( browser=="Internet Explorer")
			{
				item = document.getElementById( 'iconArea' );
                       		item.innerHTML = RandomIcon();  // icon
			}
}



function RandomizeColors()
{
	var item;
	var item2;
	item = document.getElementById( 'sectionBodyTD' );
	item.style.background=GetRandomColor();
	item.style.color=GetComplement( item.style.background );

	changecss('a.songLink:link','color', item.style.color );
	changecss('a.songLink:visited','color', item.style.color );
	changecss('td.trans','color', item.style.color );

	item = document.getElementById( 'middleBottomTD' );
	item.style.background=GetRandomColor();
	item.style.color=GetComplement( item.style.background );

	item = document.getElementById( 'middleTopTD' );
	item.style.background=GetRandomColor();
	item.style.color=GetComplement( item.style.background );



	item = document.getElementById( 'bottomLeftTD' );
	item.style.background=GetRandomColor();
	item.style.color=GetComplement( item.style.background );

	// it was the embed background that didn't update
	// finally shrank it so there was no background




	item = document.getElementById( 'sectionHeaderTD' );
	item.style.background=GetRandomColor();
	item.style.color=GetComplement( item.style.background );
	item2 = document.getElementById( 'sectionHeaderText' );
	item2.style.color=GetComplement( item.style.background );
	item2 = document.getElementById( 'HeaderText' );
	item2.style.color=GetComplement( item.style.background );
	
	item = document.getElementById( 'headerRightTD' );
	item.style.background="white";
	item.style.color=GetComplement( item.style.background );
}

function RandomIcon()
{
	var icon = "&#178"; // default to headphones
	var totalIcons = 15;
	var random = Math.round( Math.random() * totalIcons );

	switch( random )
	{
		case 0:
			//icon="H"; //house
		break;
		case 1: 
			//icon="s"; //question mark
		break;
		case 2:
			icon="&#175"; //note
		break;
		case 3:
			icon="&#177"; //microphone
		break;
		case 4:
			icon="&#178"; //headphones
		break;
		case 5:
			icon="&#179"; //cd
		break;
		case 6:
			//icon="&#181"; //camera
			icon = "&#175";
		break;
		case 7:
			//icon="&#183"; //clapboard
			icon = "&#179";
		break;
		case 8:
			//icon="&#184"; //film camera
		break;
		case 9:
			icon="&#186"; //boombox
		break;
		case 10:
			//icon="&#187"; //radio
		break;
		case 11:
			icon="&#196"; //gamepad
		break;
		case 12:
			icon="&#220"; //lightning cloud
		break;
		case 13:
			icon="&#229"; //martini
		break;
		case 14:
			icon="&#252"; //globe
		break;
	}
	return icon;

}

function GetRandomColor()
{
	var totalColors = 6;
	var random = Math.round( Math.random() * totalColors );
	var color;

	switch( random )
	{
		case 0:
			color="black";
		break;
		case 1: 
			color="white";
		break;
		case 2:
			color="red";
		break;
		case 3:
			color="yellow";
		break;
		case 4:
			color="blue";
		break;
		case 5:
			color="gray";
		break;
	}

	return color;
}


function GetComplement( mycolor )
{
	var temp = new Array();
	temp = mycolor.split(' ');

	var comp;
	var color = temp[0];
	comp="white";

	switch( color )
	{
		case "white":
		case "yellow":
			comp="black";
		break;
		case "red":
		case "blue":
		case "gray":
		case "black":
			comp="white";
		break;
	}

	return comp;

}




function setInnerHTML( filename, item, bDoColors )
{
var text;
var item2;
var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
  xmlhttp = new XMLHttpRequest();
}


 xmlhttp.open("GET", filename,true);
 xmlhttp.onreadystatechange=function() {
  if (xmlhttp.readyState==4) {
   text = xmlhttp.responseText;
   item.innerHTML = text;
   if( bDoColors == true )
	RandomizeColors();
  }
	if (bSetHeaderWhite == true)
        {
		item2 = document.getElementById( 'HeaderText' );
		item2.style.color="white";
		bSetHeaderWhite=false;
        }
 }
 xmlhttp.send(null)

}

	function changecss(theClass,element,value) {
	//documentation for this script at http://www.shawnolson.net/a/503/
	 var cssRules;
	 if (document.all) {
	  cssRules = 'rules';
	 }
	 else if (document.getElementById) {
	  cssRules = 'cssRules';
	 }
	 for (var S = 0; S < document.styleSheets.length; S++){
	  for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
	   if (document.styleSheets[S][cssRules][R].selectorText.toUpperCase() == theClass.toUpperCase()) {
	    document.styleSheets[S][cssRules][R].style[element] = value;
	   }
	  }
	 }	
	}


function setPlayer( filename, songTitle )
{
	var item;
	var playerItem;
	var parent;

	stopPlayer();	

	item = document.getElementById( 'closeButton' );
	item.style.visibility = "visible";
	item = document.getElementById( 'closeLink' );
	item.style.visibility = "visible";

	item = document.getElementById( 'playerSpan' );
	parent = document.getElementById( 'bottomLeftTD' );

	if( songTitle == undefined ) { songTitle="No Song Data"; }

	playerItem = document.getElementById( 'player' );
	
	if( playerItem )
	{
		// change source of current player
		//playerItem.style.src = ".//music//" + filename;	
		//playerItem.setAttribute('src', ".//music//" + filename);
		//return;
	}


	item.innerHTML = "";
	item.innerHTML = "<EMBED class='player' id='player' src='.//music//" + filename + "'></EMBED>";

	if( browser=="Internet Explorer" )
	{	
		item.innerHTML += "<BR><MARQUEE id='songMarquee'>" + songTitle + "</MARQUEE>";
	}
	else
	{
		item.innerHTML += "<BR>" + songTitle;
	}
	
}

function stopPlayer()
{
	var item;
	item = document.getElementById( 'closeButton' );
	item.style.visibility = "hidden";
	item = document.getElementById( 'closeLink' );
	item.style.visibility = "hidden";
	item = document.getElementById( 'playerSpan' );
	item.innerHTML = "";
}








function showLyrics( songTitle )
{
	var item;

	item = document.getElementById( 'sectionBodyTD' );
	item.style.verticalAlign="top";

	//get html from file
	item = document.getElementById( 'sectionText' );
	setInnerHTML( ".//lyrics//" + songTitle + ".lyr", item, false );
}

function downloadSong()
{
	alert( "To download, right click and choose 'Save File As...'" );
	exit();
}











