window.onload = makeDoubleDelegate(window.onload, init );
var img=document.createElement("img");
var img2=document.createElement("img");
img.src="http://mysite.verizon.net/doofymusic/mj_logo3.gif";
img.src="http://mysite.verizon.net/doofymusic/mj_logo2.jpg";
var spinningNumber;
var disappearCount=0;

function makeDoubleDelegate(function1, function2) 
{
	return function() 
	{
		if (function1) function1();
		if (function2) function2();
	}
}// makeDoubleDelegate

function init()
{
	//createDisplayOptions();
	altLogo();
	createOrdinalValues();
	colorCode();
}// end init

function altLogo()
{
	var div=document.getElementById("logo");
	var img=div.getElementsByTagName("img")[0];
	img.src="http://mysite.verizon.net/doofymusic/mj_logo2.jpg";
}// end altLogo

function flashLogo()
{
	var div=document.getElementById("logo");
	var img=div.getElementsByTagName("img")[0];
	var exclusionList = new Array("artist/joanna");
	var myProfileLink=document.getElementById("my_profile_link");
	var i,a;
	var displayLogo=true;
	if (myProfileLink)
	{
		a=myProfileLink.getElementsByTagName("a")[0];
		for (i=0; i<exclusionList.length; i++)
		{
			if (a.href.toLowerCase().indexOf(exclusionList[i])>=0)
			{
				displayLogo=false;
				break;
			}
		}// end for i
	}
	if (displayLogo) img.src="http://mysite.verizon.net/doofymusic/mj_logo3.gif";
}// end flashLogo

function createDisplayOptions()
{
	var select=document.createElement("select");
	var songsTable=document.getElementById("songs_table");
	var option,text;
	select.setAttribute("id","last_comment_select");
	option=document.createElement("option");
	option.setAttribute("value","-1");
	text=document.createTextNode("Please select comment date...");
	option.appendChild(text);
	select.appendChild(option);
	
	option=document.createElement("option");
	option.setAttribute("value","0");
	text=document.createTextNode("Today's comments");
	option.appendChild(text);
	select.appendChild(option);
	
	option=document.createElement("option");
	option.setAttribute("value","1");
	text=document.createTextNode("Yesterday's comments");
	option.appendChild(text);
	select.appendChild(option);
	
	option=document.createElement("option");
	option.setAttribute("value","30");
	text=document.createTextNode("Comments in last 30 days");
	option.appendChild(text);
	select.appendChild(option);	
	
	option=document.createElement("option");
	option.setAttribute("value","90");
	text=document.createTextNode("Comments in last 90 days");
	option.appendChild(text);
	select.appendChild(option);
	
	songsTable.parentNode.parentNode.insertBefore(select,songsTable.parentNode);
}// end createDisplayOptions

function createOrdinalValues()
{
	var songsTable=document.getElementById("songs_table");
	var tr,td,i,day,month,year,theDate;
	tr=songsTable.getElementsByTagName("tr");
	for (i=1; i<tr.length; i++)
	{
		td=tr[i].getElementsByTagName("td");
		if (td.length<8) continue;
		tr[i].title=td.length;
		theDate=td[5].firstChild.nodeValue;
		month=theDate.substring(0,2);
		day=theDate.substring(3,5);
		year=theDate.substring(6,8);
		td[5].title=ordinal(month,day,year);//+"="+month+"/"+day+"/"+year;
	}// end for i
}// end createOrdinalValues

