﻿$(function () {
   //$(".DropDownlist").easySelectBox({ className: 'easy-select-box' });
   $(".LeftColumn").append('&nbsp;');

   //menu
   if ($(".MenuExtras .FirmProfile").hasClass("active")) {
      $(".MenuMainChildren").hide();
      $(".FirmProfile").css("background-position", "0 -338px");
   }

   $("label.profileAdvert").css("background-position", "400px 400px");

   if ($(".MenuMain div").hasClass("active")) {
      $(".FirmFeature").css("background-position", "0 -288px")
   } else {
      $(".FirmFeature").css("background-position", "0 -144px")
   }

   if ($(".MenuExtras .WebExtras").hasClass("active")) {
      $(".WebExtras").css("background-position", "0 -288px");
      $(".FirmFeature").css("background-position", "0 -144px");
   }

   //append a break after every p tag in the main content
   $(".OrganisationContent p").each(function (i) {
      if (i > 0) {
         $(this).after("<br>");
      }
      i++;
   });

   //$(".OrganisationContent p:first-child").remove();

   $(".main p").each(function () {
      $(this).after("<br>");
   });

   //Law school search control actions
   $(".LawSchoolSearch").change(function () {
      $("input[type='hidden']").val($(this).children(":selected").val());
   });

   $(".lawschoolButton").click(function () {
      var radioVal = $("input[name='lawschool']:checked").val();
      var selectVal = $(".hidSelected").val();
      window.location = radioVal + "/FirmFeature/" + selectVal;
   });

   //web extras controls
   var cnt = 1;

   var uri = window.location.pathname;
   if (uri.indexOf("WebExtras") > 0) {
      $(".OrganisationContent h3").each(function () {
         if (cnt > 1) {
            $(this).nextUntil('h3').hide();
            $(this).addClass("hidden");
         } else
            $(this).addClass("visible");
         cnt = cnt + 1;
      });
      $(".OrganisationContent h3").click(function () {
         $(".OrganisationContent h3").each(function () {
            if ($(this).hasClass("visible")) {
               $(this).nextUntil('h3').hide();
               $(this).removeClass("visible").addClass("hidden");
            }
         });

         $(this).nextUntil('h3').show();
         $(this).removeClass("hidden").addClass("visible");
      });
      $(".MenuMainChildren li a").click(function () {
         $(".OrganisationContent h3").each(function () {
            if ($(this).hasClass("visible")) {
               $(this).nextUntil('h3').hide();
               $(this).removeClass("visible").addClass("hidden");
            }
         });
         var href = $(this).attr('href');
         $(".OrganisationContent a").each(function () {
            var anchor = "#" + $(this).attr('name');
            if (href == anchor) {
               $(this).nextUntil('.OrganisationContent a').show();
               $(this).prev("h3").removeClass("hidden").addClass("visible");
               $(this).focus();
            }
         });
      });
   }
   //text transform
   Cufon.replace('h1')('.alph h1')('.ResultSorting span')('.SideMenuWrapper h3');

   // Set active menu bar
   $('.MenuBar li').each(function () {
      var uri = window.location.pathname;
      var target = $(this).children("a").attr('href');

      if (uri == target) {
         if ($(this).parent().parent('li').length > 0)
            $(this).parent().parent('li').addClass("active");
         else
            $(this).addClass("active");
      }
   });

   $(".ResultsTitle a").hover(function () {
      $(this).css("color", "#F7901E");
   });
   $(".ResultsLink a").hover(function () {
      $(this).css("color", "#F7901E");
   });

   $(".ResultsItem").hover(function () {
      $(this).find("a").css("color", "#3B6E8F");
   });
   $(".ResultsItem").mouseout(function () {
      $(this).find(".ResultsLink a").css("color", "#4a9288");
      $(this).find(".ResultsTitle a").css("color", "#686159");
   });

   //remove anchor text
   $(".anchorLink").text("");

   $(".toggleMenu").clone().appendTo('div.LeftToggleMenu');
   //align first column of table left
   $('.PostIts .Diversity tr').each(function () {
      $(this).find("td:first").css("text-align", "left");
   });

   $('.FirmSaysQuote').eq(1).removeClass("FirmSaysQuote").addClass("FirmSaysQuote2nd");

   $('.OrganisationContent h3').each(function () {
      $(this).nextUntil("h3").last("p").append("<div><a href=#100 class=backToTop><span>Back to top</span></a></div>");
   });

   //terrible hack to fix practice area xml inconsistencies - dont remove WB
   if ($(".articlePA h1").text() == "") {
      $(".articlePA h2:first").replaceWith(function () { return "<h1>" + this.innerHTML + "</h1>"; });
      $(".toggleMenu h2:first").remove();
   }
});
