/**
 * @author Pawel Knapik
 */


/* decimal to hex */
function d2h(d){d=(d*1).toString(16);return(d.length<2)?'0'+d:d}

function getTextColor(el) {
	var colorstr = $(el).css('color');
	if(/rgb/.test(colorstr)){ var c = colorstr.substring(4,colorstr.length-1).split(','); c={r:d2h(parseInt(c[0],10)),g:d2h(parseInt(c[1],10)),b:d2h(parseInt(c[2],10))}; colorstr="#"+c.r+''+c.g+''+c.b; }
	else if(/#/.test(colorstr)&&colorstr.length==4) {var c = colorstr; c={r:c.substr(1,1),g:c.substr(2,1),b:c.substr(3,1)}; colorstr="#"+c.r+''+c.r+''+c.g+''+c.g+''+c.b+''+c.b;  }
	else if(/#/.test(colorstr)&&!colorstr.length==7) return;
	return colorstr;
}

 jQuery.fn.sifr = function(fontPath,opts,variable){

	opts = opts || {};
	for(var i=0,j=this.length;i<j;i++) {

		var ufostr = {movie:fontPath, width:this[i].offsetWidth, height:opts.height || /*Math.round(parseFloat($(this[i]).css('font-size')))*1.3 ||*/ $(this[i]).height()*1.3, majorversion:"7", build:"0", wmode: "transparent" };
		var textcolor = opts.textcolor? '&textcolor='+opts.textcolor : '&textcolor='+getTextColor(this[i]);
		var textalign = opts.textalign? '&textalign='+opts.textalign : '';
		var url = this[i].href ? "&sifr_url_0="+this[i].href : '';
		var link = this[i].href ? "<a href=%22asfunction:_root.launchURL,0%22>" : '';
		var endlink = this[i].href ? '</a>' : '';

		ufostr.flashvars = "txt="+link+this[i].innerHTML+endlink+"&w="+ufostr.width+"&h="+ufostr.height+textcolor+textalign+url;
		this[i].id = this[i].id || variable+i; 
		UFO.create(ufostr,this[i].id);

	}

	
 }