	
	/*
	JS
	--------------------------------------------------------------------------------------------  
	@site				sho.com (v5)
	@file				Cosmetics.js
	@author			dpaul
	@modified		01.08.09
	@desc				Adjusts the layout by overcoming some CSS limitations 
	@desc				Adds rounded corners effect to specified modules, normalizes column heights,
	@desc				and handles PNG replacement in masthead. (IE6 only).
	@depend		Prototype,SHO.Utils
	
	/* =:Cosmetics
	-------------------------------------------------------------------------------------------- */  
	if( SHO == undefined ) var SHO = {};
	
	SHO.Cosmetics = function()
	{	
		/* =:Private
		  -----------------------------------------------------------------------------------------*/  
		function init()
		{
			fixMasthead();
			setInnerStyles();
			patchPseudoSelectors();
			(function(){ normalizeColumns(); }).delay(0.5);
		}
		
		function fixMasthead()
		{	
			if( !SHO.Utils.isIE6() || !$('masthead')) return;
			
			var masthead = $('masthead').select('h1 > a')[0];
			var src = masthead.getStyle('background-image').match(/url\("(.+)"\)/)[1];
			masthead.setStyle({ background:'0' });
			masthead.innerHTML = ''+
				'<img src="/site/beta/image-panel/global/clear.png" width="180" height="90" style="'+
				'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader( src=\''+ src +'\', sizingMethod=\crop\')" />';
		}
		
		function setInnerStyles()
		{
			$('content').select('.mod.inner').each( function(div){ 
				addRoundedCorners( div );  
			});
		}
		
		function addRoundedCorners( d )
		{
			var corners = [ '',
			 	'<div class="TL">&nbsp;</div>', 
				'<div class="TR">&nbsp;</div>', 
				'<div class="BR">&nbsp;</div>', 
				'<div class="BL">&nbsp;</div>'		
				] ;
			
			d.insert({ bottom: corners.join("\n") });
		}
		
		function patchPseudoSelectors()
		{
			$$('.mod:first-child').invoke('addClassName', 'FIRST');
			$$('.mod:last-child').invoke('addClassName', 'LAST');
			$$('.mod.subcontent li:last-child').invoke('addClassName', 'LAST');
		}
		
		function normalizeColumns()
		{
			(function(){
				fixHeights([ 'c1','c2','c3' ]);
			}).defer();
		}
		
		function fixHeights( elements )
		{	
			// determine property to apply
			var fixType =  !SHO.Utils.isIE6() ? 'minHeight' : 'height';
			var biggest = 0;
			
			// loop thru set and evaluate heights
			elements.each( function(e){ 
				if( !$(e)) return;
				var fix = {}; fix[ fixType ] = ''; // wipe out any left-over fixes
				$(e).setStyle(fix);
										  
				var h = $(e).getHeight(); 
				biggest = biggest > h ? biggest : h;    
			});
			
			// apply the fix
			elements.each( function(e){ 
				if(!$(e)) return;
				var fix = {}; fix[ fixType ] = biggest +'px';
				$(e).setStyle(fix);    
			});
		}
			
		/* =:Public
		  -----------------------------------------------------------------------------------------*/  
		return {
			init:init,
			fixCols:normalizeColumns,
			fixColumns:normalizeColumns,
			fixColumnHeights:normalizeColumns,
			fixHeights:fixHeights
		}
	
	}();
	
	document.observe("dom:loaded", function() { 
		SHO.Cosmetics.init();
	});	
	
	
