jQuery.fn.extend({
	userbox: function() {
		return this.each(function() {
			var proc=$(this).find('.pgbOuter').attr('rel');
			if(proc<=50){
				var fx2={
					pos: (proc*2)/100,
					end:[255,205,0],
					start:[222,0,0]
				};
			}else{
				var fx2={
					pos: ((proc*2)-100)/100,
					end:[0,255,0],
					start:[255,205,0]
				};
				//$(this).find('.pgbInner').css({backgroundColor: 'rgb('+fx2.start.join(",")+')'})
			}

			var mycolor= "rgb(" + [
				Math.max(Math.min( parseInt((fx2.pos * (fx2.end[0] - fx2.start[0])) + fx2.start[0]), 255), 0),
				Math.max(Math.min( parseInt((fx2.pos * (fx2.end[1] - fx2.start[1])) + fx2.start[1]), 255), 0),
				Math.max(Math.min( parseInt((fx2.pos * (fx2.end[2] - fx2.start[2])) + fx2.start[2]), 255), 0)
			].join(",") + ")";
			$(this).find('.pgbInner').css({
				width: proc+'%',
				backgroundColor: mycolor
			});
			//alert(($(this).find('.longtext').width()+' - '+$(this).find('span:first').width()));
			
			
		});
	},
	searchBox:function(){
		return this.each(function() {
				$(this).click(function(){
					if(!$('#overlay').attr('id')){
						$('<div id="overlay"></div>').insertAfter($('div:last'));
						
					}
					$('#overlay').css({
							width: '100%',
							height:$(document).height(),
							backgroundColor: '#590B91',
							opacity: 0,
							position: 'absolute',
							top: 0,
							left:0
						}).show().animate({
						    opacity:0.7,
						    backgroundColor:'#000000'
						});
					return false;
				});
				$('#overlay').live('click',function(){
					$(this).fadeOut(); 
				});
				$(window).resize(function(){
					$('#overlay').css({
						height:$(document).height()
					});
				});

		});
	},

	longText:function(){
		
		return this.each(function() {
		    
		    if($(this).width()<$(this).find('span:first').width()){
			
				var txt=$(this).find('span:first').text();
				while($(this).width()-26<$(this).find('span:first').width()){
					txt=txt.substring(0, txt.length-1);
					$(this).find('span:first').text(txt);
				}
				$('<span>...</span>').insertAfter($(this).find('span:first'));
		    }else{
			//$(this).css({color:'red'});
			//alert($(this).width()+' < '+$(this).find('span:first').width());
		    }
		});
	}
});




