$(document).ready(function(){
    // Watermark
    var originalValues = {"username": $('input#password, input#username').attr('value'),
                          "password": $('input#password, input#password').attr('value')};
        $('input#password, input#username').focus(function(){
            if ($(this).attr('value') == originalValues[$(this).attr('id')] || $(this).attr('value') == '') {
                $(this).attr('title', $(this).attr('value'));
                $(this).removeAttr('value');
                $(this).attr('type', 'text');
            } else {

            }
        }).blur(function(){
            if ($(this).attr('value') == originalValues[$(this).attr('id')] || $(this).attr('value') == '') {
                $(this).attr('value', $(this).attr('title'));
            } else {

            }
        });

    // Show/hide login form on click on login
    $('.login a.button').click(function(){
        if ($(this).hasClass('selected')) {
            $(this).removeClass('selected');
            $('.login-form').hide();
        } else {
            $(this).addClass('selected');
            $('.login-form').show();
        }
    });

    // Animating the content (3 columns)

    var hide_foldouts = function(group) {
      if (group.hasClass('clubs')) {
        group.children('a.bigbutton').removeClass('last-button');
      }

      group.children('div.foldout-01').hide('slide', {direction: 'left'}, 500);
      group.children('div.foldout-02').delay(300).hide('slide', {direction: 'up'}, 500, function() {
        group.css('position', '');
        group.css('float', '');
        group.animate({'left': group.data('left')}, 500);
        group.parent().height('');
        group.siblings().show(1000);
      });
      group.data('active', false);
    }

    $('div.block a.bigbutton').click(function() {
      var group = $(this).parent();

      if (group.data('active') === true) {
        hide_foldouts(group);
      }
      else {
        group.data('left', group.position().left);
        group.siblings().hide(200);

        if (group.hasClass('clubs')) {
          group.children('a.bigbutton').addClass('last-button');
        }

        group.animate({'left': '0'}, 500, function(ev){
          group.parent().height('auto');
          group.css({'position': 'static', 'float': 'left'});
          group.children('div.foldout-01').show('slide', {direction: 'left'}, 500);
          group.children('div.foldout-02').delay(300).show('slide', {direction: 'up'}, 500);
        });
        group.data('active', true);
      }

    });

    $('div.block a.close').click(function(){
      hide_foldouts($(this).parent().parent());
    });
});


