function init(){
  $('#groups').show();
  $('#groups').accordion({
    active: false,
    alwaysOpen: false,
    header: '.header',
    clearStyle: true,
    autoHeight: false
    //autoHeight: true
  }).bind("accordionchange", function(event, ui){ $('.popup').hide('fast'); });
  
  $('a.minus').click(function(){ $('#groups').accordion('activate', -1); $('.header.showing:hidden').show(); });
  $('.privacy-options input.cancel').click(function(){ $('#groups').accordion('activate', -1); $('.header.showing:hidden').show(); });
  $('.header').click(function(){ $('.header.showing:hidden').show(); $(this).toggle(); });
  
  $('#groups li div.content:first').height(70);
  $('#groups li.join-group div.content').height(110);
  $('select.groups').change(function(){ $('#groups li div.content:first').height(454);
                                        $('#group-settings-wrapper>div').hide();
                                        $('#group-settings-wrapper div.'+$('select.groups').val()).show(); });
  
  $('a.create-group').click(function(){ $('#groups').accordion('activate', 0); });
  $('a.join-group').click(function(){ $('#groups').accordion('activate', 1); });
  

  
  var original_value = $('.send-a-message textarea').val();
  $('.send-a-message textarea').click(function(){
    if ($(this).val() == original_value) $(this).attr('value', '');
  });
  $('.send-a-message textarea').blur(function(){
    if ($(this).val() == '') $(this).attr('value', original_value);
  });
  $('.send-a-message textarea[maxlength]').keyup(function(){
    if($(this).val().length > $(this).attr('maxlength')){
      $(this).val($(this).val().substr(0, $(this).attr('maxlength')));
    }
    $(this).parent().find('.characters-remaining').html($(this).attr('maxlength') - $(this).val().length);
  });
  $('input.button').hover(function(){ var tmp = $(this).attr('src').split('.');
                                      $(this).attr({src: tmp[tmp.length-2]+'-hover.'+tmp[tmp.length-1]});
                                      $(this).css('border-color', '#8A8A8A'); },
                          function(){ $(this).attr({src: $(this).attr('src').replace(/-hover/, '')});
                                      $(this).css('border-color', '#666666'); });
  $('a.button').hover(function(){ var tmp = $(this).css('background-image').split('.');
                                  $(this).css('background-image', $(this).css('background-image').replace(/\.gif/, '-hover.gif')); 
                                  $(this).css('border-color', '#8A8A8A');},
                          function(){ $(this).css('background-image', $(this).css('background-image').replace(/-hover/, ''));
                                      $(this).css('border-color', '#666666'); });
  new Image().src='/images/buttons/cancel-hover.gif';
  new Image().src='/images/buttons/group-hover.gif';
  new Image().src='/images/buttons/create-group-hover.gif';
  new Image().src='/images/buttons/join-group-hover.gif';
  new Image().src='/images/buttons/send-hover.gif';
  new Image().src='/images/buttons/save-hover.gif';
  new Image().src='/images/buttons/submit-hover.gif';
  new Image().src='/images/buttons/login-hover.gif';
}

function popup(w, el){
  $('.popup').hide();
  var w = '.'+w;
  if (el!=''){
    var l = $(el).parent().offset().left+2,
        t = $(el).parent().offset().top+14,
        p = $(el).width()/2+($(el).offset().left-l-7);
    $(w).css({left: l,
              top: t });
    $(w+' .top').css('background-position', p+'px top');
    $(w).show();
  }
  
}
function expand(el){
  if ($(el).is(':hidden')){
    $('#groups li.selected div.content').height($('#groups li.selected div.content').height()+330);
  }
  else{
    $('#groups li.selected div.content').height($('#groups li.selected div.content').height()-330);
  }
  $(el).toggle();
}
