var validAttrs = ['text-align','vertical-align', 'background-color',
        'background-image','background-repeat','background-position',
        'background-attachment','opacity','width','height','top','right','bottom',
        'left','margin', 'margin-top','margin-right','margin-bottom','margin-left',
        'padding', 'padding-top','padding-right','padding-bottom','padding-left',
        'border', 'border-top-width','border-right-width','border-bottom-width',
        'border-left-width','border-top-color','border-right-color',
        'border-bottom-color','border-left-color','border-top-style',
        'border-right-style','border-bottom-style','border-left-style','position',
        'display','visibility','z-index','overflow-x','overflow-y','white-space',
        'clip','float','clear','cursor'];



Array.prototype.in_array = function(needle) {
	for(var i=0; i < this.length; i++) if(this[ i] === needle) return true;
	return false;
}

$(".replaceTWI").each(
	function(idx, ele) {
		if(ele.id != "") {
			$(ele).removeClass("replaceTWI");
			var img = $('<img src="img/' + ele.id + '">');

			for (var k in ele.style) {
				if(validAttrs.in_array(k)) {
					img.css(k, ele.style[k]);
				}
			}

			img.attr("alt", $(ele).text());
			img.attr("class", $(ele).attr("class"));
			img.css("margin", $(ele).css("margin"));
			img.css("display", "block");
			$(ele).replaceWith(img);
		}
	}
);
