function verifyContactForm() {
  var $contactForm = $(this);
  var error = "";
  if ($contactForm.find("[name=firstName]").val() == "") {
    error = error + "* You must enter your First Name.\n"
  }
  if ($contactForm.find("[name=lastName]").val() == "") {
    error = error + "* You must enter your Last Name.\n"
  }
  if ($contactForm.find("[name=address1]").val() == "") {
    error = error + "* You must enter your Address.\n"
  }
  if ($contactForm.find("[name=city]").val() == "") {
    error = error + "* You must enter your City.\n"
  }
  if ($contactForm.find("[name=state]").val() == "") {
    error = error + "* You must enter your State.\n"
  }
  if ($contactForm.find("[name=zip]").val() == "") {
    error = error + "* You must enter your Zip Code.\n"
  }
  if ($contactForm.find("[name=emailAddress]").val() == "") {
    error = error + "* You must enter your Email Address.\n"
  }
  if ($contactForm.find("[name=referral]").val() == "") {
    error = error + "* You must enter how you heard about us.\n"
  }
  if (error == "") {
    return true;
  } else {
    alert("In order to continue:\n\n" + error);
    return false;
  }
}

function nextCopy() {
  var $frontPageCopy = $("#front_page_copy");
  var $activeCopy = null;
  var $nextCopy = null;
  var $visibleCopy = $frontPageCopy.children(":visible");

  if($frontPageCopy.children(".active").size() == 0) {
    $activeCopy = $frontPageCopy.children(":first");
  } else {
    $activeCopy = $frontPageCopy.children(".active");
  }

  if($activeCopy[0] == $frontPageCopy.children(":last")[0]) {
    $nextCopy = $frontPageCopy.children(":first");
  } else {
    $nextCopy = $activeCopy.next();
  }

  $visibleCopy.fadeOut(2000, function() {
    $visibleCopy.removeClass("active");
    $nextCopy.addClass("active");
    $nextCopy.fadeIn(3000);
  });
}

var county = null;

/*
var nextMarqueeTimeout = null;
var fadeTimeout = null;
var freeze = false;
var nextIndex = null;

function nextMarquee(keepGoing) {
  var $currentImg = $("#slider>:visible");
  var $currentTab = $("#slider_menu>ul>li>a.active").parent();
  var $currentTxt = $("#heroContent>.heroItemActive");
  $currentTxt.removeClass("heroItemActive");;
  $currentTxt.find(".highlight").fadeTo(1500, 0.0);
  $currentTab.find("a").removeClass("active");
  $currentImg.fadeOut(1500, function() {
    if(nextIndex != null) {
      $currentImg = $("#slider>:nth-child(" + (nextIndex+1) + ")");
      $currentTab = $("#slider_menu>ul>:nth-child(" + (nextIndex+1) + ")");
      if ($currentTab == null) {
        $currentTab = $("#slider_menu>ul>li.first");
      }
      $currentTxt = $("#heroContent>:nth-child(" + (nextIndex+1) + ")");
    }
    else {
      if($currentImg[0] == $("#slider>:last")[0]) {
        $currentImg = $("#slider>.sliderImage>:first");
      }
      else {
        $currentImg = $currentImg.next();
      }
      if($currentTxt[0] == $("#heroContent>:last")[0]) {
        $currentTxt = $("#heroContent>:first");
      }
      else {
        $currentTxt = $currentTxt.next();
      }
      if($currentTab[0] == $("#slider_menu>ul>:last")[0]) {
        $currentTab = $("#slider_menu>ul>:first");
      }
      else {
        $currentTab = $currentTab.next();
      }
    }
    clearTimeout(fadeTimeout);
    fadeTimeout = setTimeout(function() {
      $currentImg.fadeIn(2000);
      $currentTab.find("a").addClass("active");
      $currentTxt.addClass("heroItemActive");
      $("#heroContent").children().not(".heroItemActive").find(".highlight").fadeTo(0, 0.0);
      $currentTxt.find(".highlight").fadeTo(2000, 0.3);
      if(keepGoing) nextMarqueeTimeout = setTimeout(function() { nextMarquee(true); }, 5000);
    }, 500);
  });
}
*/

function setupMarquee() {
  var $controls = $("#slider_menu");
  var $togglePlay = $controls.find(".toggle_play");
  var $controlBullets = $controls.find(".frames>li");
  var $frames = $("#slider>.frames>li");
  var marqueeTimeout = null;
  var emptyFunc = function() { return false; };

  function play(timeout) {
    if(!timeout) timeout = 8000;
    $togglePlay.removeClass("paused").attr("title", "Pause");
    clearTimeout(marqueeTimeout);
    marqueeTimeout = setTimeout(function() { nextFrame() }, timeout);
  }

  function pause() {
    $togglePlay.addClass("paused").attr("title", "Play");
    clearTimeout(marqueeTimeout);
    marqueeTimeout = null;
  }

  function nextFrame($next) {
    var $active = $frames.filter(".active");
    if(!$next) {
      if($active[0] != $frames.filter(":last")[0]) {
        $next = $active.next();
      }
      else {
        $next = $frames.eq(1);
      }
    }
    var nextIndex = $frames.index($next);
    $frames.not($active[0]).removeClass("active").hide();
    $controlBullets.removeClass("active");
    if($active != null) $active.removeClass("active");
    $next.addClass("active")
    $controlBullets.eq(nextIndex).addClass("active");
    setTimeout(function() {
      if($active != null) $active.fadeOut(1200);
    }, 10);
    setTimeout(function() {
      $next.fadeIn(1200);
    }, 10);
    if(!$togglePlay.is(".paused")) play();
  }

  // jump to frames using the controls
  $controlBullets.each(function(index) {
    $(this).click(function() {
      if($(this).is(".active")) {
        pause();
        return false;
      }
      pause();
      nextFrame($frames.eq(index));
      return false;
    });
  });

  // play/pause toggling
  $togglePlay.click(function() {
    if($togglePlay.is(".paused")) {
      play(100);
    }
    else {
      pause();
    }
    return false;
  });
  
  // init to first frame on load
  $controlBullets.removeClass("active").eq(0).addClass("active").show();
  $frames.removeClass("active").hide().eq(0).addClass("active").show();
  $frames.find("a").attr("tabindex",-1);
  play(9000);
}

