
// msg = "loaded 24";
// console.log( msg );

// -------------------------------------------------------
// this is a utility function, returning true if 
// the current page ends with the passed "Menu link title"
// where the menu link title is a custom url created for
// the page.
// -------------------------------------------------------
function isNamedPage( mlt ) {
  var pageAddr = document.location.href.split("/");
  var elems = pageAddr.length;
  
  if (pageAddr[elems-1] == mlt)
       return true;
  else return false;
}

// -------------------------------------------------------
function isContentEditPage( ) {
  var pageAddr = document.location.href.split("/");
  var elems = pageAddr.length;
  if (elems < 4)
       return false;
  if ((pageAddr[elems-3] == "node") && (pageAddr[elems-1] == "edit"))
       return true;
  else return false;
}

// this is the opening of a jquery wrapper that insures the 
// code is only executed after the DOM finishes loading;
// This logic makes the "mission" element grow upon mouseover:
$(function() {
  
  // this jquery call is using a selector to find all p tags with an id of 'mission',
  // and then attaches the in-line defined anonymous function to an 'onmouseover'
  // event for any 'p' tagged elements:
  $( '#mission p' ).mouseover( function() {
                    // animate to 0% semi-trans and 100% of full size
                    $(this).animate( { opacity:1, 
                                       fontSize:"1.5em", 
                                       lineHeight:"1.32em", 
                                   } ); 
                    });

// this is the ending of the jquery wrapper insuring the DOM is loaded:
});



// another run-after-DOM-is-loaded wrapper:
// this one places default text inside the search input field, until the user
// tries to use the search form, then it disables itself, letting the user
// operate the search form unhindered.
$(function() {

  // var elem = "#edit-search_theme_form.search-input";             // works
  // var elem = 'input';                                            // works, but finds 5 elements, too many
  // var elem = '.search-input';                                    // works just like #1 above
  // var elem = '.search-input.form-text';                          // works just like #1 above
  // var elem = 'input .search-input.form-text';       // fails
  // var elem = 'input:contains("search_theme_form")'; // fails
  // var elem = ':contains("search_theme_form")';      // fails
  var elem = '[name=search_theme_form]';                            // works just like #1 above
  
  /* debug logic:
  var ar = $( elem ).get();
  console.log( "elem is " + elem + ", length is " + ar.length );
  for (var i = 0, len = ar.length; i < len; i++) {
      console.log( "item " + i + " " + ar[i] );
  }
  */
  
  var searchText = "Your search terms";
  
  // create a function pointer to a function:
  var focusSearch = function() {
                    // because this function will be installed as a callback, the
                    // 'this' pointer is the DOM element who owns the callback...
                    // the DOM element will be the search text, so we can test its
                    // text value with the .val() jquery method as well as set its
                    // text value with the .val("new text") jquery method:
                    if ($(this).val() == searchText) // if 'val' is = to searchText
                    { $(this).val(""); }             // make val the empth string
                    };
                    
  var blurSearch = function() {
                   if (!$(this).val())               // if 'val' is the empty string
                    { $(this).val(searchText); }     // make val the searchText
                   else                                // else val is not empty...
                    { $(this)                          // so unbind these event callbacks
                       .unbind( 'focus', focusSearch )
                       .unbind( 'blur',  blurSearch );
                    }
                   };

  $( elem ) 
    .val( searchText )
    .focus( focusSearch )
    .blur( blurSearch );
});

// another after-the-DOM is loaded wrapper,
// this makes the menus slide up and disappear as soon as the page is visible,
// as well as holds conditional slide up/down logic specific to the OurServices page:
$(function() {

  // upon page render, slide the menus up to show the user that there's stuff hidden:
  $('.menu').fadeOut();
            // .slideUp( "normal" );
    
  // This logic makes the menus slide down upon mouseover of their sidebar:
  $( '#sidebar-first' ).bind( "mouseenter", function() {
                                            $('.menu').fadeIn();
                                                     // .slideDown();
                            });
             
  // links with a class of "content-hideable" have a "rel" attribute equal to the id of content
  // that should be 'hidden' or 'revealed' upon a mouse click, accomplished via an animated toggle: 
  $('.content-hideable').each( function() {
                                
                              // the content is originally visible, and this will make it
                              // disappear in front of the user upon 1st page render:
                              var rel = $(this).attr('rel');
                              if (rel) {
                                 $('#'+rel)// .toggle( 'blind', {}, 6000 );
                                           .animate( { opacity: "hide", height: "hide" }, 3000 );
                                           // .animate( { opacity: "hide" }, 500, function() { $(this).animate( { height: "hide" }, 1000 ); } );
                                           // .fadeOut(); //*/ .slideUp();
                              }
                                
                              // and attaches a callback to toggle the element's visibility:
                              $(this).click( function() {
                                               var rel = $(this).attr('rel');
                                               if ( rel ) {
                                                  $('#' + rel)// .toggle( 'blind', {}, 3000 );
                                                              .animate( { opacity: "toggle", height: "toggle" }, 1000 );
                                                              // .animate( { opacity: "hide" }, 500, function() { $(this).animate( { height: "hide" }, 1000 ); } );
                                                              // .fadeOut(); //*/ .slideUp();
                                               }  
                                               return false;
                                           });
                          });

// this is the ending of the jquery wrapper insuring the DOM is loaded:
});

