//
// Phil (and Joe)'s Super Amazing Flowplayer Plugin..
// This bit of grotty javascript is to make it easy to embed videos in web pages by creating
// special div tags with a class "mce-flowplayer", and some cunning stuff in the ID tag.
// This function recursively traverses the DOM looking for these and does the magic javascript
// to get the video playing using flowplayer and flashembed.
//

//
// Copyright 2008, Philip Scott. All rights reserved.
//

function doSubstitution(node,depth)
{ 
    if(node.attributes != null && node.attributes["class"] != null && node.attributes["class"].value == "mce-flowplayer")
    {
      	id = node.attributes["id"].value;
        info = eval('(' + id + ')');
        
      	newid = "flowplayer" + Math.floor(Math.random()*1000000000);
      	node.id = newid;
//		node.setAttribute("style", "width:" + info.width + "px;height:" + info.height + "px;")
      	node.style.cssText = "width:" + info.width + "px;height:" + info.height + "px;"
      	// delete any child nodes as this confuses flowplayer
        if ( node.hasChildNodes() )
        {
            while ( node.childNodes.length >= 1 )
            {
                node.removeChild( node.firstChild );       
            } 
        }      	
        flowplayer(newid, "/files/flash/flowplayer-3.2.2.swf", {	plugins: {
		controls: {
			url: 'flowplayer.controls-3.2.1.swf',
			
			buttonColor: 'rgba(0, 0, 0, 0.9)',
			buttonOverColor: '#1383c5',
			backgroundColor: '#f89337',
			backgroundGradient: 'medium',
			sliderColor: '#e77038',
			
			sliderBorder: '1px solid #808080',
			volumeSliderColor: '#e77038',
			volumeBorder: '1px solid #808080',
			
			timeColor: '#000000',
			durationColor: '#535353'
		}
	}, playlist: [info.image, {url: info.video, autoPlay: false}] });	
    }
    
    for(var local_i = 0; local_i < node.childNodes.length; local_i++)
    {
        doSubstitution(node.childNodes[local_i], depth+1);
    }
}

window.addEvent('domready', function() {
     doSubstitution(document.documentElement,0);
});