//External links script

function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}
window.onload = externalLinks;


// Subnav hide/display for IE6

$(document).ready(function() {

    // The .not(.sub-nav li) stop the effect if the mouse hits a sub nav item of the select tab coming from below, otherwise that would disappear
    $("ul#topnav li:not(.selected)").not('.sub-nav li').hover(function() { //Hover over event on list item
        // Change the background colour
        $(this).css({ 'background-color': '#7f0804' });
        // if this is not the .selected tab then hide the ul subnav of the .selected tab
        $('ul#topnav li.selected ul').hide();
        // Then show this subnav
        $('ul', $(this)).show();
        
    }, function() { //on hover out...
        // Subnavs are caught up by this function too since they also match the selector.  I haven't figured out
        // how to exclude them from selection yet and doing a check here is much easier
        if ($(this).parents('.sub-nav').length > 0) return;
        // Clear background colour
        $(this).css({ 'background-color': '#fff' });
        // Hide the subnav
        $('ul', $(this)).hide();
        // Then show the subnav of .selected tab
        $('ul#topnav li.selected ul').show();
    });

});


// IE form styling

if( document.addEventListener ) document.addEventListener( 'DOMContentLoaded', cmxform, false );

function cmxform(){
  // Hide forms
  $( 'form.cmxform' ).hide().end();

  // Processing
  //$('form.cmxform').find('li/label').not('.nocmx')

  $('form.cmxform li>label:not(".nocmx")').each(function(i) {
      // Essentially, stick a span with a width around the inner text of the label
      var labelContent = this.innerHTML;
      var labelWidth = document.defaultView.getComputedStyle(this, '').getPropertyValue('width');
      var labelSpan = $('<span></span>').css('display', 'block').attr('width', labelWidth).html(labelContent);
      $(this).css('display', '-moz-inline-box').html('').append(labelSpan);
  }).end();
  
  // Show forms
  $( 'form.cmxform' ).show().end();
}

