var isMac = (navigator.platform.toLowerCase().indexOf("mac") != -1) ? true : false;

function openWindow(url,name,width,height,resizable,scrollbars,statusbar,menubar,toolbar)
{
	var win = (window.name) ? eval(name) : null;
	var optionString = "";
	if (width) optionString += "width=" + width + ",";
	if (height) optionString += "height=" + height + ",";
	if (resizable) optionString += "resizable=" + resizable + ",";
	if (scrollbars) optionString += "scrollbars=" + scrollbars + ",";
	if (statusbar) optionString += "statusbar=" + statusbar + ",";
	if (menubar) optionString += "menubar=" + menubar + ",";
	if (toolbar) optionString += "toolbar=" + toolbar + ",";
	win = window.open(url,name,optionString);
	win.focus();
}

function openImageWin(img,width,height)
{
	openWindow("Image.aspx?i=" + img,'Image', width, height, 1, 1, 0, 0, 0);
}

function clearForm(theForm)
{
	for (i=0; i<theForm.elements.length; i++)
	{
		switch (theForm.elements[i].type)
		{
			case "text" :
				theForm.elements[i].value = "";
				break;
			case "textarea" :
				theForm.elements[i].value = "";
				break;
			case "select-one" :
				theForm.elements[i].selectedIndex = 0;
				break;
			case "select-multiple" :
				for (j=0; j<theForm.elements[i].options.length; j++)
					theForm.elements[i].options[j].selected = false;
				break; 
			case "checkbox" :
				theForm.elements[i].checked = false;
				break;
			case "radio" :
				theForm.elements[i].checked = false;
				break;
		}
	}
}

function resetForm(theForm)
{
	theForm.reset();
}

var audioPath = "http://www.marshmallowmusic.com/media/";
var videoPath = "http://www.marshmallowmusic.com/media/";

var audioFiles = new Array();
audioFiles[audioFiles.length] = new Array("Anytime Soon", "anytime_soon");
audioFiles[audioFiles.length] = new Array("Come Sunday", "come_sunday");
audioFiles[audioFiles.length] = new Array("Scooter Girl", "scooter_girl");
audioFiles[audioFiles.length] = new Array("Snow", "snow");
audioFiles[audioFiles.length] = new Array("Do the Decent Thing", "do_the_decent_thing");
audioFiles[audioFiles.length] = new Array("Interlude", "interlude");
audioFiles[audioFiles.length] = new Array("Let Me Love You (Like There's No Tomorrow)", "let_me_love_you");
audioFiles[audioFiles.length] = new Array("Casting Couch", "casting_couch");
audioFiles[audioFiles.length] = new Array("Open Mic Night", "open_mic_night");
audioFiles[audioFiles.length] = new Array("Over & Done", "over_and_done");
audioFiles[audioFiles.length] = new Array("The Ballad of Wendi Deng", "the_ballad_of_wendi_deng");
audioFiles[audioFiles.length] = new Array("Born Again", "born_again");
audioFiles[audioFiles.length] = new Array("Later On", "later_on");

function writeFeatureTrack()
{
	var randomTrack = audioFiles[Math.round(Math.random() * 10)];
	var img = "<img src=\"images/song_" + randomTrack[1] + ".gif\" alt=\"" + randomTrack[0] + "\" border=\"0\" vspace=\"3\" /><br />"
	var holder = document.getElementById("featureTrack");
	holder.innerHTML = "<a href=\"javascript:openWindow('Audio.aspx?a=" + randomTrack[1] + "','win',480,480,0,1,0,0,0);\">" + img + "</a>";
}

function writeTrack(track)
{
	var holder = document.getElementById("audioPlayer");
	holder.innerHTML = "";
	if (isMac)
	{
		holder.innerHTML += getAudioHTML(track + ".mp3", "100%", 16);
	}
	else
	{
		holder.innerHTML += getAudioHTML(track + ".mp3", "100%", 45);
	}
}

function getAudioHTML(trackName, width, height)
{
	var mediaHTML = "";
	if (isMac)
	{
		mediaHTML += "<obj" + "ect classid=\"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\" width=\"" + width + "\" height=\"" + height + "\" codebase=\"http://www.apple.com/qtactivex/qtplugin.cab\">";
		mediaHTML += "	<param name=\"src\" value=\"" + audioPath + trackName + "\" />";
		mediaHTML += "	<param name=\"autoplay\" value=\"false\" />";
		mediaHTML += "	<param name=\"controller\" value=\"true\" />";
		mediaHTML += "	<embed src=\"" + audioPath + trackName + "\" width=\"" + width + "\" height=\"" + height + "\" autoplay=\"false\" controller=\"true\" pluginspage=\"http://www.apple.com/quicktime/download/\"></embed>";
		mediaHTML += "</object>";
	}
	else
	{
		mediaHTML += "<obj" + "ect classid=\"CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6\" width=\"" + width + "\" height=\"" + height + "\">";
		mediaHTML += "	<param name=\"URL\" value=\"" + audioPath + trackName + "\" />";
		mediaHTML += "	<param name=\"autoStart\" value=\"false\" />";
		mediaHTML += "	<embed type=\"application/x-mplayer2\" src=\"" + audioPath + trackName + "\" width=\"" + width + "\" height=\"" + height + "\" AutoStart=\"false\" pluginspage=\"http://www.microsoft.com/MediaPlayer/\"></embed>";
		mediaHTML += "</object>";
	}
	return "<div class=\"mediaplayer\">" + mediaHTML + "</div>";
}

function getVideoHTML(trackName, width, height)
{
	var mediaHTML = "";
	mediaHTML += "<object id=\"Player\" width=\"" + width + "\" height=\"" + (height + 18) + "\" classid=\"CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6\">";
	mediaHTML += "	<param name=\"URL\" value=\"" + videoPath + trackName + "\" />";
	mediaHTML += "	<param name=\"autoStart\" value=\"True\" />";
	mediaHTML += "	<embed width=\"" + width + "\" height=\"" + height + "\" type=\"application/x-mplayer2\" src=\"" + videoPath + trackName + "\" controller=\"true\" autoplay=\"true\" pluginspage=\"http://www.microsoft.com/MediaPlayer/\"></embed>";
	mediaHTML += "</object>";
	return "<div class=\"mediaplayer\" style=\"width:" + width + "px;\">" + mediaHTML + "</div>";
}
