/*!
 * @copyright 2011-Present Advanced Care Solutions, Inc.
 * @author Christopher Rahauiser <crahauiser@acs-web.com>
 */
(function($) {

  $('a.newwin').click(function(event) {
    event.preventDefault();
    var win = window.open(this.href);
    if (win && win.focus) {
      win.focus();
    }
  });

  $.scrollToElement = function(jqObj) {
    var selector = 'html';
    if (! $.browser.opera) {
      selector += ',body';
    }
    var offsetTop = jqObj.offset().top;
    $(selector).animate({
      scrollTop: offsetTop
    }, 1000);
  };

  var programStripes = $('#programs-stripes');
  $('#back-to-top').click(function(event) {
    event.preventDefault();
    $.scrollToElement(programStripes);
  });

  var lightbox = $('#lightbox');
  var lightboxPanel = $('#lightbox-panel');

  if (lightbox.length > 0 && lightboxPanel.length > 0) {
    var lightboxPanelHeight = lightboxPanel.height();
    var lightboxPanelWidth = lightboxPanel.width();

    function positionLightbox() {
      var windowHeight = $(window).height();
      if (lightboxPanelHeight > windowHeight) {
        return;
      }
      var windowWidth = $(window).width();
      if (lightboxPanelWidth > windowWidth) {
        return;
      }
      var top = (windowHeight - lightboxPanelHeight) / 2;
      var left = (windowWidth -lightboxPanelWidth) / 2;

      lightboxPanel.css({
        'top': top + $(document).scrollTop(),
        'left': left
      });
    }

    function fadeOut() {
      lightbox.fadeOut(300);
      lightboxPanel.fadeOut(300);
    }

    $(window).bind('resize scroll', positionLightbox);

    $(".show-panel").click(function(event) {
      event.preventDefault();
      lightbox.fadeIn(300);
      lightboxPanel.fadeIn(300);
      positionLightbox();
    })

    $("#close-panel").click(fadeOut);

    lightbox
      .click(fadeOut)
      .css({
        opacity: 0.75,
        height: $(document).height()
      });
  }
})(jQuery);


  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-21627946-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();