$(document).ready(function() {
  $(".submit").click(function() {
    $(this).closest("form").submit();
    return false;
  });

  $(".reset").click(function() {
    $(this).closest("form")[0].reset();
    return false;
  });

  $(".contact_form").submit(verifyContactForm);
/*
// classnames changes for compact list of offices
  $("[name=practiceArea]").change(function() {
    $(".practiceAreaItem").hide();
    if($(this).val() != "") {
      var $li = $("#" + $(this).val());
      if($li.find(".office").size() > 0) {
        $li.show();
        $(".sorry_text").hide();
      }
      else {
        $(".sorry_text").show();
        var practice = $(this).children(":selected").text();
        $(".sorry_text .practice").text(practice);
        $(".sorry_text .county").text(county);
      }
      $(".search_instructions").hide();
    }
    else {
      $(".search_instructions").show();
        $(".sorry_text").hide();
    }
  }).trigger("change");
*/

  $(".tabs").tabs();

  $(".superfish").superfish({ autoArrows: false });
  $(".superfish").find("a[href=#]").click(function() { return false; });

//  setTimeout(nextCopy, 6000);
  $(function() {
    setInterval( "nextCopy()", 8000 );
  });


  var $c2_1 = $(".c2_1");
  var $c2_2 = $(".c2_2");
  if($c2_1.height() > $c2_2.height()) {
    $c2_1.addClass("sep_right");
  }
  else {
    $c2_2.addClass("sep_left");
  }

/*
  $("slider img").hide().filter(":first").show();
  $("#heroContent>.heroItem>.highlight").fadeTo(0,0).filter(":first").fadeTo(0, 0.3);
  nextMarqueeTimeout = setTimeout(function() { nextMarquee(true); }, 4000);
  
  $(".heroItem").each(function(index) {
    $(this).hover(function() {
      nextIndex = index;
      clearTimeout(nextMarqueeTimeout);
      nextMarqueeTimeout = setTimeout(function() {
        nextMarquee(false);
      }, 500);
    }, function() {
      nextMarqueeTimeout = setTimeout(function() {
        nextMarquee(true);
      }, 4000);
      nextIndex = null;
    });
  });
*/  

});

$(window).load(function() {
  if($("body").is(".find_a_hospital")) {
    setupMarquee();
    $("#slider ul>li").css("visibility", "visible");
    var $lastMenuItem = $("#slider_menu .frames li:last");
    var offsetRight = $lastMenuItem.offset().left + $lastMenuItem.width();
    var targetOffsetRight = $("#slider_menu").offset().left + $("#slider_menu").width();
    $lastMenuItem.find("a").width($lastMenuItem.width()-parseInt($lastMenuItem.find("a").css("padding-left"))-parseInt($lastMenuItem.find("a").css("padding-right"))+(targetOffsetRight-offsetRight)-1);
  }
  $(".hospital_search_tab").click( function() {
    if ($(".hospital_search>.identifier").is(":hidden")) {
        $(".hospital_search").animate({ 
            marginTop: "264px"
            }, 800 );
        $(".hospital_search>.identifier").show();
    } else if ($(".hospital_search>.identifier").is(":visible")) {
        $(".hospital_search").animate({ 
            marginTop: "362px"
            }, 800 );
        $(".hospital_search>.identifier").hide();
    }
    return false;
  });

  $("[name=practiceArea]").change(function() {
    $(".practiceAreaItem").hide();
    if($(this).val() != "") {
      var $li = $("#" + $(this).val());
      if($li.find(".client_entity").size() > 0) {
        $li.show();
        $(".sorry_text").hide();
      } else {
        $(".sorry_text").show();
        var practice = $(this).children(":selected").text();
        $(".sorry_text .practice").text(practice);
        $(".sorry_text .county").text(county);
      }
      $(".search_instructions").hide();
    } else {
      $(".search_instructions").show();
        $(".sorry_text").hide();
    }
  }).trigger("change");

  $(".practiceAreaItem a").not(".button").click(function() { window.location = $(this).attr("href"); return false; });
/*
  $(".practiceAreaItem .office").hover(function() { $(this).addClass("hover"); }, function() { $(this).removeClass("hover"); }).click(function() { if($(this).find(".button").attr("href") != null) window.location = $(this).find(".button").attr("href"); return false; });
*/
  $(".practiceAreaItem .client_entity").hover(function() { $(this).addClass("hover"); }, function() { $(this).removeClass("hover"); }).click(function() { if($(this).find(".button").attr("href") != null) window.location = $(this).find(".button").attr("href"); return false; });

  $(".dentistPracticeAreaItem a").not(".button").click(function() { window.location = $(this).attr("href"); return false; });
/*
  $(".dentistPracticeAreaItem .office").hover(function() { $(this).addClass("hover"); }, function() { $(this).removeClass("hover"); }).click(function() { if($(this).find(".button").attr("href") != null) window.location = $(this).find(".button").attr("href"); return false; });
*/
  $(".dentistPracticeAreaItem .client_entity").hover(function() { $(this).addClass("hover"); }, function() { $(this).removeClass("hover"); }).click(function() { if($(this).find(".button").attr("href") != null) window.location = $(this).find(".button").attr("href"); return false; });


});
