﻿var SEARCH_URL = "/GibbsCancerCenter/Pages/SearchResults.aspx?s=GibbsCancerCenter&k=";

$(document).ready(function () {
   // handle tabs
   var tabContainers = $('div.tabs > div');
   tabContainers.hide().filter(':first').show();

   $('div.tabs ul.tabNavigation a').click(function () {
      tabContainers.hide();
      tabContainers.filter(this.hash).show();
      $('div.tabs ul.tabNavigation a').removeClass('selected');
      $(this).addClass('selected');
      return false
   }).filter(':first').click();
   
   $("#searchBtn").click(function () {
      searchSite();
      return (false);
   });
   
   $("#searchField").keypress(function (e) {
      if (e.keyCode == 13) {
         searchSite();
         return (false);
      }
   });
   
   $("#mewlyDiagnosed").hover(function () {
         $("#mewlyDiagnosed").stop().animate({
            'height': '236px',
            'top': "-74px"
         })
      }, function () {
         $("#mewlyDiagnosed").stop().animate({
            'height': '162px',
            'top': "0px"
      })
   });

   $("#referpatient").hover(function () {
         $("#referpatient").stop().animate({
            'height': '219px',
            'top': "-74px"
         })
      }, function () {
         $("#referpatient").stop().animate({
            'height': '147px',
            'top': "0px"
         })
   });
   
   $("#iampatient").hover(function () {
         $("#iampatient").stop().animate({
            'height': '220px',
            'top': "-77px"
         })
      }, function () {
         $("#iampatient").stop().animate({
            'height': '143px',
            'top': "0px"
         })
   })
   
   // Rollover images
   $(function() {
       $('img[data-hover]').hover(function() {
           $(this).attr('tmp', $(this).attr('src')).attr('src', $(this).attr('data-hover')).attr('data-hover', $(this).attr('tmp')).removeAttr('tmp');
       }).each(function() { // preloads image
           $('<img />').attr('src', $(this).attr('data-hover'));
       });;
   });
   
   $("a[rel^='prettyPhoto']").prettyPhoto({
      animation_speed: 'normal', /* fast/slow/normal */
      opacity: 0.45, /* Value betwee 0 and 1 */
      show_title: false, /* true/false */
      allow_resize: false, /* true/false */
      counter_separator_label: ' of ', /* The separator for the gallery counter 1 "of" 2 */
      theme: 'facebook', /* light_rounded / dark_rounded / light_square / dark_square */
		default_width: 640,
		default_height: 480,
      callback: function() { }
   });
   
});

function searchSite(){
   var $searchField = $("#searchField");
   var searchText = new String($searchField.val());

   if(searchText.length > 0) { window.location = SEARCH_URL + searchText; }
   else { $searchField.css('border', 'solid 1px red').focus(); }
}
