﻿function func_getwindowsize()
	{
	//	Try to get the height of the window
	ThisWindowHeight='';
	try
		{
		ThisWindowHeight=onlyNumeric(''+window.innerHeight)
		}
	catch(err)
		{
		ThisWindowHeight='';
		}
	if (ThisWindowHeight=='')
		{
		ThisWindowHeight=onlyNumeric(''+window.mainbody.clientHeight)
		}
	//	Try to get the width of the window
	ThisWindowWidth='';
	try
		{
		ThisWindowWidth=onlyNumeric(''+window.innerWidth)
		}
	catch(err)
		{
		ThisWindowWidth='';
		}
	if (ThisWindowWidth=='')
		{
		ThisWindowWidth=onlyNumeric(''+window.mainbody.clientWidth)
		}
	}
function PaintBgImage(par)
	{
	//Center background image
   	obj=document.getElementById(par);
	LogoTop=ThisWindowHeight/8;
   	UseSize=ThisWindowHeight/1.5;
   	//alert(obj.style.top+LogoTop);
   	obj.style.top=LogoTop;
   	obj.style.left=(ThisWindowWidth/2)-(UseSize/2);
   	obj.style.height=UseSize;
   	obj.style.width=UseSize;
	}
LogoSize=1;
function PaintLogo(par)
	{
	//Center background image
	obj=document.getElementById('Logo87PM');
	//obj=Logo87PM;
   	UseSize=ThisWindowHeight/1.5
   	GrowSize=ThisWindowHeight/2
   	obj.style.left=((ThisWindowWidth/2)-(UseSize/2)+((UseSize-LogoSize)/2));
   	LogoTop=ThisWindowHeight/8;
   	obj.style.top=LogoTop+((UseSize-LogoSize)/2);
   	obj.style.height=LogoSize;
   	obj.style.width=LogoSize;
   	LogoSize+=1;
   	if(LogoSize<GrowSize)
   		{
   		//Continue resizing
   	  	window.setTimeout("PaintLogo('Logo87PM');", 0);
   	  	}
	}
	
function func_ExpandToCenter_Loop(par, CD_GrowAmount)
	{
	//Center background image
	obj=document.getElementById(par);
	//alert (par+"-"+obj.id);
   	obj.style.left=((ThisWindowWidth/2)-(UseSize/2)+((UseSize-LogoSize)/2));
   	LogoTop=ThisWindowHeight/8;
   	obj.style.top=LogoTop+((UseSize-LogoSize)/2);
   	obj.style.height=LogoSize;
   	obj.style.width=LogoSize;
	LogoSize+=CD_GrowAmount;
	TRACKLIST_Left+=TRACKLIST_MoveAmount;
	document.getElementById('tracklist').style.left=TRACKLIST_Left;
   	if((CD_GrowAmount>=1 && LogoSize<CD_GrowSize) || (CD_GrowAmount<=-1 && LogoSize>1))
   		{
   		//Continue resizing
   	  	window.setTimeout("func_ExpandToCenter_Loop('" +obj.id+"',"+CD_GrowAmount +");", CD_GrowSpeed);
   	  	}
   	else if (CD_GrowAmount<=-1)
   		{
   		//alert('Y');
   		//Verberg de geminimaliseerde image
   		obj.style.left=-200;
   		//document.getElementById('tracklist').style.left=-2000;
   		}
   	else
   		{
   		//Do we need to show the tracklist?
   		if (LogoSize>10)
   			{
   			//alert('ZZ');
   			}
   		}
	}
	
function func_ExpandToCenter(par)
	{
	//Open or close the cd
	obj=document.getElementById(par);
   	UseSize=ThisWindowHeight/1.5
   	CD_GrowSize=ThisWindowHeight/1.5
   	CD_GrowSteps=100;
   	CD_GrowTime=1000;
   	CD_GrowAmount=CD_GrowSize/CD_GrowSteps;
   	CD_GrowSpeed=CD_GrowTime/CD_GrowSteps;
   	TRACKLIST_TargetLeft=(onlyNumeric(document.getElementById('EarthGlobe').style.left)/2)-100;
	document.getElementById('tracklist').style.width=200;
	document.getElementById('tracklist').style.top=document.getElementById('EarthGlobe').style.top;
	//document.getElementById('tracklist').style.left=TRACKLIST_StartFrom;
	//alert (par+"-"+obj.id);
	//alert('X'+par+obj.style.width);
	if (onlyNumeric(''+obj.style.width)<=10)
		{
		//Position tracklist
	   	TRACKLIST_StartFrom=-300;
	   	TRACKLIST_Left=TRACKLIST_StartFrom;
	   	TRACKLIST_MoveAmount=(TRACKLIST_TargetLeft-TRACKLIST_StartFrom)/CD_GrowSteps;
		//Fill tracklist
		document.getElementById('tracklist').innerHTML='Loading tracks...';
		if (par=="OceanCoast")
			{
			loadXMLDoc('files/tracklist2.xml', 'Ocean Coast')
			}
		else
			{
			loadXMLDoc('files/tracklist2.xml', 'Earth Summit')
			}
		//Expand
		LogoSize=1;
		obj.style.height=LogoSize;
		obj.style.width=LogoSize;
		func_ExpandToCenter_Loop(''+obj.id, CD_GrowAmount);
		}
	else
		{
		//Position tracklist
	   	TRACKLIST_MoveAmount=-TRACKLIST_MoveAmount;
		//Decrease
		LogoSize=obj.style.height=LogoSize;
		func_ExpandToCenter_Loop(obj.id, -CD_GrowAmount);
		}
	}
	
