var $j=jQuery.noConflict();
$j(document).ready(
  function() {
    if($j(".planChooser").length) {
      $j(".split3way a").hover(
        function (event) {
          event.preventDefault();
          $j(".split3way").find('a').removeClass("active");
          $j(this).addClass("active");
          $j(".descriptionBox").hide();
          var boxId = '#description' + $j(this).parent().attr('id').split('plan')[1];
          $j(boxId).show();          
        }
      );
    }
    $j("#account .title a, #prepay .title a").click(
      function (event) {
        event.preventDefault();
        return false;
      }
    );        
    $j("#mapInput").focus(
      function () {  
        $j(this).val('');    
      }
    );

    $j("#mapShower").click(
      function (event) {
        event.preventDefault();
        var searchTerm = $j('#mapInput').attr('value');
        $j("#addressInput").attr('value', searchTerm);
        blockUI("#mapOverlay");
        searchCoverage();
        return false;
      }
    );

    $j("#mapInput").keydown(
      function (e) {
        if (e.keyCode === 13) {
          var searchTerm = $j(this).attr('value');
          $j("#addressInput").attr('value') = searchTerm;
          blockUI("#mapOverlay");
          searchCoverage();
          return false;
        }
      }
    );

    $j(".cityList li a").each(
      function () {
        $j(this).click(
          function (event) {
            $j("#mapInput").attr('value', $j(this).text());
            $j("#addressInput").attr('value', $j(this).text());
            blockUI("#mapOverlay");
            searchCoverage();
          }
        );
      }
    );      
    $j(".closeOverlay").click(
      function (event) {
        unblockUI(".siteOverlay");
        return false;
      }
    );   
    $j('#account').accordion({
      header: 'span.button',
      active: '.selected',
      alwaysOpen: false,
      autoheight: false,
      animated: 'easeslide'
    });
    $j('#support').accordion({
      header: 'span.button',
      active: '.selected',
      alwaysOpen: false,
      autoheight: false,
      animated: 'easeslide'
    });
    $j('#webmail').accordion({
      header: 'span.button',
      active: '.selected',
      alwaysOpen: false,
      autoheight: false,
      animated: 'easeslide'
    });
    $j('#address').accordion({
      header: 'span.button',
      active: '.selected',
      alwaysOpen: false,
      autoheight: false,
      animated: 'easeslide'
    });
    $j('#benefits').accordion({
      header: 'span.button',
      active: '.selected',
      alwaysOpen: false,
      autoheight: false,
      animated: 'easeslide'
    });
    $j('#contact').accordion({
      header: 'span.button',
      active: '.selected',
      alwaysOpen: false,
      autoheight: false,
      animated: 'easeslide'
    });

    $j('#popular').accordion({
      header: 'span.button',
      active: '.selected',
      alwaysOpen: false,
      autoheight: false,
      animated: 'easeslide'
    });

    $j('#myBills').accordion({
      header: 'span.button',
      active: '.selected',
      alwaysOpen: false,
      autoheight: false,
      animated: false
    });

    $j('#myPlan').accordion({
      header: 'span.button',
      active: '.selected',
      alwaysOpen: false,
      autoheight: false,
      animated: false
    });

    $j('#myPhone').accordion({
      header: 'span.button',
      active: '.selected',
      alwaysOpen: false,
      autoheight: false,
      animated: false
    });

    $j('#basket').accordion({
      header: 'span.button',
      active: '.selected',
      alwaysOpen: false,
      autoheight: false,
      animated: 'easeslide'
    });

    $j('#compare').accordion({
      header: 'span.button',
      active: '.selected',
      alwaysOpen: false,
      autoheight: false,
      animated: 'easeslide'
    });

    if ($j(".helpContentTabs").length) {
      $j(".tab-content").hide();
      var URLstr = window.location.toString();
      if (URLstr.indexOf('#', 0) >= 0 ) {
        $j(".helpChooserDialog").hide();
        $j(".if-js-hide").removeClass("if-js-hide");
      }
      $j("#prepayintro, #onaccountintro").click(
        function (event) {
          event.preventDefault();
          var activeTab = $j(this).attr("href");
          $j.address.value(activeTab);  
          $j(".helpChooserDialog").hide();
          $j(".if-js-hide").removeClass("if-js-hide");
        }
      );
      $j("ul.tabs li").click(
        function (event) {
          event.preventDefault();
          var activeTab = $j(this).find("a").attr("href");
          $j.address.value(activeTab);  
          $j(this).addClass("active");
          return false;
        }
      );  
      $j.address.change(
        function (event) {
          $j("ul.tabs li").removeClass("active");
          $j(".tab-content").hide();
          switch (event.value) {
          case '/#prepay':
          case '/%23prepay':
            $j("ul.tabs li:eq(0)").addClass("active");
            $j(".tab-content:eq(0)").show();
            break;
          case '/#onaccount':
          case '/%23onaccount':
            $j("ul.tabs li:eq(1)").addClass("active");
            $j(".tab-content:eq(1)").show();
            break;
          default:
          }    
        }
      ); 
    }
    if ($j(".pricingContentTabs").length) {
      $j("a.close").click(
        function (event) {
          event.preventDefault();
        }
      );
      $j(".additionalInformation a").click(
        function (event) { 
          event.preventDefault();
          $j(".additionalInformation").fadeOut();
        }
      );
      $j(".tab-content").hide();      
      $j(".tab-content:first").show();
      $j("ul.tabs li").click(
        function (event) {
          event.preventDefault();
          var activeTab = $j(this).find("a").attr("href");
          $j.address.value(activeTab);
          $j(this).addClass("active");
          return false;
        }
      );  
      $j.address.change(
        function (event) {
          $j("ul.tabs li").removeClass("active");
          switch (event.value) {
          case '/#top':
          case '/%23top':
            $j("ul.tabs li:eq(0)").addClass("active");
            $j(".option2, .option3, .option4").hide();
            $j(".option1").fadeIn();
            break;
          case '/#tab2':
          case '/%23tab2':
            $j("ul.tabs li:eq(1)").addClass("active");
            $j(".option1, .option3, .option4").hide();
            $j(".option2").fadeIn();
            break;
          case '/#tab3':
          case '/%23tab3':
            $j("ul.tabs li:eq(2)").addClass("active");
            $j(".option1, .option2, .option4").hide();
            $j(".option3").fadeIn();
            break;
          case '/#tab4':
          case '/%23tab4':
            $j("ul.tabs li:eq(3)").addClass("active");
            $j(".option1, .option2, .option3").hide();
            $j(".option4").fadeIn();
            break;
          default:
            $j("ul.tabs li:eq(0)").addClass("active");
            $j(".option2, .option3, .option4").hide();
            $j(".option1").fadeIn();
          }
        }
      );
    }
    $j("#morePrepayInfo").click(
      function (event) {
        event.preventDefault();
        $j("#addPrepayInfo").show();
        return false;
      }
    );
    $j('.mbbOffer').bind(
      'click',
      function (e) {
        $j.blockUI( { message : $j('#mbb_offer_content') } );
        $j('.blockOverlay, .basicCloseOverlay').click($j.unblockUI);
        e.preventDefault();
        e.stopPropagation();
        return false;
      }
    );
    $j('#mbb_offer_content').addClass('hidden');
  }
);
