/* JS Library */
    
/* =================================================================== */
    
    window.onload = function() {
      if (document.all&&document.getElementById) {
        navRoot = document.getElementById("navigation");
        for (i=0; i<navRoot.childNodes.length; i++) {
          node = navRoot.childNodes[i];
          if (node.nodeName=="LI") {
            node.onmouseover=function() {
              this.className+=" over";
            }
            node.onmouseout=function() {
              this.className=this.className.replace(" over", "");
            }
          }
        }
      }
    }
    
/* == JQUERY ========================================================= */
      
    $(function() {
      var fs      = $('.main').css('font-size');
      var max     = 750;
      var txt     = ' characters remaining.';
      var find    = [/"([^"]+)"/g,/'/g,/[f]i/g,/[f]l/g];
      var replace = ['<span>&ldquo;<\/span>$1<span>&rdquo;<\/span>','<span>&rsquo;<\/span>','<span>&#64257;<\/span>','<span>&#64258;<\/span>'];
      var i = 0;
      for (i = 0; i < find.length; i++) {
        $('body *').replaceText( find[i], replace[i] );
      }
      
   // Reset Font Size
      $('#normal').click(function() {
        $('.main').css('font-size', fs);
      });
      
   // Increase Font Size
      $('#bigger').click(function() {
        var currentFontSize = $('.main').css('font-size');
        var currentFontSizeNum = parseFloat(currentFontSize, 10);
        var newFontSize = currentFontSizeNum*1.1;
        $('.main').css('font-size', newFontSize);
        return false;
      });
      
   // Decrease Font Size
      $('#smaller').click(function() {
        var currentFontSize = $('.main').css('font-size');
        var currentFontSizeNum = parseFloat(currentFontSize, 10);
        var newFontSize = currentFontSizeNum*0.9;
        $('.main').css('font-size', newFontSize);
        return false;
      });
      
   // Open new window
      $('a[href^=http]').click(function() {
        window.open(this.href);
        return false;
      });
      
   // ceebox
      $('a.display-video').ceebox({
        overlayOpacity: 0.8,
        overlayColor:  '#006',
        htmlWidth:      354,
        htmlHeight:     264
      });
      
   // beauty tool tip
      $('#smaller, #normal, #bigger').bt({
        cssStyles: {
          color:      '#FFF',
          fontSize:   '12px',
          padding:    '9px 12px'
          },
        showTip: function(box) { $(box).fadeIn(250); },
        hideTip: function(box, callback) { $(box).animate({opacity: 0}, 250, callback); },
        cornerRadius:  6,
        fill:         'rgba(0,0,0,0.7)',
        overlap:       3,
        positions:    'bottom',
        shrinkToFit:   true,
        hoverIntentOpts: {
          interval: 300,
          timeout: 500
        },
        spikeGirth:    20,
        spikeLength:   10,
        strokeStyle:  'rgba(0,0,0,0.7)',
        strokeWidth:   1,
        //width:      '320px',
        shadow: true,
        shadowOffsetX: 3,
        shadowOffsetY: 3,
        shadowBlur: 8,
        shadowColor: 'rgba(0,0,0,0.7)',
        shadowOverlap: false
      });
      
   // Countdown
      $('#defaultCountdown').countdown({
        until: new Date(2011, 5 - 1, 3, 8, 30),
        timezone: -5,
        format: 'DHMS'
      });
      
   // Dropdown
      /*createDropDown();
      $(".dropdown dt a").click(function() {
        $(".dropdown dd ul").toggle();
      });
      $(document).bind('click', function(e) {
        var $clicked = $(e.target);
        if (! $clicked.parents().hasClass("dropdown"))
          $(".dropdown dd ul").hide();
      });
      $(".dropdown dd ul li a").click(function() {
        var text = $(this).html();
        $(".dropdown dt a").html(text);
        $(".dropdown dd ul").hide();
        var source = $("#source");
        source.val($(this).find("span.value").html())
      });
      
      $('ul#thumbnails a').addClass('lightbox');
      $('a.lightbox').lightbox();
      $('div#overlay').css({
        backgroundColor: '#003',
        opacity: '0.7'
      });
      $('span#countdown').append(max + txt);
      $('textarea').keyup(function() {
        if(this.value.length >= max) {
          $(this).addClass('overmax');
          this.value = this.value.substring(0, max);
        } else {
          $(this).removeClass();
        }
        $('span#countdown').css('color','#000').text((max - this.value.length) + txt);
      });
      $('input#name').example('Required');
      $('input#email').example('Required');
      $('input#reg').example('Optional');
      $('textarea#msg').example('Required');
      $("form#regForm").validate({
        rules: {
          cname:  { required: true },
          cemail: { required: true, email: true },
          cmsg:   { required: true }
        },
        messages: {
          cname:  { required: "Please enter your name." },
          cmsg:   { required: "Please enter your message." }
        }
      });
      */
    });
      
    function createDropDown() {
      var source = $("#source");
      var selected = source.find("option[selected]");
      var options = $("option", source);
      
      $("#tools .container div").append('<dl id="target" class="dropdown"></dl>')
      $("#target").append('<dt><a href="#">' + selected.text() + '<span class="value">' + selected.val() + '</span></a></dt>')
      $("#target").append('<dd><ul></ul></dd>')
      
      options.each(function() {
        $("#target dd ul").append('<li><a href="#">' + $(this).text() + '<span class="value">' + $(this).val() + '</span></a></li>');
      });
    }

