// highlight current tab on mm_tabs

function bifHighlightCurrentTab(arg){
  if(document.getElementById('tab_area')){
    var links = document.getElementById('tab_area').getElementsByTagName('a');
    for (var i=0; i<links.length; i++){
      links[i].setAttribute('class','tab_default');
      links[i].setAttribute('className','tab_default'); // IE7 Workaround: http://www.digitalmediaminute.com/article/1394/the-browser-dom-and-the-class-attribute
    }
    arg.setAttribute('class','tab_current');
    arg.setAttribute('className','tab_current'); // IE7 Workaround - See above
  }
}

function bifSetCurrentTab(){
  if(document.getElementById('tab_area')){
    var links = document.getElementById('tab_area').getElementsByTagName('a');
    links[0].setAttribute('class','tab_current');
    links[0].setAttribute('className','tab_current'); // IE7 Workaround - See above
  }
}

// function to add formatting classes to input form elements

function bifExtrasChangeInputs(){
  // don't apply this styling to bif innovators forms (they're absolutely positioned)
  if(!document.getElementById('grid-wrapper')){
    var els = document.getElementsByTagName('input');
    var elsLen = els.length;
    var i = 0;
    for ( i=0;i<elsLen;i++ ){
      if ( els[i].getAttribute('type') ){
        if ( els[i].getAttribute('type') == "text" ){
          els[i].className = 'bif-extras-text';
        } else {
	  els[i].className = 'bif-extras-button';
        }
      }
    }
  }
}

// function to add formatting classes to text area form elements

function bifExtrasChangeTextArea(){
  var els = document.getElementsByTagName('textarea');
  var elsLen = els.length;
  var i = 0;
  for ( i=0;i<elsLen;i++ ){
    els[i].className = 'bif-extras-textarea';
  }
}

// function to add formatting class to select-box form element

function bifExtrasChangeSelectBox(){
  // don't apply this styling to bif innovators forms (they're absolutely positioned)
  if(!document.getElementById('grid-wrapper')){
    var els = document.getElementsByTagName('select');
    var elsLen = els.length;
    var i = 0;
    for ( i=0;i<elsLen;i++ ){
      els[i].className = 'bif-extras-select-box';
    }
  }
}

// function to add formatting class to select-box option form elements

function bifExtrasChangeSelectBoxOption(){
  // don't apply this styling to bif innovators forms (they're absolutely positioned)
  if(!document.getElementById('grid-wrapper')){
    var els = document.getElementsByTagName('option');
    var elsLen = els.length;
    var i = 0;
    for ( i=0;i<elsLen;i++ ){
      els[i].className = 'bif-extras-select-box-option';
    }
  }
}

// function to add formatting classes to images in blog posts

function bifExtrasFormatBlogImages(){
  if(document.getElementById('main')){
    var els = document.getElementById('main').getElementsByTagName('img');
    var elsLen = els.length;
    var i = 0;
    for ( i=0;i<elsLen;i++ ){
      els[i].className = 'picleft-blog';
    }
  }
  if(document.getElementById('blogmain')){
    var els = document.getElementById('blogmain').getElementsByTagName('img');
    var elsLen = els.length;
    var i = 0;
    for ( i=0;i<elsLen;i++ ){
      els[i].className = 'picleft-blog';
    }
  }
  if(document.getElementById('local-main')){
    var els = document.getElementById('local-main').getElementsByTagName('img');
    var elsLen = els.length;
    var i = 0;
    for ( i=0;i<elsLen;i++ ){
      els[i].className = 'picleft';
    }
  }
}

// function to highlight paragraph

function highlightgraph(){
  if(document.getElementById){
    document.getElementById('highlightgraph').style.backgroundColor="#ebebeb";
  }
}

// slide open comment form box
/*
$(document).ready(function(){
  $('.comment-form-drop-down .comment-form-drop-down-content').hide(); 
  $('.comment-form-drop-down h2 a').click(function() {
    $(this).parent().next(".comment-form-drop-down-content").slideToggle('fast');
    return false;
  });
});*/

// modification on 4/23/09 by jeff drury
// repeat function from quicktabs module javascript file;
// the problem: when direct linking to a tab, the new tab should be highlighted
// with the bifHighlightCurrentTab function; this part works; however,
// a split-second after the new tab is highlighted, the javascript from this
// file (bif-extras.js) kicks in, and highlights the first tab in the tab list
// (in addition to the newly selected tab); i'm repeating the modified quicktabs
// js function here to correct the situation

function gup( name ){
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null ){
    return "";
  } else {
    var thenum = results[1];
    if(document.getElementById('tab_area')){
      var links = document.getElementById('tab_area').getElementsByTagName('a');
      for (var i=0; i<links.length; i++){
        links[i].setAttribute('class','tab_default');
        links[i].setAttribute('className','tab_default'); // IE7 Workaround
      }
      links[thenum].setAttribute('class','tab_current');
      links[thenum].setAttribute('className','tab_current'); // IE7 Workaround - See above
    }
    return results[1];    
  }
}

// onload event handler

window.onload = function() {
  bifExtrasFormatBlogImages();
  bifExtrasChangeInputs();
  bifExtrasChangeSelectBox();
  bifExtrasChangeSelectBoxOption();
  bifExtrasChangeTextArea();
  bifSetCurrentTab();
  gup('qt_active');
}

