var Screenfluent = {
  
  start: function() {
    $j('html').addClass('js');
    this.expandAbout();
    this.enhanceSelectLists();
    this.enhanceSubmitForm();
  },
  
  expandAbout: function() {
    var l18n = ['Read more', 'Read less'],
        $section = $j('.about'),
        $more = $j('<p class="more"></p>'),
        $more_link = $j('<a href="">' + l18n[0]  + '</a>');
        
    $section.append($more);
    
    $more_link
      .appendTo($more)
      .bind('click', function(e) {      
        var $hidden_text = $section.find('p:first span');
        var state = $hidden_text.is(':visible');
        $hidden_text['fade' + (state ? 'Out' : 'In')]('fast');
        $more_link.text(l18n[(state ? 0 : 1)]);
        e.preventDefault();
      });    
  },
  
  enhanceSelectLists: function() {
    
    var $selection = $j('.selection');
    var $selections = $selection.add('.selections > li');
    
    $selections.each(function() {
      var $select = $j(this),
          $title_handle =$j('<a href=""/>'),
          $title = $select.find(' > *:first'),
          $list = $select.find('ul'),
          state = false;
          
      $title.wrapInner($title_handle);
      $list.hide();
      $title.bind('click', function(e) {
        if ($j(e.target).is('a')) {
          $list['slide' + (state ? 'Up' : 'Down')]();
          state = !state;
        }
        e.preventDefault();
      });
    });
  },
  
  enhanceSubmitForm: function(){
    $j('.submit-form p.info').each(function() {
      var $this = $j(this);
      $this.hide();
      var $label = $this.parent().find('label:first');
      var $info = $j(document.createElement('a'));
      $label.addClass('info').append(":");
      $info.append('<img src="/images/info-button.png" width="16" height="16">').addClass('info-button').bind('click', function(e) {
        $this.toggle();
        e.preventDefault();
      }).appendTo($label);
    });
  }
};

$j(function() {
  Screenfluent.start();
});