InsertFlashBanner = function()
{
	var theImg    = $('home_banner_img');
	var theSrc    = theImg.getProperty('src')+"";
	var theLast   = theSrc.lastIndexOf(".");
	
	if(-1<theLast)
	{
		var theFlashSrc = theSrc.substring(0,theLast)+".swf";
		var theFlash = new Swiff(theFlashSrc, {
			id: theImg.getProperty('id')+'_flash',
			container: theImg.getParent(),
			width: theImg.getProperty('width'),
			height: theImg.getProperty('height'),
			params: {wMode: 'opaque'}
		});
	}
};

InitEditorials = function()
{
	var theEds = $$('.editorial').each(function(anEd)
	{
		var theLoc      = anEd.getCoordinates();
		var theChildren = anEd.getChildren();
		
		// Gather absolute positioning of elements
		var theImgSize	= {'height': theChildren[0].get('height'),'width':theChildren[0].get('width')};
		var theOffSize	= theChildren[1].getSize();
		var theOnSize	= theChildren[2].getSize();
		
		// Account for border, etc. things if the image is bigger than the container 
		var theAdj      = (theImgSize.height > theLoc.height) ? -4 : 0;
		var theOffY		= -theOffSize.y - Math.abs(theImgSize.height - theLoc.height) + theAdj;
		var theOnY		= -theOnSize.y  - Math.abs(theImgSize.height - theLoc.height) + theAdj;
		
		// Clear out the alt/title tags so they don't pop up and annoy users
		theChildren[0].set('alt','');
		theChildren[0].set('title','');
		
		// Position the text for follover states
		theChildren[1].setStyles({
			'position': 'relative',
			'display': 'block',
			'top': theOffY,
			'left': "5px"
		});
		theChildren[2].setStyles({
			'position': 'relative',
			'display': 'block',
			'top': theOnY,
			'left': "5px",
			'display': 'none'
		});
		
		// Set dark bg to fake shading out on rollover
		anEd.setStyle('background','#000');
		
		// Let's make rollover states
		anEd.addEvents({
			'mouseover': function()
			{
				theChildren[0].setStyle('opacity',0.3);
				theChildren[1].setStyle('display','none');
				theChildren[2].setStyle('display','block');
			},
			'mouseout': function()
			{
				theChildren[0].setStyle('opacity',1);
				theChildren[1].setStyle('display','block');
				theChildren[2].setStyle('display','none');
			}
		});
	});
}

window.addEvent('domready',function()
{
	InitEditorials();
	InsertFlashBanner();
	//$$('body').setStyle('opacity', 0.9999);  // Fix flicker on Fx2/Mac - Kills Flash insert
});