
// Console escape (MSIE, etc.)
if (!console) var console = { log: function(){} };

var global_FlashVersion = Browser.Plugins.Flash.version; // Retrieve global Flash Version (MOOTools)
var ewDialog;



/**
* Enhance author links
*/
function enhanceAuthorLinks()
{
	enhanceLinkContainers($$('#author_list li'));
}

/**
* Enhance "most recent" link
*/
function enhanceMostRecentLink()
{
	enhanceLinkContainers($$('#most_recent'));
}

/**
* Loops through passed in elements (array), finds the first child link within each element and
* adds a 'click' event to the passed in element, causing the element go to the link's href location.
* @param	links	Array - elements, within which, to look for child links
*/
function enhanceLinkContainers(links)
{
	// Loop through links
	links.each(function(instance, i)
	{
		var innerLink, href;
		
		try
		{
			innerLink = instance.getElement('a');
		}
		catch(exception){ /* no link found */ }
		
		// Proceed if innerLink is defined
		if (innerLink)
		{		
			// Set cursor style, assuming child link exists
			instance.setStyle('cursor', 'pointer');
			
			// Add click event to parent
			instance.addEvent('click', function(e)
			{
				try
				{
					href = innerLink.get('href');
				}
				catch(exception)
				{
					href = '#';
				}
				
				window.location.href = href;
			}.bind(this));
		}
	}.bind(this));	
}

function replaceFlashPreviewVideo()
{
    // Store reference (if element exists)
    var previewElement = $('video_preview');
    
    // Verify that messaging element exists
    if (previewElement)
    {
		var mediaData 	= previewElement.getElement('span').get('text');	
        var swfPath 	= setSwfPath('/flash/video_player_blog.swf');
			
		var temp 		= mediaData.split('|');
		var filename 	= temp[1];
		var producer 	= temp[0];
		var mediaID 	= temp[2];
		var loopable;
		
		if (temp[3])
			loopable	= temp[3]; 
		
		var rtmpURI 	= 'rtmp://easyworship.com/ew_store/';
		var videoURI	= 'mp4:previews/' + producer + '/flv/' + filename; 
		var screenURI	= 'http://www.easyworship.com/stills/imagepreview/id/' + mediaID;
		
        // Embed SWF
        new Swiff(swfPath,
        {
            id: 'video_preview_swf',
            container: previewElement,
            width: 488,
            height: 274,
            params: {
                wmode: 		'transparent',
                bgcolor: 	'#000000'
            },
			vars: {
				rtmpURI:	rtmpURI,	
				videoURI:	videoURI,
				screenURI:	screenURI,
				loopable:	loopable
			}
        });
    }
}

function setSwfPath(swfPath)
{
    // Verify Flash Major Version
    if (global_FlashVersion && global_FlashVersion < 9)
    {
        // Does not meet minimum player requirements, load expressInstall
        swfPath = '/flash/expressInstall.swf';
    }
	
	return swfPath;
}


/**
* DOM is ready for manipulation
*/
function onDOMReady()
{
	enhanceAuthorLinks();
	enhanceMostRecentLink();
	replaceFlashPreviewVideo();
	
	ewDialog = new Dialog($$('.dialog_link'));
}

// Add window domready event
window.addEvent('domready', onDOMReady);




