function homepage_flash_embed () {
  var so = new SWFObject("/flash/banner_controller.swf", "homepage-flash", "942", "354", "8", "#000");
    so.addParam("wmode", "opaque");
    so.addVariable("xPath", "/banner_xml")
    so.write("flash-img");
}


// Hover Behaviour for Nav etc.
var HoverBehavior = Class.create({
  initialize: function() {
    $A(document.styleSheets).each( function(stylesheet) {
    $A(stylesheet.rules).each( function(rule) {
    if( rule.selectorText.match(/:hover/i) ) {
      stylesheet.addRule( rule.selectorText.replace(/:hover/ig, '.hover'), rule.style.cssText );
    }
    });
  });

  $A(arguments).each( function(arg) {
    $$(arg).each( function(tag) {
      Event.observe(tag, 'mouseenter', function() { Element.addClassName(tag, 'hover'); }, true);
      Event.observe(tag, 'mouseleave', function() { Element.removeClassName(tag, 'hover'); }, true);
      });
    });
  }
});


// Pop Image from utils
function popImage(img, alt) {
  url = '/imageviewer.php?pic='+img+'&alt='+alt;
  window.open(url, 'ImageZoom', 'width=435,height=495');
}

// Scan for rel=blank
function popExternalLinks () {
  $$('a[rel="blank"]').each(function(link){link.target = "_blank"});
}


var InputDefaultValue = Class.create({  
  
  initialize: function(field){
    // Ensure container exists
    if (!$(field)) { return false; }

    this.field = $(field);
    this.defaultValue = $F(this.field);
  
    // Clear field on click
    Event.observe(this.field, "click", function(){
      if ($F(this.field)==this.defaultValue) { 
        $(this.field).clear(); 
      }
      $(this.field).activate();
    }.bind(this));
  
    // Restore field's default text when empty
    Event.observe(this.field, "blur", function(){
      if (!$(this.field).present()) { 
        $(this.field).setValue(this.defaultValue); 
      }
    }.bind(this));
  }
});



var Accordion = Class.create({  
  selector : null,
  current_section : null,
  animating : false,
  
  initialize: function(selector, options){
      
    // Ensure selector is good
    if (!$$(selector).pop()) { return false; }
  
    // Override default options
    this.options = Object.extend({
      duration: 0.5   // transition speed
    }, options || {});
    
    var events_container = $$(selector).pop().up();
    
    $$(selector).each(function(section) {
      
      // Find current section
      if ((!this.current_section) && (section.hasClassName('active'))) {
        this.open(section);
        this.current_section = section;      
      }

      // Set a section id based on the link href
      section.id = section.down('h2 a').href.split('#').pop();

      // Secttion Toggle Link - clicking
      section.down('h2 a').observe('click', this.activate.bind(this,section), false);
      
      section.down('.section_body').hide();
      //this.close(section,0);

    }.bind(this));      
  },


  activate : function(section, event) {  
      
    var old_section = this.current_section;    

    // Do nothing if already animating or the current panel was clicked
    if (this.animating) { return false; }

    // Set flag
    this.animating = true;

    if (section.hasClassName('open')){
      this.close(section);
    } else {
      this.open(section);
    }

    // Update the current panel
    this.current_section = section;
    
    // Update the URL for any bookmarking
    location.hash = section.id.split('section-').pop();  
    
    // Don't the browser scroll up or down to the id
    if (event) { event.stop() }  
  },
  
  activate_original : function(new_section, event) {    
    var old_section = this.current_section;    

    // Do nothing if already animating or the current panel was clicked
    if (this.animating) { return false; }
    if (new_section==old_section) { return false; }

    // Set flag
    this.animating = true;

    // Animate both panels
    this.close(old_section);
    this.open(new_section);

    // Update the current panel
    this.current_section = new_section;
    
    // Update the URL for any bookmarking
    location.hash = new_section.id;    
    
    // Don't the browser scroll up or down to the id
    if (event) { event.stop() }    
  },  
  
  close : function(section) {
    if (!section) { return; }
    
    var args = Array.prototype.slice.call(arguments); 
    var duration = (args.length>1) ? args.pop() : this.options.duration;
    
    // Remove the old section's active class
    section.removeClassName('active');
    section.addClassName('animating');
    section.select('.view').pop().update('+ View Details');
    
    // Animate up, and remove the open class when done
    new Effect.BlindUp( section.down('.section_body'), { 
      duration: duration,
      afterFinish: function() {
        section.removeClassName('open');
        section.removeClassName('animating');
        this.animating=false;        
      }.bind(this)
    });    
  },
  
  open : function(section) {    
    if (!section) { return; }
    
    var args = Array.prototype.slice.call(arguments); 
    var duration = (args.length>1) ? args.pop() : this.options.duration;    
    
    // Add the active class to the new panel (make it red)
    section.addClassName('active');
    section.addClassName('animating');              
        
    // Animate down, and add the open class when done
    new Effect.BlindDown( section.down('.section_body'), {   
      duration: this.options.duration,
      afterFinish: function(){
        section.addClassName('open');
        section.removeClassName('animating');        
        section.select('.view').pop().update('- Hide Details');
        this.animating = false;        
      }.bind(this)
    });    
  }
  
});






// Global Window Onload
Event.observe(window, 'load', function() {  
    popExternalLinks();
});



// Global DOM onload
document.observe("dom:loaded", function() {

  new Accordions('#content .accordion')
  
   // Make room for CLF
  if ($('topnav')) { $('topnav').setStyle({right:'355px'}); }  


});
