$(document).ready(function() {

  var sel='';

  $(".menuitem").hover(function() {
    if($(this).hasClass("menuitemsel")) {
      sel=1;
    }
    $(this).addClass("menuitemsel");
  }, function() {
    if(sel!=1) {
      $(this).removeClass("menuitemsel");
    }
    sel='';
  })


  $(".drop-aff, .affdropmenu").hover(function() {
    $(".affdropmenu").show();
  }, function() {
    $(".affdropmenu").hide();
  })

  $(".drop-patcare, .patcaredropmenu").hover(function() {
    $(".patcaredropmenu").show();
  }, function() {
    $(".patcaredropmenu").hide();
  })

  $(".drop-about, .aboutdropmenu").hover(function() {
    $(".aboutdropmenu").show();
  }, function() {
    $(".aboutdropmenu").hide();
  })

  var dropsel='';

  $(".dropmenuitem").hover(function() {
    if($(this).hasClass("dropmenuitemsel")) {
      dropsel=1;
    }
    $(this).addClass("dropmenuitemsel");
  }, function() {
    if(dropsel!=1) {
      $(this).removeClass("dropmenuitemsel");
    }
    dropsel='';
  })

  pos='';
  vis1=vis2=vis3=vis4='';

  $(".pat1, .pat2, .pat3, .pat4").hover(function() {
    if($(this).css("background-position")=="50% 100%") {
      pos=1;
    } else {
      $(this).css("background-position","bottom");
    }

    if($(".text1").css("visibility")=="visible") {
      vis1="visible";
    } else if($(".text2").css("visibility")=="visible") {
      vis2="visible";
    } else if($(".text3").css("visibility")=="visible") {
      vis3="visible";
    } else if($(".text4").css("visibility")=="visible") {
      vis4="visible";
    }


    if($(this).hasClass("pat1")) {
      $(".text1").css("visibility","visible");
    } else if ($(this).hasClass("pat2")) {
      $(".text2").css("visibility","visible");
    } else if($(this).hasClass("pat3")) {
      $(".text3").css("visibility","visible");
    } else if($(this).hasClass("pat4")) {
      $(".text4").css("visibility","visible");
    }
  }, function() {
    if(pos==1) {} else {
      $(this).css("background-position","top");
    }
    pos='';
    $(".text1").css("visibility",vis1);
    $(".text2").css("visibility",vis2);
    $(".text3").css("visibility",vis3);
    $(".text4").css("visibility",vis4);

    vis1=vis2=vis3=vis4='';

  });

  $(".popup").tipTip();

  $(".askdoc").hover(function() {
    $("#doctornote").show();
  }, function() {
    $("#doctornote").hide();
  });

  $(".askdoc2").hover(function() {
    $("#doctornote").show();
  }, function() {
    $("#doctornote").hide();
  });

  $(".sub-btn").live('click', function() {
    if(document.contactfrm.fullname.value.length>0 && document.contactfrm.email.value.length>0) {
        $(".popcontact").hide();
        document.contactfrm.submit();
      } else {
        alert("You must fill in the name and email fields.")
      }
  });

  $(".sub-btn2").live('click', function() {
    if(document.contactfrm.fullname2.value.length>0 && document.contactfrm.email.value.length>0) {
        $(".popcontact").hide();
        document.contactfrm.submit();
      } else {
        alert("You must fill in the name and email fields.")
      }
  });

  $(".schedappt").click(function() {
    $(".apptform").fadeIn("fast");
    $("input[type=text]:first").focus();
  });

  $(".cnlappt").click(function() {
    $(".apptform").hide();
  });

  $(".clickshow").click(function() {
    $(this).hide();
    $(".showmore").show();
    $("#mainbody").height($(document).height()-390);
    $(".leftthird").css("height","100%");
    $(".middlethird, .rightthird").css("height","100%");
  });

  $(".clickhide").click(function() {
    $(".showmore").hide();
    $(".leftthird").css("height","900px");
    $(".middlethird, .rightthird").css("height","900px");

    $("#mainbody").height(1058);
    $(".clickshow").show();
  });
/*
  $(".askdoc, .askdoc_slider").click(function() {
//    $(".popcontact").show();
//alert($(this).css("background-position"));
    if($(".askdoc").css("background-position")=="50% 100%") {} else {
      $(".askdoc").css("background-position","bottom");
      $(".askdoc").html('<p><br><form name="contactfrm" method="post" action="'+base_url+'_includes/mail.php"><table cellspacing=0 cellpadding=0 style="margin-left:20px;">'+
        '<tr><td width=60 align=left>Name:</td><td><input type="text" name="fullname" style="width:130px;"></td></tr>'+
        '<tr><td align=left>Email:</td><td><input type="text" name="email" style="width:130px;"></td></tr>'+
        '<tr><td align=left>Phone:</td><td><input type="text" name="phone" style="width:130px;"></td></tr>'+
        '<tr><td align=left>Message:</td><td><textarea name="message" style="width:128px;height:60px;"></textarea></td></tr>'+
        '<tr><td colspan=2 align=right><input type="button" value="Send" class="sub-btn sm-btn">'+
          '<input type="button" value="Cancel" class="cancel-btn sm-btn"></td></tr></table></form>'+
          '<script>document.contactfrm.fullname.focus();</script>');
    }
  });
*/
  $(".cancel-btn").live('click', function() {
    $(".askdoc").css("background-position","top");
    $(".askdoc").html('.');
  });
  $(".cancel-btn2").live('click', function() {
    $(".askdoc2").css("background-position","top");
    $(".askdoc2").html('.');
  });


  $(".cancel-btn-about").live('click', function() {
    $(".middlethird").html('<span class="sectionhead">Community Commitment</span>'+
      '<p>Thrive Physical Medicine is a member of the Oceanside and Carlsbad Chambers of Commerce.   We consider it part of our responsibility to reach out into the local community and help to promote health and wellness.  We are interested in hearing about opportunities where our presence at health and well-centric events and activities can make a difference.  Call today or click <a href="#" class="contactlink">here</a> to have our medical staff, massage therapists, stretching coaches, or other health and wellness representatives attend your event!"'+
      '<p><br><br><a href="#"><img src="'+base_url+'_images/bannerLearn-More.png" border=0 class="scootleft"></a></div>');
    $(".middlethird").css("height","320px");
  });

});


$(window).load(function() {
    $('#slider').nivoSlider({
//      effect: 'boxRain', // For slice animations
      effect: 'fade', // For slice animations
      boxCols: 8, // For box animations
      boxRows: 4, // For box animations
      animSpeed:500,
      controlNav:true,
      directionNav:false, // Slide transition speed
      pauseTime:8000,
      pauseOnHover:false

    });

    $("#mainbody").height($(document).height()-420);

});
