$(document).ready(function(){
  
    $.fn.qtip.styles.tipAbove = { // Last part is the name of the style
        background:'#f8f4de',
        border:{width:2,color:'#ece1a5',radius:2},
        color:'#c6a05d',
        fontSize:'11px',
        fontWeight:'bold',
        padding:'2px',
        textAlign:'center',
        tip:'bottomMiddle'
  };
  
  $('#nav-main ul').superfish({ 
    delay:       1000,                            // one second delay on mouseout 
    animation:   {opacity:'show',height:'show'},  // fade-in and slide-down animation 
    speed:       'fast',                          // faster animation speed 
    autoArrows:  false,                           // disable generation of arrow mark-up 
    dropShadows: true                            // disable drop shadows 
  });

  /*$('#promo-tabs-container')*/
  $('#featured-content:not(.alert-status) #promo-tabs-container')
  .after('<ul id="promo-tabs-selectors">') 
  .cycle({ 
    cleartype:  1, 
    timeout: 8000, 
    effect: 'fade',
    speed: 500,
    pause: true,
    pager:  '#promo-tabs-selectors',
    pagerEvent:   'click',
    pagerAnchorBuilder: function(idx, slide) { 
      if(jQuery(slide).next().length > 0){
        //jQuery(slide).next().attr("")
        return '<li class="' + jQuery(slide).attr("id") + '"><a href="#"><span class="wrap">' + jQuery(slide).find("div.tab-text").html() + '</span></a></li>';
      }
      else{
        return '<li class="' + jQuery(slide).attr("id") + '"><a href="#"><span class="wrap">' + jQuery(slide).find("div.tab-text").html() + '</span></a></li>'; 
      }
    },
  after: function(currSlideElement, nextSlideElement, options, forwardFlag){
    if($('#promo-tabs-next-item').length == 0){
      $('#promo-tabs-selectors').append('<li id="promo-tabs-next-item"><h2></h2></li>');
    }
    
    if($(nextSlideElement).next().find('div.promo-text h3').length > 0){
      //console.log($(nextSlideElement).next().find('div.promo-text h3').text());
      $('#promo-tabs-next-item h2').text('Next: ' + $(nextSlideElement).next().find('div.promo-text h3').text());
    }
    else{
      //console.log($(nextSlideElement).parent('div:first').find('#promo-content1 div.promo-text h3').text());
      $('#promo-tabs-next-item h2').text('Next: ' + $(nextSlideElement).parent('div:first').find('#promo-content1 div.promo-text h3').text());
    }
  }
    });
  $('#promo ul').hover(function(){
    $('#promo-tabs-container').cycle("pause");
  }, function(){
    $('#promo-tabs-container').cycle("resume");
  });
  
  $('#home #content-sub1').tabs();

// add hover to service items
$('.featured-services li').hover(
  function(){
    $(this).addClass('service-hover');
  }, function(){
    $(this).removeClass('service-hover');
  }).click( 
  function() {
    window.location = $(this).find('h3 a').attr('href'); // find the h3 a of each service 
});
  
  $('.form').validate();
  $('form .phone').mask('(999) 999-9999',{placeholder:""});
  
    $('#site-search a').qtip({
    width:{max:200},
    style:'tipAbove',
    position:{corner:{target:'topMiddle',tooltip:'bottomMiddle'}}
  });

  $('#home #health-encyclopedia a').qtip({
    width:{max:200},
    style:'tipAbove',
    position:{corner:{target:'topMiddle',tooltip:'bottomMiddle'}}
  });
  
  $('#interior #health-encyclopedia a').qtip({
    width:{max:200},
    style:'tipAbove',
    position:{corner:{target:'topMiddle',tooltip:'bottomMiddle'}}
  });
  
  $('#conditionsAZSearchForm a').qtip({
    width:{max:200},
    style:'tipAbove',
    position:{corner:{target:'topMiddle',tooltip:'bottomMiddle'}}
  });
  
});
