/**
*	SimpPlay, copyright Kasimir Pihlasviita 2009
*	changes links to mp3 files to simple flash players
*/
var SimpPlay = {

	// count of the inserted players, used for ids
	instanceCount : 0,
	// if different size is required, change these before init
	// e.g. SimpPlay.sizeX = 15;
	sizeX : 10,
	sizeY : 10,

	init : function() {
		// loop through all <a> elements in the document
		$$('a').each(function(el) {
			// create test string from href and text content of the link
			var str = el.href + (el.innerText || el.textContent);
			// does the href or text content contain ".mp3"?
			if (str.indexOf(".mp3") != -1) {
				// create a <span> and attach it before the link
				// the swf will be replaced in its place
				var spanId = "SimpPlayInstance" + ++SimpPlay.instanceCount;
				var span = new Element('span', { id : spanId });
				el.up().insertBefore(span, el);
				// insert the swf
				// last argument is flashVars:
				// the links href is assigned to soundURL
				swfobject.embedSWF(
					"/pub/s/pinja/simpplay.swf",
					spanId,
					SimpPlay.sizeX,
					SimpPlay.sizeY,
					"6.0.0",
					false,
					{ soundURL : el.href });
				// attach event listener to the link
				// on click invoke playPauseSong() of the swf before the link
				// stop the click event to prevent normal loding of the link
				el.observe('click', function(evt) {
					this.previous().playPauseSong();
					evt.stop();
				});

			}
		});
	}
};

// on load invoke SimpPlay.init()
Event.observe(window, 'load', function() {
	SimpPlay.init();
});
