$(document).ready(function() {

	$('.cat a.img').tipTip();
	$('#header form label').inFieldLabels();
	
	$("ul#ticker").liScroll();
	
	// Fix Tweets width
	var c = $('#tweets div.cat').length;
	$('#tweets div.cat:last').css('marginRight', '0px');
	$('#tweets').width( ( c * 250 ) + ( (c-1) * 30 ) );
	
	// Assign AJAX to the form
	$('#header form').bind('submit', sendForm );
	$('#header fieldset.confirmation button').bind('click', function() { 
		$('#header form .loader').hide();	
		$('#btn_send').show();
		$('#header form fieldset.confirmation').hide();
		$('#header form fieldset:not(.confirmation)').show();
		$('#header form input').val('');
		$('#header form select option:selected').attr('selected', false);		
		$('#header form select option:first').attr('selected', 'selected');
		return false;
	});	
	
});

function sendForm() {
	var a = $('#account').val();
	if( a != '' ) {
		$('#btn_send').hide();
		$('#header form .loader').show();
		$.ajax({
			type: $(this).attr('method'),
			url: $(this).attr('action'),
			data: $(this).serialize(),
			success: function( data ) {
				$('#header form fieldset').hide();
				$('#header form fieldset.confirmation').show();
			}
		});
		
	} else {
		alert('Du kan väl åtminstone fylla i en twitteradress.');
	}
	
	return false;
}
