$(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'
  };
  
  // dropdown nav effects
  $('#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 
  });

  // 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');
  });
  
  //Qtip styles for Health Library EBSCO
        $('#site-search 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'}}
  });
/*
  // Check for iPad
  // you can additionally add |iPod|iPhone to this statement
  if (navigator && navigator.platform && navigator.platform.match(/^(iPad)$/)) {
    $('#promo-tabs-container') 
      .after('<ul id="ipad-promo-tabs-selectors">') 
      .cycle({
        cleartype:  1, 
        timeout: 0, 
        effect: 'fade',
        pager:  '#ipad-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>'; 
        }
      });    
  } else {  
    $('#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-tabs-container').hover(function(){
      $('#promo-tabs-container').cycle("pause");
  });
  
  if($.browser.msie){
    $('#promo-tabs-selectors li').css('filter','progid:DXImageTransform.Microsoft.BasicImage(rotation=1)');    
  }
*/
}); // end document.ready

/*
// This function is called when an error is thrown by the player
function onPlayerError(errorCode) {
	alert("An error occured of type:" + errorCode);
}

// for each promo content 1 2 etc, hide the image
// also, make slideshow pause when video is playing

// take away image thumb
function videoBegin1(playState) { checkPlayState(1, playState); }
function videoBegin2(playState) { checkPlayState(2, playState); }
function videoBegin3(playState) { checkPlayState(3, playState); }
function videoBegin4(playState) { checkPlayState(4, playState); }
function videoBegin5(playState) { checkPlayState(5, playState); }

function checkPlayState(playerId, playState) {
  // removes image thumbnail when video plays
  // and adds image thumbnail when video is ended or cued
  // console.log(playState);

  $('#play' + playerId).click(function() {
    $(this).addClass('playing');
  });
  
  if(playState == 1 && $('#play' + playerId).hasClass('playing') ) { // removes image when video is played
    $('#promo-tabs-container').cycle("pause");
    
    $('img.vthumb'+playerId).hide();
  
    $('.video-wrap').animate({
      height: '529px'
    }, 500, 
    function() {
          $('.promo-text').fadeOut();        
    });
    
  if($.browser.msie) {
    $('#promo-tabs-selectors li,#promo-tabs-selectors li a').animate({
      width:'529px'
    }, 500);
  } else {
    $('#promo-tabs-selectors li a').animate({
        width:'519px'
      }, 500);
  }

    $('.vid-controls').animate({
      top: '479px'
    }, 500);
    
  } else if(playState == 0 || playState == 5 || playState == -1) { // adds image back when video ends or is cued up
    //$('#promo-tabs-container').cycle("resume");
    $('#play' + playerId).removeClass('playing');

    $('.video-thumb').show();

    $('.video-wrap').animate({
      height: '320px'
    }, 500,
    function() {
      $('.promo-text').fadeIn();        
    });
    
    $('#promo-tabs-selectors li a').animate({
      width:'310px'
    });
    
    $('.vid-controls').animate({
      top: '270px'
    }, 500);
    
  } else if(playState == 2) {
    $('.video-wrap').animate({
      height: '320px'
    }, 500, 
    function() {
      $('.promo-text').fadeIn();
    });
    
    $('#promo-tabs-selectors li a').animate({
      width:'310px'
    });
    
    $('.vid-controls').animate({
      top: '270px'
    }, 500);
  }
}

function setVolume(newVolume) {
  if (ytplayer) {
    ytplayer.setVolume(37);
  }
}

function playerParams(ytplayer, videoId, playerId) {
  ytplayer.cueVideoById(videoId);
  ytplayer.addEventListener("onStateChange", "videoBegin"+playerId);
}

var ytplayerIds = [];

function onYouTubePlayerReady(playerId) {
  ytplayer = document.getElementById("myytplayer"+playerId);
  videoId = ytplayerIds[playerId - 1];
  // videoId = $("#myytplayer"+playerId+' param[name="videoId"]').attr('value');
  playerParams(ytplayer, videoId, playerId);
}

function playVideo(playerId){
  ytplayer = document.getElementById("myytplayer"+playerId);
  ytplayer.playVideo();
  $('#promo-tabs-container').cycle("pause");
}

function pauseVideo(playerId) {
  ytplayer = document.getElementById("myytplayer"+playerId);
  ytplayer.pauseVideo();
}
*/