
var Account_controller = Class.create();
	
Account_controller.prototype = {
	
  len: { 'email': 128, 'website': 1024, 'location': 64, 'password_new':	16, 'password_repeat': 16 },

  // Initialize vote.
  //
  initialize: function() {
  },
	
  // Refresh counter
  //
  refresh_cnt: function(name, len) {
	  if ($('cnt_'+name))
      $('cnt_'+name).innerHTML = eval('this.len.'+name) - len;
  },
	
	// Follow a user
	//
	follow:	function(username) {
	
    var opt = {
      method:	'get',
      parameters: 'username='+username,
	    onSuccess: function() { Element.toggle('follow'); Element.toggle('notfollow'); },
      evalScripts: false
    };

    var au = new Ajax.Updater('ajaxDump', url.basemain+'ajax/account/follow/', opt);	
	
	}	

};
	
var Account = new Account_controller();	
	
var Account_rules = {

  '#content #left form input': function(e) {
    e.onkeyup = function() {
      Account.refresh_cnt(e.getAttribute('cnt'), e.value.length);
    }
  },
	
  '#content #left form #services label': function(e) {
    e.onclick = function() {
			if (e.className == 'checked') {
	      $(e.getAttribute('service')).value = '';
	      e.className = '';
	    }	else {
	      $(e.getAttribute('service')).value = 'on';
	      e.className = 'checked';
			}
	    $(e.getAttribute('service')+'_login').toggle();
    }
  },
	
  '#content #left form #notifs label': function(e) {
    e.onclick = function() {
			if (e.className == 'checked') {
	      $(e.getAttribute('notif')).value = '';
	      e.className = '';
	    }	else {
	      $(e.getAttribute('notif')).value = 'on';
	      e.className = 'checked';
			}
    }
  },
	
	'#content #right #follow': function(e) {
	  e.onclick = function() {
	    Account.follow(e.getAttribute('username'));
	    return false;
	  };
	  e.onmousedown = prevent_focus;
	},
	
	'#content #right #notfollow': function(e) {
	  e.onclick = function() {
	    Account.follow(e.getAttribute('username'));
	    return false;
	  };
	  e.onmousedown = prevent_focus;
	}	

};
	
Behaviour.register(Account_rules);
	
var tabs_rules = ['profile', 'newavatar', 'password', 'services'].fold({}, function(result, value) {
  result['#'+value+'-tab'] = function() {
    $(value+'-tab').onclick = function() {
	
			['profile', 'newavatar', 'password', 'services'].each(function(e) {
        Element.hideIf(e);
      });	
	
	    Element.showIf(value);
	
      ['profile', 'newavatar', 'password', 'services'].each(function(e) {
        $(e+'-tab').removeClassName('current');
      });
      $(value+'-tab').addClassName('current');	

      return false;
    };
    $(value+'-tab').onmousedown = prevent_focus;
  };
  return result;
});
	
Behaviour.register(tabs_rules);
