$(document).ready(function(){
	var input_username = $('#login');
	var input_password = $('#password');
	if (input_username.val() == '') {
		input_username.focus();
	} else {
		input_password.focus();
	}
	
	tabs.init();
	
});

var calendar = {

    show: function(url) {
        $('#calendar_table').load(url + ' #calendar_table');
        return false;
    }
}

var comments = {
	submit: function() {
		$('#comment_msg').hide();
		$.ajax({
			url: '/comments/save/',
		  	dataType: 'json',
		  	data: {
				name:    $('#comment_name').val(),
				email:   $('#comment_email').val(),
				text:    $('#comment_text').val(),
				type:    $('#comment_type').val(),
				type_id: $('#comment_type_id').val()
			},
		  	success: function(data, textStatus){
			  	$('.vs-context-menu').hide('slow');
			  	if (data.status == 'ok') {
				  	$('#write_comment').text('Der Kommentar wurde gespeichert.');
				  	$('#comment_form').hide();
					$('#no-comments-hint').hide();
				  	$('#write_comment').before(data.new_comment);
			  	} else if (data.status == 'error') {
			  		$('#comment_msg').text('Fehler: ' + data.errMsg);
			  		$('#comment_msg').show('slow');
			  	}
		  	}
		});
	}
};

var tabs = {
    init: function() {
        $('.tabs').each(function(){
            var as = $(this).find('a');
            as.click(function(test) {
                var href = $(this).attr('href');
                var tobefadedin = $($(this).attr('href'));
                
                as.each(function() {
                    $(this).removeClass('active');
                    //$($(this).attr('href')).fadeOut('slow');
                    $($(this).attr('href')).hide();
                    
                    //$($(this).attr('href')).fadeOut('slow').empty().html(tobefadedin).fadeIn('slow');
                    
                });
                $(this).addClass('active');
                //$($(this).attr('href')).fadeIn('slow');
                $($(this).attr('href')).show();
                
                return false;
            });
        });
    }
};
