/*
	Author: Alejandro Caduceus
	Created On: 2011-11-28
	Revised On:
	CSS Version: 2.1
	
	heavely borrowed from javascriptkit.com
	
	Purpose: create a script that performs an audible function in an HTML document
	
	Related Files:	playsound.js, (These scripts were borrowed from SoundCloud - sc-player.js, soundcloud.player.api.js)
					main.css, (These styles were borrowed from SoundCloud - color-green.css, structure-horizontal.css)
					logo.png, logoback.png, bg.jpg, (These images were borrowed from SoundCloud - pause-green.png, pause-green-hover.png, play-green.png, play-green-hover.png)
					(This soundbite was borrowed from FruityLoops10 - ride.wav, ride.ogg, ride.mp3)
					
					
						
	The example for this script came from this link -- http://www.javascriptkit.com/script/script2/soundlink.shtml#current
	The example demonstrates the ability of the script to correctly determine which if any file to play onMouseOver.
	More info at the bottom.***********
	
*/


var audioType = {"wav": "audio/wav", "mp3": "audio/mpeg", "ogg": "audio/ogg"}//create a variable named wav of tpe audio

var browsersChoice = createSoundbite("./sound/ride.wav", "./sound/ride.ogg", "./sound/ride.mp3")//plug the audio file into the variable

function createSoundbite()// this function originally attempted to determine which of 3 file types to send to the browser
{
	var html5audio = document.createElement('audio')//establishes the variable for which the file type will be associated
	
	if (html5audio.canPlayType)//determines whether the browser supports the audio function
	{
		for (var i = 0; i < arguments.length; i++)//loops till it determines the correct file type
		{
			var sourceel = document.createElement('source')
			sourceel.setAttribute('src', arguments[i])
			
			if (arguments[i].match(/\.(\w+)$/i))
				sourceel.setAttribute('type', audioType[RegExp.$1])
			html5audio.appendChild(sourceel)//a winner has been choosen, hooray ... or not
		}//end for
		html5audio.load()
		html5audio.playclip = function()//sends the choosen one to playclip;
		{
			html5audio.pause()
			html5audio.currentTime = 0
			html5audio.play()
		}//end function
		return html5audio
	}// end if
	else//if no match is found an error message is displyed
	{
		return {playclip:function(){throw new Error("Your browser doesn't support HTML5 audio unfortunately")}}//throw ?
	}//end else
}//end createSoundbite


// Mouseover/ Click sound effect- by JavaScript Kit (www.javascriptkit.com)
// Visit JavaScript Kit at http://www.javascriptkit.com/ for full source code

//** Usage: Instantiate script by calling: var uniquevar=createsoundbite("soundfile1", "fallbackfile2", "fallebacksound3", etc)
//** Call: uniquevar.playclip() to play sound

