$(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'
  };
  
	// Adds and removes search text
	$('#header #site-search input[type="text"]').addClass('watermark');
	$('#header #site-search input[type="text"]').focus(function(){
		$(this).filter(function(){
			return $(this).val() === '' || $(this).val() === 'Search';
		}).removeClass('watermark').addClass('text').val('');
	}).blur(function(){
		$(this).filter(function(){
			return $(this).val() === '';
		}).removeClass('text').addClass('watermark').val('Search');
	});


  // dropdown nav
  $('#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 
  });
    
    // Video Scroller
  $('#video-library #browsable').scrollable({size: 2}).navigator().mousewheel();
  
  
  // Events and News tabs
  $('#home #content-sub1').tabs();
  
  // Cycle the home tabs
  $('#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) { 
        return '<li class="' + jQuery(slide).attr("id") + ' "><a href="#"><span class="wrap">' + jQuery(slide).find("div.tab-text").html() + '</span><span class="extra"></span></a></li>'; 
      }
  });
  
  $('#promo ul').hover(function(){
    $('#promo-tabs-container').cycle("pause");
    }, function(){
    $('#promo-tabs-container').cycle("resume");
  });
    
$('.featured-services li').hover(
  function(){
    $(this).addClass('service-hover');
  }, function(){
    $(this).removeClass('service-hover');
  }).click( 
  function() {
    window.location = $(this).find('h3 a').attr('href');
}); 
  
    $('#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'}}
  });
  
    $('.form').validate();
    $('form .phone').mask('(999) 999-9999',{placeholder:""});

  	$('#home #yplaylist').before("<div id='playlist-nav'><a href='#' id='prev'>Previous</a> <a href='#' id='next'>Next</a></div>");
});