function bgDisco(lastval)
	{
	//var  x =Math.round(255*Math.random());
	lastval = lastval + 1;
	if (lastval >= 250)
		{
		lastval = 150;
		}
	document.body.style.background="#"+getHex(lastval)+getHex(lastval)+getHex(lastval);
	setTimeout("bgDisco(" + lastval + ")",1000);
	}
function getHex(dec)
	{ 
	var hexArray = new Array( "0", "1", "2", "3","4", "5", "6", "7","8", "9", "A", "B","C", "D", "E", "F" ); 
	var code1 = Math.floor(dec / 16);
	var code2 = dec - code1 * 16; 
	var decToHex = hexArray[code2]; 
	return (decToHex); 
	}
function triggerFX()
	{
	//	********************************************************************************************************************
	//	** Main trigger code for all actions *******************************************************************************
	//	********************************************************************************************************************
	func_getwindowsize()
	Hmove=1;
	MoveSteps=400;
	CD_Button_StartSize=ThisWindowHeight/3;
	CD_Button_Size=CD_Button_StartSize;
	CD_Button_MinSize=ThisWindowHeight/8;
	CD_Button_SizeStep=(CD_Button_StartSize-CD_Button_MinSize)/MoveSteps
	CD_LeftPos=-CD_Button_StartSize;
	CD_LeftPos_End=ThisWindowWidth-180;
	CD_LeftPos_Step=onlyNumeric(''+CD_LeftPos_End)/MoveSteps;
	//colorFade('mainbody','background','999999','d8e6ee', 25, 100);	
	//func_setvars()
	PaintBgImage('EarthGlobe');
	PaintLogo('Logo87PM');
	document.getElementById('EarthBlue').style.top=1;
	moveObjRight('EarthBlue');
	document.getElementById('EarthGreen').style.top=ThisWindowHeight-180;
	moveObjRight('EarthGreen');
	//moveObjRight(JS);
	runningFX();
	}
function runningFX()
	{
	colorLoop('colorthis','background','dddddd','d8e6ee', 25, 100);
	//alert('1');
	//colorFade('colorthis','background','d8aaaa','ee00ee', 25, 100);
	//alert('2');
	//runningFX();
	}
function func_giveinfo()
	{
	alert('Info: ' + ThisWindowWidth);
	}
	
func_getwindowsize()
Hmove=1;
MoveSteps=400;
CD_Button_StartSize=ThisWindowHeight/3;
CD_Button_Size=CD_Button_StartSize;
CD_Button_MinSize=ThisWindowHeight/8;
CD_Button_SizeStep=(CD_Button_StartSize-CD_Button_MinSize)/MoveSteps
CD_LeftPos=-CD_Button_StartSize;
CD_LeftPos_End=ThisWindowWidth-180;
CD_LeftPos_Step=onlyNumeric(''+CD_LeftPos_End)/MoveSteps;

function moveObjRight(par)
	{
	//Move menu circles right
	//varCompl=(window.mainbody.clientWidth-180)/Hmove;
	obj=document.getElementById(par);
   	obj.style.left=Hmove;
   	obj.style.height=CD_Button_Size;
   	obj.style.width=CD_Button_Size;
   	UseSize=ThisWindowHeight/1.5;
   	if (obj.id=='EarthBlue')
   		{
   		obj.style.top=document.getElementById('EarthGlobe').style.top;
   		}
   	if (obj.id=='EarthGreen')
   		{
   		LogoTop=ThisWindowHeight/8;
   		obj.style.top=LogoTop+UseSize-CD_Button_Size;
   		}
   	//Hmove+=1;
   	Hmove += CD_LeftPos_Step;
   	CD_Button_Size=CD_Button_Size-CD_Button_SizeStep;
   	if (CD_Button_Size <=10)
   		{
   		CD_Button_Size = 10;
   		}
   	if(Hmove<CD_LeftPos_End)
   		{
   		//Continue moving right
   	  	window.setTimeout("moveObjRight('" +obj.id+ "');", 5);
   	  	}
   	else
   		{
   		//Finished - trigger next animation
   		displayMenu('mainmenu');
   		//expandcloseMenu(EarthBlue);
   		}
	}
