$(document).ready(function() {
	var playerHeight = $("#divPlayer").outerHeight(true) + 20; // 22 IS ARBITARY NUMBER OBTAINED BY TESTING DIFFERENT BROWSERS
	var wHeight = $(window).height();
	$("#ifrSite").attr("height", wHeight - playerHeight);
	
	$(window).resize(function() {
		var wWidth = $(window).width();
		var wHeight = $(window).height();
		$("#ifrSite").attr("width", wWidth);
		$("#ifrSite").attr("height", wHeight - playerHeight);
	}); // window.resize
	
	removeAudio = function() {
		document.getElementById("html5player").pause();
		document.getElementById("playerContainer").innerHTML = "";
	}; // removeAudio
	
	createAudio = function(filename) {
		var browser = navigator.userAgent;
		if (browser.match("Chrome") || browser.match("Safari")) {
			filename = filename + ".mp3"; // CHROME AND SAFARI SUPPORT MP3 FORMAT
		} // if
		else if (browser.match("Firefox") || browser.match("Opera")) {
			filename = filename + ".ogg"; // FIREFOX AND OPERA SUPPORT OGG FORMAT
		} // else if
		
		var audioElement = document.createElement("audio");
		audioElement.id = "html5player";
		audioElement.controls = "controls";
		audioElement.src = "/songs/files/" + filename;
		document.getElementById("playerContainer").appendChild(audioElement);
		audioElement.play();
	}; // createAudio
	
	$("#song").change(function() {
		removeAudio();
		createAudio($(this).val());
	}); // #song.change
	
	var flashCallback = function(e) {
		if (!(e.success)) {
			$("#divPlayer").html("<p id=\"pSorry\">Sorry, your browser does not support audio playback</p>");
		} // if
	}; // flashCallback
	
	var a = document.createElement("audio");
	if (!(a.play)) {
		// ATTEMPT TO CREATE FLASH PLAYER
		var swfURL = "http://www.thedominorally.com/songs/player/zdominoplayer.swf";
		var flashvars = {};
		var params = {};
		var attributes = {};
		swfobject.embedSWF(swfURL, "divPlayer", "960", "32", "9", false, flashvars, params, attributes, flashCallback);
	} // if
	else {
		var filename = $("#song").find("option").eq(0).attr("value");
		createAudio(filename);
		document.getElementById("html5player").pause();
	} // else
}); // document.ready

