$(document).ready(function(){
    if( $('div.dobsolete')) { $('#sless').show(); }

	$('#sless').click(function(){ $('div.dobsolete').slideUp( 'slow',
                                    function() { $('#sless').hide( 0); $('#sall').show( 0); });
                                  }
                       );
	$('#sall').click(function(){ $('div.dobsolete').slideDown( 'slow',
                                    function() { $('#sless').show( 0); $('#sall').hide( 0); });
                               }
                    );
    if( $('.dobsolete').length == 0) { $('#sless').hide( 0); }
    $('select.ddmenu').change( function() { var selected= this.selectedIndex;
                                            var target= this.options[selected].value;
                                            if( target != "none") { location= target; }
                                          }
                             );

    $('select#search-result-show').change( function() { var target= $(this).parent().attr( 'action');
                                                        var value=  $(this).attr( 'value');
                                                        if( value) { target = target + '&status=' + value; }
                                                        location= target;
                                                      } 
                                         );

    resize_title( $('#title-banner').children('h1'), 100); // make sure the title is less than 100px high

    $('.more_items').hide();
    $('.mlb').click( function() { $( '.mlb').slideToggle(); $( '.more_items').slideToggle(); });

    // set selected attribute on proper headlink
    var file2area= { std_index: 'find-standards', wg_index  : 'developing',     project_index: 'developing' };
    var dir2area= { standard  : 'find-standards', findstds  : 'find-standards', getieee802 : 'find-standards',
                    project   : 'developing',     wg        : 'developing',     develop   : 'developing',
                    membership: 'membership',
                    news      : 'news-and-events',
                    about     : 'about-us', contact   : 'about-us', faq       : 'about-us'
                  };
    var file= location.pathname.split( '/').pop();
    var dir= location.pathname.split( '/')[1];
    var area= file2area[file] || dir2area[dir];
    $( 'li.headlink').removeClass( 'selected').has( 'a.' + area).addClass( 'selected');

    // add popup for links to the store
    $('a.tostore').click( function() { $(this).after( '<div id="disclaimer"><div id="close" title="close" onclick="$(this).parent().fadeOut()">X</div><p>You are being transitioned to IEEE\’s Online Shop to purchase a print copy of a standard. Please conduct a search for the standard you wish to purchase and add it to your shopping cart.</p><p><a href="' + this.getAttribute( 'href') + '" target="_blank">Click here</a> to enter the IEEE Online Shop</p></div>').fadeIn( 'slow'); return false; });



                             });



function resize_title ( h1, target_height)
  { var min_padding   = 10;
    var font_size     = parseInt( h1.css( 'font-size'), 10);

    while( h1.outerHeight() > target_height)
      { var over= h1.outerHeight() - target_height;
        var padding= h1.outerHeight() - h1.height();
        if( over <= padding - min_padding)
          { var new_padding= padding - over;
            h1.css( 'padding-top', new_padding + "px"); 
          }
        else
          { font_size--;
            h1.css( 'font-size', font_size + "px");
          }
      }

    // additional tweak to restore some bottom padding
    var total_height= h1.parent().outerHeight();
    if( total_height > target_height + (2 * min_padding) ) { h1.css( 'padding-top', '20px'); }
    if( total_height > target_height + (3 * min_padding) ) { h1.css( 'padding-top', '10px'); }

  }





