function buttonskin(buttons, flag)
{ // [jQuery] automatic button skinning of anchors and form buttons to a common presentation, flag=text-on-top
	if (typeof(jQuery) == "undefined") { return; } // ensure jQuery library is present
	(function($) { $(function() { // avoid conflicts from other JavaScript libraries
		var tmp, x, w, w4, w6, wNew, h, h4, h6, hNew, obj, typ;
		$(buttons).each(function() { // locate the CSS specified DOM elements
			obj = $(this);
			typ = (typeof(obj.attr("type")) != "undefined")? obj.attr("type").toLowerCase() : "";
			if (obj.attr("tagName").toLowerCase() == "input" && obj.css("display") != "none" &&
			 (typ == "submit" || typ == "reset" || typ == "button") &&
			 obj.parent().attr("tagName").toLowerCase() != "a") { // wrap form submit, reset, & button
				x = obj.attr("title");
				obj.css({ // remove existing button styling to allow skinning
					margin:"0px", border:"none", padding:"2px", background:"transparent none", outline:"none"
				}).wrap( /* wrap form button with skinning anchor and apply button's classes */
					"<span class=\"btn\" style=\"display:-moz-inline-block;display:inline-block;" +
					 "width:auto\"><a class=\"" + obj.attr("className") + "\"><\/a><\/span>"
				).removeAttr("class");
				obj.focus(function() { // treat tab-focus like hover over
					$(this).parent("a").addClass("hover");
				}).blur(function() { // treat tab-blur like hover out
					$(this).parent("a").removeClass("hover");
				});
				obj = obj.parent("a"); // move object reference to new anchor object
				obj.find("input:first").click(function(e){ e.stopPropagation(); }); // kill event click propagation
				obj.attr("title", x).click(function() { // bind anchor's click event to the form button
					$(this).find("input:first").click(); // click inner button
					return false; // ignore anchor click event
				});
			}
			if (obj.attr("tagName").toLowerCase() == "a" && obj.find("i.m").length == 0) { // skin anchors
				obj.css({ margin:"0px", border:"none" }); // remove any margins and borders
				if ((document.all && !window.XMLHttpRequest) || window.opera) { // older browser support
					w = obj.outerWidth() + 1; // read width
					w4 = parseInt(w * .4); // 40% width
					w6 = parseInt(w * .6); // 60% width
					wNew = obj.width() - w + w4 + w6 + 1; // calculated button width
					w = w4 + w6; // internal width
					h = obj.outerHeight(); // read height
					h4 = parseInt(h * .4); // 40% height
					h6 = parseInt(h * .6); // 60% height
					hNew = h4 + h6 - parseInt(obj.css("paddingTop")) - parseInt(obj.css("paddingBottom")) + 1;
					h = h4 + h6; // internal height
					obj.css({ width:wNew + "px", height:hNew + "px" }); // set the calculated button size
					// pre-dimensioned presentation elements
					tmp = "<i class=\"m\" style=\"width:" + w + "px !important;height:" + h +
					 "px !important\"><span style=\"width:" + w4 + "px !important;height:" + h4 +
					 "px !important\"><\/span><b style=\"top:" + h4 + "px !important;width:" + w4 +
					 "px !important;height:" + h6 + "px !important\"><\/b><\/i><b class=\"m\" style=\"width:" + w +
					 "px !important;height:" + h + "px !important\"><span style=\"left:" + w4 +
					 "px !important;width:" + w6 + "px !important;height:" + h4 +
					 "px !important\"><\/span><i style=\"left:" + w4 + "px !important;top:" + h4 +
					 "px !important;width:" + w6 + "px !important;height:" + h6 + "px !important\"><\/i><\/b>"
				}
				else { // all other browsers, just add presentation elements
					tmp = "<i class=\"m\"><span><\/span><b><\/b><\/i><b class=\"m\"><span><\/span><i><\/i><\/b>";
				}
				if (flag) { obj.wrapInner("<span style=\"position:relative;display:block;z-index:1\"><\/span>").prepend(tmp); } // prepend
				else { obj.append(tmp); } // append
			}
		});
	}); })(jQuery);
}
if (typeof(jQuery) != "undefined") { (function($) { $(function() { // jQuery loaded, avoid conflicts from other JavaScript libraries
	// when the document is ready, skin all CSS referenced anchors and form buttons
	$(document).ready(function() { buttonskin(".btn"); });
}); })(jQuery); }

