function image_tag(image_id)
{
  tag = "\n\n" + '<div><img src="/images/blog_photos/' + image_id + '.jpg" align="center"></div>' + "\n\n";
  document.forms[0].text.value += tag;
}

function popup(url, title, height, width) {
  window.open(url, 'PlanetUniversity', 'toolbar=0,status=0,scrollbars=0,menubar=0,resizable=0,location=0,height=' + height + ',width=' + width)
  return false;
}

$( function() {
  
  var timer = null;
  
  /* Nav menus 
  ----------------------------------------------------------------------------*/
  current_nav = $('#nav li.selected')
  $('#nav > ul > li').hover(
    function() { 
      // Over 
      if( $(this).attr('id') == current_nav.attr('id') ) {
        current_nav.addClass('selected');
      }
      else {
        // console.log('Removing selected class');
        current_nav.removeClass('selected');
      }
      $(this).addClass('hovering').find('ul').fadeIn(150);
      is_hovering = true;
      clearTimeout(timer);
    },
    function() { 
      // Out
      $(this).removeClass('hovering').find('ul').fadeOut(210); 
      is_hovering = false;
      if( $(this).attr('id') != current_nav.attr('id') ) {
        timer = setTimeout(restore_selected_tab, 150);
      }
    }
  );
  
  function restore_selected_tab() {
    if (!is_hovering) {
      current_nav
        .removeClass('hovering')
        .addClass('selected');
      if ($.browser.msie == false) {
        current_nav.css('opacity', .5)
        .animate({opacity:1}, 300);
      }
    }
  }
  
  // Do stuff for IE6 only
  if($.browser.msie && $.browser.version=="6.0") {
    
    // Remove the select menu when nav tabs open over it
    var conflict_tabs = $('#microfinance-tab, #what-we-do-tab, #blogs-tab, #media-tab');
    var country_menu  = $('#select-country select');
    conflict_tabs.hover( 
      function() {
       country_menu.addClass('hide');
      },
      function() {
       country_menu.removeClass('hide');
      }
    );
  }
  
});