// Youtube video embeded selector
// By Nestor Lafon-Gracia
//
// Usage:
//  randomYoutube(ids)
//  ids: String with list of video ids separated by a space or comma
function randomYoutube(ids)
{
	idPositionStart = 0; 
	idIndex = 0;
	videoArray = new Array();
	idsLength = ids.length;
  
	for ( iterator = 0; iterator < idsLength; iterator++) 
	{
		if (ids.charAt(iterator) == ' ') 
		{
			videoArray[idIndex] = ids.substring(idPositionStart,iterator);
			idPositionStart = iterator + 1;
			idIndex++;
		}
    }
	
	// Doesn't end with a separator, so take for the idPosition start till the end
	if ( idPositionStart != idsLength )
	{
		videoArray[idIndex] = ids.substring(idPositionStart, idsLength);
		idIndex++;
	}
	
	i = Math.floor(Math.random() * idIndex);
	document.write("  <object width=\"320\" height=\"256\"><param name=\"movie\" value=\"http://www.youtube.com/v/" + videoArray[i] + "\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"http://www.youtube.com/v/" + videoArray[i] + "\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"320\" height=\"256\"></embed></object>")
}