function animateCounter(t,tt,s,f,after)
{
	if( s < f )
		s++;
	else
		s--;
	$(t).html(s+''+after);
	$(tt).css('width',(s*150/100)+'px');
	if( s != f )
		setTimeout(function(){animateCounter(t,tt,s,f,after)},15);
}
function arataVotare(tid)
{
	$('#intrebare_'+tid+' .hraspuns').show();
	$('#intrebare_'+tid+' .hrezultate').hide();
}
function arataRezultate(p,i,tid)
{
	t = p+i;
	v = $('#intrebare_'+tid+' .rezultate');
	h = $('#intrebare_'+tid+' .raspuns');
	$('#intrebare_'+tid+' .hraspuns').hide();
	$('#intrebare_'+tid+' .hrezultate').show();
	$(v).find('.total').html('<b>'+t+'</b><br>voturi');
	if( t == 0 )
	{
		pt = 0;
		im = 0;
	}
	else
	{
		pt = Math.ceil((p/t)*100);
		im = Math.floor((i/t)*100);
	}
	animateCounter($(v).find('.pentru>.perc'),$(v).find('.pentru>div'),0,pt,'%');
	animateCounter($(v).find('.impotriva>.perc'),$(v).find('.impotriva>div'),0,im,'%');
}

function attachLoader( obj, oid )
{
	//create an object the size of object
	loader = $(document.createElement('div'));
	//$('body').prepend(loader);
	tagName = $(obj).get(0).tagName.toLowerCase();
	insertIn = 'inside';
	if( tagName != "div" || tagName != "td" || tagName != "p" )
		insertIn = 'outside';
	if( insertIn == 'outside' )
		$('body').prepend(loader);
	else
		$(obj).prepend(loader);
	$(loader).attr('class','attachedLoader');
	if( typeof oid !== 'undefined' )
		$(loader).attr('id',oid);
	if( typeof obj === 'undefined' )
	{
		obj = window;
		w = $(obj).width();
		h = $(obj).height();
		$(loader).css('position','fixed');
	}
	else
	{
		w = $(obj).outerWidth();
		h = $(obj).outerHeight();
		o = $(obj).offset();
		if( insertIn == 'outside' )
			$(loader).css({
				top: o.top+'px',
				left: o.left+'px',
				'border-top-right-radius': $(obj).css('border-top-right-radius'),
				'border-top-left-radius': $(obj).css('border-top-left-radius'),
				'border-bottom-right-radius': $(obj).css('border-bottom-right-radius'),
				'border-bottom-left-radius': $(obj).css('border-bottom-left-radius')
			});
	}
	$(loader).css({
		width: w+'px',
		height: h+'px',
		display: 'block'
	});
	//alert($(loader).parent());
}
function destroyLoader( oid )
{
	if( typeof oid === 'undefined' )
		$('.attachedLoader').remove();
	else
		$('#'+oid+'.attachedLoader').remove();
}