function expandcloseMenu(obj,par)
	{
   	if (par==0)
   		{
   		//alert('Testx!'+par+'-'+onlyNumeric(''+EarthBlue.style.left)+'-'+(window.mainbody.clientWidth/2));
   		//Determine whether the object needs to be moved left or right
   		if (onlyNumeric(''+EarthBlue.style.left) > (onlyNumeric(''+ThisWindowWidth)/2))
   			{
   			//alert('Test x!'+par);
   			expandcloseMenu(EarthBlue.id,-1)
   			}
   		else
   			{
   			//alert('Test y!'+par);
   			expandcloseMenu(EarthBlue.id,1)
   			}
   		}
   	else
   		{
	   	//alert('Test!'+par);
	   	EarthBlue.style.left=Hmove;
	   	EarthGreen.style.left=Hmove;
	   	UseSize=ThisWindowHeight/1.5;
	   	Hmove=Hmove+par;
	   	if( (par==-1 && Hmove>180) || (par==1 && Hmove<(ThisWindowWidth-180)) )
	   		{
	   		//Continue moving object
	   	  	window.setTimeout("expandcloseMenu(" +EarthBlue.id+ ", " + par + ");", 0);
	   	  	}
	   	else
	   		{
	   		//Finished - trigger next animation
	   		//displayMenu(mainmenu);
	   		}
	   	}
	}
function displayMenu(par)
	{
	obj=document.getElementById(par);
	obj.style.backgroundColor='#000000';
   	UseSize=ThisWindowHeight/1.5;
   	UseHeight=ThisWindowHeight;
   	UseWidth=ThisWindowWidth;
	obj.style.left=20;
	obj.style.width=UseWidth-40;
	obj.style.top=UseHeight-100;
	obj.style.height=80;
	colorFade('mainmenu','background','000000','d8e6ee')
	}
function onlyNumeric(par)
	{
	//Only allow numerical parts of a string to return (used to strip some returned size of the px appendage)
	//par='123px';
	newValue=''
	allowedChar='1234567890.,'
	for (i=0;i<=(par.length-1);i++)
		{		
		ll=par.substring(i,i+1);
		//alert('Text: ' + par.substring(i,i+1));
		if (allowedChar.indexOf(ll)>=0)
			{
			//alert('Ok: ' + par.substring(i,i+1));
			newValue=newValue+ll;
			}
		}
	//alert('New: '+newValue);
	return newValue;
	}

function loadXMLDoc(url,cd_name)
	{
	var xmlhttp;
	var txt,x,xx,i;
	if (window.XMLHttpRequest)
		{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
		}
	else
		{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	xmlhttp.onreadystatechange=function()
		{		
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
			//We have received the XML data
			//Determine which index we need to search for files
			txt="<table border='0'>";
			//Determine which index we need to search for files
			x=xmlhttp.responseXML.documentElement.getElementsByTagName("CD");			
			cdindex=-1
			for (i=0;i<x.length;i++)
				{
				xx=x[i].getElementsByTagName("TITLE");
				if (xx.length>0)
					{
					if (xx[0].firstChild.nodeValue==cd_name)
						{
						cdindex=i;
						break;
						}
					}
				}
			//alert (cdindex);    
			//xx=x[0].getElementsByTagName("TITLE");
			//xxx=xx[0].getElementsByTagName("NO");
			//alert (xxx[0].firstChild.nodeValue);
			if (cdindex > -1)
				{
				//Get album title				
				xx=x[cdindex].getElementsByTagName("TITLE");
				if (xx.length>0)
					{
					txt=txt+"<tr class='headerrow'><td>" + xx[0].firstChild.nodeValue + "</td></tr>"
					}
				xx=x[cdindex].getElementsByTagName("SUBFLDER");
				if (xx.length>0)
					{
					subf=xx[0].firstChild.nodeValue;
					}
				tracks=x[cdindex].getElementsByTagName("TRACK");
				//alert (tracks.length);
				for (i=0;i<tracks.length;i++)
					{
					txt=txt + "<tr>";
					track_name='';
					track_file='';
					xx=tracks[i].getElementsByTagName("TITLE");
					if (xx.length>0)
						{
						track_name=''+xx[0].firstChild.nodeValue;
						}
					xx=tracks[i].getElementsByTagName("FNAME");
					if (xx.length>0)
						{
						track_file=xx[0].firstChild.nodeValue;
						if (track_file.length>1)
							{
							track_file='files/'+subf+'/'+track_file;
							track_file=track_file.replace(' ', '%20');
							}
						else
							{
							track_file='';
							}
						}
					txt=txt + '<td>';
					if (track_file.length > 0)
						{
						txt=txt + "<a href='" + track_file + "' target=_blank>" + track_name + "</a>";
						}
					else
						{
						txt=txt + track_name;
						}
					txt=txt + "</td>";
					txt=txt + "</tr>";
					}
				txt=txt + "</table>";
				//alert(txt);
				document.getElementById('tracklist').innerHTML=txt;
				}
		}
	}
xmlhttp.open("GET",url,true);
xmlhttp.send();
}

