/**
 * @author Kris Kelly
 */
if (!Y){var Y = YAHOO;}
if (!H){
	Y.namespace("Heehaw", "Heehaw.tagCache");
	var H = Y.Heehaw;
		H.tagCache.IMG = document.createElement('IMG');
		H.tagCache.SPAN = document.createElement('SPAN');
		H.tagCache.DIV = document.createElement('DIV');
}
H.imageTitler = function imageTitler(){
	var D = Y.util.Dom;
	var E = Y.util.Event;
	
	
	/**
	 * 
	 * @param {DomNode} img
	 */
	function setTitle(img){
		if (false){
			img = H.tagCache.IMG.cloneNode(false);
		}
		var imgSibling = img.previousSibling;
		var imgParent = img.parentNode;
		var container = H.tagCache.DIV.cloneNode( false );
		var titleText = document.createTextNode(img.alt);
		var title = H.tagCache.SPAN.cloneNode( false );
			title.appendChild( titleText );
			title.className = "image_title";
		container.className = img.className;
		D.removeClass(img, "show_image_title_right");
		D.removeClass(img, "show_image_title_left");
		D.setStyle( container, "width", img.width+"px" );
		//D.setStyle( container, "height", img.height+"px" );
		container.appendChild( img );
		container.appendChild( title );
		
		if (imgSibling) {
			D.insertAfter(container, imgSibling);
		} else {
			imgParent.appendChild(container);
		}
	}
	function getTitlers(e){
		if (D.hasClass(e, 'show_image_title_left') || D.hasClass(e, 'show_image_title_right')){
			return true;
		}
		return false;
	}
	var imgs = D.getElementsBy(getTitlers, 'img', 'content', setTitle);
	
}
Y.util.Event.onDOMReady( H.imageTitler );