function a(val) { alert(val.toSource()); }


function stopEvent(ev)
{
	if (ev.preventDefault)
	{
		ev.preventDefault();
	}
	else
	{
		ev.returnValue = false;
	}
}

function calcPosForCenter(elHeight, elWidth)
{
	var windowWidth   = document.documentElement.clientWidth;
	var windowHeight  = document.documentElement.clientHeight;
	return {"top": windowHeight/2 - elHeight/2, "left": windowWidth/2-elWidth/2};
}

function redirectTo(url)
{
	window.location.href = url;
}

function sprintf(string)
{
	if (arguments.length <2)
	{
		return string;
	}

	for (var i=1; i<arguments.length; i++)
	{
		string = string.replace(/%s/, arguments[i]);
	}

	return string;
}

jQuery(document).ready( function($)
{
	$('.column span.share').click(function(){

		var $actionsField = $(this).parent().parent().next();
		
		if ($actionsField.hasClass('visible'))
		{
			$actionsField.animate({'height' : '0px'}, 100).removeClass('visible');
		}
		else
		{
			$actionsField.animate({'height' : '30px'}, 100).addClass('visible');
		}
	});



	/* form controls */
	$formElements =
		$('#comment-form .row, #take-part-form .row')
		.has('label')
		.find('input, textarea, select');

	
	// on focus
	$formElements.focus(function() {
		$(this).closest('.row').find('label').hide()
	});

	// on leaving
	$formElements.blur(function() {
		if ('' === $(this).val()) {
			$(this).closest('.row').find('label').show()
		}
	});

	// on load
	$formElements.each(function() {
		if ('' !== $(this).val()) {
			$(this).closest('.row').find('label').hide()
		}
	});

});