function colorCode()
{
	var songsTable=document.getElementById("songs_table");
	var name=document.getElementById("artist_username");
	var tr=songsTable.getElementsByTagName("tr");
	var td,i,j,ord,m,d,y,today;
	var songCount=document.getElementById("songs");
	var count=0;
	today=new Date();
	m=today.getMonth()+1;
	d=today.getDate();
	y=today.getYear();
	m=m.toString();
	d=d.toString();
	if (y.toString().length>2) y=y.toString().substring(y.toString().length-2,y.toString().length);
	//document.title=y;
	ord=ordinal(m,d,y);
	for (i=1; i<tr.length; i++)
	{
		td=tr[i].getElementsByTagName("td");
		if (tr[i].title!="8") continue;
		tr[i].title="";
		for (j=0; j<=5; j++)
		{
			if (td[5] && ord-parseInt(td[5].title)==0)
			{
				count++;
				td[5].style.backgroundImage="url('http://www.macjams.com/chat/emoticons/fire.gif')";
				td[j].style.fontWeight="bold";
				td[j].style.color="#ff0000";
				td[j].style.fontSize="1.25em";
				td[j].style.fontFamily="comic sans ms";
				td[6].firstChild.style.color="#ff0000";
				if (td[6].firstChild.firstChild.nodeValue!="Disabled") td[6].firstChild.firstChild.nodeValue="On Fire";
				if (j==1 || j==4) 
				{
					td[j].getElementsByTagName("a")[0].style.fontWeight="bold";
					td[j].getElementsByTagName("a")[0].style.color="#ff0000";
					td[j].getElementsByTagName("a")[0].fontFamily="comic sans ms";
				}
				songCount.getElementsByTagName("legend")[0].style.backgroundImage="url('http://www.macjams.com/chat/emoticons/fire.gif')";
				songCount.getElementsByTagName("legend")[0].style.color="#ff0000";
				name.style.backgroundImage="url('http://www.macjams.com/chat/emoticons/fire.gif')";
				flashLogo();
			}		
			if (td[5] && ord-parseInt(td[5].title)==1)
			{
				td[j].style.fontWeight="bold";
				td[j].style.color="#ff0000";
				td[j].style.fontSize="1.15em";
				td[6].firstChild.style.color="#ff0000";
				if (td[6].firstChild.firstChild.nodeValue!="Disabled") td[6].firstChild.firstChild.nodeValue="Hot";
				if (j==1 || j==4) 
				{
					td[j].getElementsByTagName("a")[0].style.fontWeight="bold";
					td[j].getElementsByTagName("a")[0].style.color="#ff0000";
				}
				songCount.getElementsByTagName("legend")[0].style.color="#ff0000";
			}
			if (td[5] && ord-parseInt(td[5].title)>1 && ord-parseInt(td[5].title)<=15)
			{
				td[j].style.fontWeight="bold";
				td[j].style.color="#804000";
				td[j].style.fontSize="1.15em";
				td[6].firstChild.style.color="#804000";
				if (td[6].firstChild.firstChild.nodeValue!="Disabled") td[6].firstChild.firstChild.nodeValue="Warmer";
				if (j==1 || j==4) 
				{
					td[j].getElementsByTagName("a")[0].style.fontWeight="bold";
					td[j].getElementsByTagName("a")[0].style.color="#804000";
				}
				if (songCount.getElementsByTagName("legend")[0].style.color=="") songCount.getElementsByTagName("legend")[0].style.color="#804000";
			}		
			if (td[5] && ord-parseInt(td[5].title)>15 && ord-parseInt(td[5].title)<=30)
			{
				td[j].style.fontWeight="bold";
				td[j].style.color="#449944";
				td[j].style.fontSize="1.15em";
				td[6].firstChild.style.color="#449944";
				if (td[6].firstChild.firstChild.nodeValue!="Disabled") td[6].firstChild.firstChild.nodeValue="Warm";
				if (j==1 || j==4) 
				{
					td[j].getElementsByTagName("a")[0].style.fontWeight="bold";
					td[j].getElementsByTagName("a")[0].style.color="#449944";
				}
				if (songCount.getElementsByTagName("legend")[0].style.color=="") songCount.getElementsByTagName("legend")[0].style.color="#449944";
			}	
			if (td[5] && ord-parseInt(td[5].title)>30 && ord-parseInt(td[5].title)<=45)
			{
				td[j].style.fontWeight="bold";
				td[j].style.color="#5555dd";
				td[j].style.fontSize="1.15em";
				td[6].firstChild.style.color="#5555dd";
				if (td[6].firstChild.firstChild.nodeValue!="Disabled") td[6].firstChild.firstChild.nodeValue="Cool";
				if (j==1 || j==4) 
				{
					td[j].getElementsByTagName("a")[0].style.fontWeight="bold";
					td[j].getElementsByTagName("a")[0].style.color="#5555dd";
				}
				if (songCount.getElementsByTagName("legend")[0].style.color=="") songCount.getElementsByTagName("legend")[0].style.color="#5555dd";
			}			
			if (td[5] && ord-parseInt(td[5].title)>45 && ord-parseInt(td[5].title)<=60)
			{
				td[j].style.fontWeight="bold";
				td[j].style.color="#7777ee";
				td[6].firstChild.style.color="#7777ee";
				if (td[6].firstChild.firstChild.nodeValue!="Disabled") td[6].firstChild.firstChild.nodeValue="Cooler";
				if (j==1 || j==4) 
				{
					td[j].getElementsByTagName("a")[0].style.fontWeight="bold";
					td[j].getElementsByTagName("a")[0].style.color="#7777ee";
				}
				if (songCount.getElementsByTagName("legend")[0].style.color=="") songCount.getElementsByTagName("legend")[0].style.color="#7777ee";
			}	
			if (td[5] && ord-parseInt(td[5].title)>45 && ord-parseInt(td[5].title)>=365)
			{
				td[6].firstChild.style.color="#999999";
				if (td[6].firstChild.firstChild.nodeValue!="Disabled") td[6].firstChild.firstChild.nodeValue="ZzZzZ";
				td[6].style.cursor="help";
				td[6].title="No comments in "+(ord-parseInt(td[5].title))+" days.";
			}
		}// end for j
	}// end for i
	if (count>0) songCount.getElementsByTagName("legend")[0].firstChild.nodeValue+=" - ("+parseInt(count/6)+")";
	if (songCount.getElementsByTagName("legend")[0].style.color!="") name.style.color=songCount.getElementsByTagName("legend")[0].style.color;
	if (count>0 && cssAnimateCheck(count/6));
}// end colorCode

