jQuery(function ($) {
    
   // main and subnavigation ---------------------------------------------------
   (function (parent) {
      var subNavWrap = $('.sub-wrap', parent),
         subNavs = subNavWrap.children('li'),
         activeSubNav = subNavs.filter('.active'),
         isInit = true,
         isSubNavOpen;

      $('.main a', parent).each(function () {
         var self = $(this),
            defaultHeight = self.css('height'),
            offset = self.closest('li').position().left + self.find('span').position().left,
            subNav = subNavs.filter('[rel="' + self.attr('rel') + '"]');

         // Bind everything.
         parent.mouseleave(function () {
            // Go back to default subnavigation.
            subNavs.hide();
            activeSubNav.show();
            isSubNavOpen = activeSubNav.length > 0;
         }).mouseleave();

         self.mouseenter(function () {

            // Show subn avigation.
            subNavs.hide();

            if (!isSubNavOpen) {
               isSubNavOpen = true;
               subNav.slideDown(isInit ? 0 : 250);
            } else {
               subNav.stop().css('opacity', 1.0).fadeIn(isInit ? 0 : 500);
            }

            subNav.css('padding-left', offset + 'px');
         }).mouseleave(function () {
            self.stop().animate({
               height: defaultHeight
            }, isInit ? 0 : 250);
         }).mouseenter().mouseleave();

         // Initialization ends when the initial UI queue has finished.
         setTimeout(function () {
            isInit = false;
         }, 0);
      });
   }($('#body > .nav')));
   
   // content navigation -------------------------------------------------------
   (function (parent) {
      var nav = $('.nav', parent),
         navItems = $('a', nav),
         contentItems = $('.selectable > div', parent);
      
      navItems.click(function (e) {
         var self = $(this),
            name = self.attr('href').substr(1);
         
         e.preventDefault();
         
         if (name === '_default') {
            window.location.hash = '';
         } else {
            window.location.hash = name;
         }
         
         navItems.removeClass('active');
         self.addClass('active');
         
         contentItems.hide().filter('[rel="' + name + '"]').show();
         _gaq.push(['_trackEvent', 'ShowPage', pageName,name]);
      });
   
      if (window.location.hash.length > 0) {
         navItems.filter('[href="' + window.location.hash + '"]').click();
      } else {
         contentItems.filter('[rel="_default"]').show();
         navItems.filter('[href="#_default"]').click();
      }
   }($('#body .content-wrap > .content')));
   
   // contact form and dsl check-------------------------------------------------------------
//   $('input, textarea', $('.dslcheck')).each(function () {
//      var self = $(this),
//         defaultValue = self.val();
//      
//      self.focus(function () {
//         if (self.val() == defaultValue) {
//            self.val('');
//         }
//      }).blur(function () {
//         if (self.val() == '') {
//            self.val(defaultValue);
//         }
//      });
//   });
   
   $('#WebToLeadForm').submit(function(e){
       valid = true;
       
       $('#WebToLeadForm .req').each(function(){
           if($(this).val() == ''){
               valid = false;
               $(this).addClass('border-red');
           }
       })
       
       if(!valid){
           $('.error').slideDown();
           return false; 
       }
   });
   
   $('#WebToLeadForm .req').change(function(e){
       if($(this).val() != ''){
           $(this).removeClass('border-red');
       }
   });
   

   
   
   
   
   $( "a.orderButton, button, .button, .submit").button();
   
   
   
//   Cufon.replace('h1', { fontFamily: 'PT Sans', textShadow: '0px -1px #fff' });
//   Cufon.replace('h2', { fontFamily: 'PT Sans Bold', textShadow: '0px 1px #fff' });
});
function subnavclick(target) {
	var nav = $('.nav');
    navItems = $('a', nav);
	navItems.filter('[href="#' + target + '"]').click();
};


