/*



Dynamic Application of Functions to DOM
*/
var _debugMode = false;
document.observe('dom:loaded', init);


function init(){
  /*
  
  To set the height of the 2nd column
  */
  /* max height for sub */
  if ($('main3')){
    if ($('main3').getHeight() > 1560) {
      Try.these(
        function(){
          $('sub1').down('.margin').setStyle({
            height: 1560 + 'px'
          });
        },
        function(){
          $('sub1').down('.margin').setStyle({
            height: 1560
          });
        }
      );
    }
    /* if the sub column is larger than the main column */
    else if ($('main3').getHeight() < $('sub3').getHeight()){
      /* adjust the main column */
      Try.these(
        function(){
          $('main1').down('.margin').setStyle({
            height: $('sub3').getHeight() + 'px'
          });
        },
        function(){
          $('main1').down('.margin').setStyle({
            height: $('sub3').getHeight()
          });
        }
      );
    } else {
      /* else adjust the sub column */
      Try.these(
        function(){
          $('sub1').down('.margin').setStyle({
            height: ($('main3').getHeight() - 28) + 'px'
          });
        },
        function(){
          $('sub1').down('.margin').setStyle({
            height: $('main3').getHeight() - 28
          });
        }
      );
    }
  }
  // end main3 adjustments 
  
  /*
  
  
  decorating the NavSub
  $$('ul.NavSub li a').each(function(n, i){
    n.insert({ top: '&bull;&nbsp;&nbsp;' });
  });
  */
  // should be faster?
  // $$('ul.NavSub li a').invoke('insert', { top: '&bull;&nbsp;&nbsp;' });

  /*



  Forms
  */
  $$("input", "select", "textarea").each(c.addFocus);


}
/* end init function */

function changeQuestionForm(thisForm) {
  if(thisForm != "") {
    var url = String("/"+thisForm);
    new Ajax.Request(url, {
      method:'get',
      onSuccess: function(transport){
        var response = transport.responseText || "Could Not Retrieve Form";
        if($('question_form')) {
          $('question_form').update(response);
        }
      },
      onFailure: function(){ 
        if($('question_form')) {
          $('question_form').update("Could Not Retrieve Form");
        }
      }
    });

    
  }
}

/*




The start of the custom functions object
*/
var c = {
  addFocus: function(node, i){
    node.observe("focus", c.toggleFocus.bindAsEventListener(node));
    node.observe("blur", c.toggleFocus.bindAsEventListener(node));
  },
  toggleFocus: function(e){
    this.toggleClassName("focus");
  },
  addHover: function(node, i){
    node.observe("mousover", c.toggleHover.bindAsEventListener(node));
    node.observe("mouseout", c.toggleHover.bindAsEventListener(node));
  },
  toggleHover: function(e){
    this.toggleClassName("hover");
  }
};

function cl(str){
  if(_debugMode) t(function(){console.log(str);});
}

function t(f) {
  Try.these(f);
}