function cssAnimateCheck(count)
{
	var agent=navigator.userAgent.toLowerCase();
	if (agent.indexOf("safari")>=0 && agent.indexOf("version/4")>=0)
	{
		spinningNumber=document.createElement("span");
		spinningNumber.style.position="absolute";
		spinningNumber.style.zIndex=5000;
		spinningNumber.appendChild(document.createTextNode(count));
		spinningNumber.style.fontSize="70em";
		spinningNumber.style.webkitTransition="-webkit-transform 9s ease-in";
		spinningNumber.style.color="#bbbb00";
		setTimeout('spinningNumber.style.webkitTransform="rotate(3600deg)"',1000);
		spinningNumber.style.top=document.body.scrollTop+"px";
		document.body.insertBefore(spinningNumber,document.body.childNodes[0]);
		disappearingSpin();
		return true;
	}
	else return false;
}// end cssAnimateCheck

function disappearingSpin()
{ 
	disappearCount++;
	var fSize=70-(disappearCount * .85);
	var opac=1-(disappearCount * .0225);
	spinningNumber.onclick=function() {
		spinningNumber.style.display="none";
	}
	spinningNumber.style.fontSize=fSize+"em";
	spinningNumber.style.opacity=opac;
	spinningNumber.style.left="45%";
	spinningNumber.style.top=document.body.scrollTop+"px";
	if (disappearCount<36) setTimeout("disappearingSpin()",250);
	else spinningNumber.style.display="none";
}// end disappearingSpin

function displayTodaysSongs()
{
/*
	var songsTable=document.getElementById("songs_table");
	var i,j,td,tr,row,cell,a,element,table,month,day,year,today,text;
	tr=songsTable.getElementsByTagNAme("tr");
	month=Date().getMonth()+1;
	day=Date().getDate();
	year=Date().getYear();
	today=month+"."+day+"."+year;
	table=document.createElement("table");
	table.setAttribute("align","center");
	table.setAttribute("id","new_song_table");
	table.setAttribute("border","1");
	for (i=1; i<tr.length; i++)
	{
		td=tr[i].getElementsByTagName("td");
		if (td[0].firstChild.nodeValue==today)
		{
			row=document.createElement("tr");
			cell=document.createElement("td");
			
		}
	}// end for i
*/
}// end displayTodaysSongs

function ordinal(m,d,y)
{
	var value=0;
	var i;
	var leapYear=0;
	var previousYears=0;
	if (m.charAt(0)=="0") m=m.charAt(1);
	if (d.charAt(0)=="0") d=d.charAt(1);
	if (y.charAt(0)=="0") y=y.charAt(1);
	y=parseInt(y)+2000;
	d=parseInt(d);
	m=parseInt(m);
	if (y % 4 == 0) leapYear=1;
	for (i=1; i<m; i++)
	{
		if (i==9 || i==4 || i==6 || i==11) value+=30;
		else if (i==2) value+=(28+leapYear);
		else value+=31;
	}// end for i
	value+=d;
	for (i=2004; i<y; i++)
	{
		previousYears+=365;
		if (i%4==0) previousYears++;
	}
	return parseInt((value+previousYears));
}// end ordinal
