/*
Declaration 
===========
Button: 
<a href="#" class="roundedbutton">Text</a>
Button with icon: 
<a href="#" class="roundedbutton" rel="add">Text</a>
Disabled button with icon:
<a href="#" class="roundedbutton disabled" rel="application_form_delete">Text</a>
*/

var Buttons = {

	Create: function(strTree) {
		// If there is no tree specified, we will check the whole DOM
		if (typeof(strTree) == 'undefined') {
			strTree	= '';
		}
		$(strTree+' .roundedbutton').each (function() {
			icon		= $(this).attr('rel');
			if (icon) {
				textContent	= $(this).html();
				disabled	= this.className.search("disabled");
				
				setIcon = '';
				setIcon = '<img class="icon_'+icon+'_png" src="'+jsWebRoot+'gfx/iconset_silk/icon_'+icon+'.png" alt="'+icon+'.png" />';
				if(disabled != -1) {
					attrDisable	= document.createAttribute("disabled");
					attrDisable.value	= 'disabled';
					this.attributes.setNamedItem(attrDisable);
				}
				this.innerHTML = '<span title="'+textContent+'">'+setIcon+textContent+'</span>';
				
				if (icon && $.browser.msie && $.browser.version<7 ) {
					this.firstChild.firstChild.src=jsWebRoot+"gfx/bg/trans_1px.gif";
					this.firstChild.firstChild.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+jsWebRoot+"gfx/iconset_silk/icon_"+icon+".png', sizingMethod='crop')";
				}
				
				// Clean up the rel attribute
				$(this).removeAttr('rel');
			}
		});
		
		$(strTree+' .iconize').each (function() {
			iconize		= $(this).attr('rel');
			if (iconize) {
				textContent	= $(this).html();
				
				setIcon = '';
				setIcon = '<img class="icon_'+iconize+'_png" src="'+jsWebRoot+'gfx/iconset_silk/icon_'+iconize+'.png" alt="'+iconize+'.png" />';
				this.innerHTML = '<span title="'+textContent+'">'+setIcon+textContent+'</span>';
				
				if (iconize && $.browser.msie && $.browser.version<7 ) {
					this.firstChild.firstChild.src=jsWebRoot+"gfx/bg/trans_1px.gif";
					this.firstChild.firstChild.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+jsWebRoot+"gfx/iconset_silk/icon_"+icon+".png', sizingMethod='crop')";
				}
				
				// Clean up the rel attribute
				$(this).removeAttr('rel');
			}
		});
	}
	
}

$(function() {
	$('.roundedbutton').each (function() {
		icon		= $(this).attr('rel');
		textContent	= $(this).html();
		disabled	= this.className.search("disabled");
		
		setIcon = '';
		if (icon) {
			setIcon = '<img class="icon_'+icon+'_png" src="'+jsWebRoot+'gfx/iconset_silk/icon_'+icon+'.png" alt="'+icon+'.png" />';
		}
		if(disabled != -1) {
			attrDisable	= document.createAttribute("disabled");
			attrDisable.value	= 'disabled';
			this.attributes.setNamedItem(attrDisable);
		}
		this.innerHTML = '<span title="'+textContent+'">'+setIcon+textContent+'</span>';
		
		if (icon && $.browser.msie && $.browser.version<7 ) {
			this.firstChild.firstChild.src=jsWebRoot+"gfx/bg/trans_1px.gif";
			this.firstChild.firstChild.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+jsWebRoot+"gfx/iconset_silk/icon_"+icon+".png', sizingMethod='crop')";
			//this.firstChild.firstChild.style.filter="";
			//alert(this.firstChild.firstChild.style.filter);
		}

	})
});

/*
Declaration 
===========
Icon link: 
<a href="#" class="iconize" rel="add">Text</a>
*/

$(function() {
	$('.iconize').each (function() {
		iconize		= $(this).attr('rel');
		textContent	= $(this).html();
		
		setIcon = '';
		if (iconize) {
			setIcon = '<img class="icon_'+iconize+'_png" src="'+jsWebRoot+'gfx/iconset_silk/icon_'+iconize+'.png" alt="'+iconize+'.png" />';
		}
		this.innerHTML = '<span title="'+textContent+'">'+setIcon+textContent+'</span>';
		
		if (iconize && $.browser.msie && $.browser.version<7 ) {
			this.firstChild.firstChild.src=jsWebRoot+"gfx/bg/trans_1px.gif";
			this.firstChild.firstChild.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+jsWebRoot+"gfx/iconset_silk/icon_"+iconize+".png', sizingMethod='crop')";
			//this.firstChild.firstChild.style.filter="";
			//alert(this.firstChild.firstChild.style.filter);
		}

	})
});

