﻿/// <reference path="jquery-1.3.2.js" />

$(function() {

   $('body').initializeSections();
   $('input.watermark').createWatermark();
   $('.focus').focus();

})

$.fn.initializeSections = function() {

   return this.each(function() { initializeSection(this); });

   /************************************************************************/
   /************************************************************************/

   function initializeSection(container) {

      // convert all divs with the class "section" that are inside this container

      $(container).find('div.section').each(function() {
         var originalContent = $(this).html();
         var newContent = $('<div>').addClass('sectionContent').html(originalContent);

         $(this).html(newContent);
         $('<h3>').text(this.title).prependTo(this);
      });

   }

};

$.fn.createWatermark = function() {

   return this.each(function() { initializeWatermark(this); });

   /************************************************************************/
   /************************************************************************/

   function initializeWatermark(textbox) {
      var textbox = $(textbox);

      textbox.focus(function() {
         if (textbox.val() == textbox.attr('title')) {
            textbox.val('');
            textbox.css('color', '');
         }
      });

      textbox.blur(function() {
         if (textbox.val() == '') {
            textbox.val(textbox.attr('title'));
            textbox.css('color', '#999999');
         };
      });

      textbox.blur();
   }

};

$.fn.toggleOverflow = function(toggleLink) {

   toggleLinkText();

   return this.each(function() { toggleElementOverflow(this); });

   /************************************************************************/
   /************************************************************************/

   function toggleLinkText() {
      toggleLink = $(toggleLink);

      if (toggleLink.text().indexOf('Expand') >= 0)
         toggleLink.text(toggleLink.text().replace('Expand', 'Collapse'));
      else
         toggleLink.text(toggleLink.text().replace('Collapse', 'Expand'));
   }

   function toggleElementOverflow(element) {
      var element = $(element);
      if (element.css('overflow') == 'hidden') {
         element.css('overflow', '');
         element.css('white-space', 'normal');
      } else {
         element.css('overflow', 'hidden');
         element.css('white-space', '');
      }
   }

};
