/*global window $$*/
window.addEvent('domready', function(){

  var setupMore = function(butt, baseClass){
    /*define the properties we will need*/
    
    butt.hidden = true; //button is hidden by default
    butt.dependants = $$('.'+baseClass+'.'+ butt.getProperty('ref')); // store referneces to the objects this button affects
    butt.moreText = butt.getProperty('html'); //stiore the default more text

    //add the onclick event
    butt.addEvent('click',function(event){
      event.preventDefault(); //stop the link linking

      if (this.hidden){
        //show the dependants
        this.dependants.each(function(toShow){
          toShow.reveal();
        });
        this.setProperty('html', '...less');
        this.hidden = false; //toggle the hidden state
      }else{
        //hide the dependants
        this.dependants.each(function(toShow){
          toShow.dissolve();
        });
        this.setProperty('html', this.moreText);
        this.hidden = true; //toggle the hidden state
      }
    });
  };

  //find each button
  $$('.showmore').each(function(butt){
    setupMore(butt, 'hidden');
  });

  //find each menu point
  $$('.showmore2').each(function(butt){
    setupMore(butt, 'hiddennav');
  });
});

