
var float_out_strip = function(obj, normal_w, full_w) {
        $(obj).siblings().not(obj).animate({ width: normal_w},'fast');
        $(obj).siblings().not(obj).find('p').animate({ opacity: 'hide' },'fast');
        $(obj).animate({ width: full_w},'fast');
        $(obj).find('p').animate({ opacity: 'show' },'fast');
      };
var float_in_strip = function(obj, normal_w) {
        $(obj).children().animate({ width: normal_w},'fast');
        $(obj).find('p').animate({ opacity: 'hide' },'fast');
      };
$(document).ready(function() {
    $('li.item').each(function() {
      $(this).fadeOut("fast");
      $(this).fadeIn("fast");
    });
    var mousing_over = false;
    $('.scm-sidebar div.summary').animate({opacity: 'hide', height: 'hide'},'fast');
    $('.scm-sidebar li.item').find('div.summary').each(function() {
         var my_text = $(this).text();
         if(!my_text.match(/^\s*$/)) {
           $(this).parents('li.item').each(function() {
             $(this).find('div.headline').prepend(' <a class="sidebar-more-link" href="#">&gt;<\/a>');
             $(this).find('div.headline a.sidebar-more-link').click(function() {
               $('li.item').each(function() {
                 $(this).fadeOut("fast");
                 $(this).fadeIn("fast");
               });
               $(this).parents('li.item').find('div.summary').slideToggle();
             });
           });
         }
       });
if(false) {
    $('.scm-sidebar li.item').hover(function() {
       if(!mousing_over){
         mousing_over = true;
         $(this).find('div.summary').animate({opacity: 'show', height: 'show'},'slow', function() { mousing_over = false});
       }
       else{
	setTimeout(function(){
			mousing_over = true;
		        $(this).find('div.summary').animate({opacity: 'show', height: 'show'},'slow', function() { mousing_over = false});
			mousing_over = false;
			}, 500);
      }
      },function() {
       $(this).find('div.summary').animate({opacity: 'hide', height: 'hide'},'slow'); return false;
      });
}
    $('.fp_image_stack p, .three-strip p, .photo-stack p').css({display: 'none', position: 'absolute', bottom: '0px', height: '4em'});
    $('.fp_image_stack>li').hover(function() { float_out_strip(this, '164px','298px') }, function() {});
    $('.three-strip>li').hover(function() { float_out_strip(this, '178px','298px') }, function() {});
    $('.photo-stack>li').hover(function() { float_out_strip(this, '256px','256px') }, function() {});
    $('.fp_image_stack').hover(function() {},function() { float_in_strip(this, '198px') });
    $('.three-strip').hover(function() {},function() { float_in_strip(this, '216px') });
    $('.photo-stack').hover(function() {},function() { float_in_strip(this, '256px') });
  });
var gallery_current_img = 0;
var gallery_num_imgs = 0;
var gallery_current_img_url = '';
var animate_gallery = function(i) {
  //alert(i);
  $('.sitegallery-image-full').eq(gallery_current_img).animate({ opacity: 'hide'},'slow');
  $('.sitegallery-image img').eq(gallery_current_img).css('border','solid 2px white');
  gallery_current_img = i - 1;
  $('.sitegallery-image-full').eq(gallery_current_img).animate({ opacity: 'show'},'slow');
  $('.sitegallery-image img').eq(gallery_current_img).css('border','solid 2px green');
}
$(document).ready(function() {
  $('.gallery-image-viewer').append('<div id="gallery-nav"><a href="#" id="gallery-nav-prev">&lt;&lt; Previous</a> <a href="#" id="gallery-nav-next">Next &gt;&gt;</a></div>');
  $('.gallery-image-viewer').animate({ opacity: 'show'},'fast');
  $('.sitegallery-image').eq(gallery_current_img).children('a').each(function() {
    gallery_current_img_url = this.href;
  });
  $('.sitegallery-image img').css('border','solid 2px white');
  $('.sitegallery-image img').eq(gallery_current_img).css('border','solid 2px green');
  $('.sitegallery-image').each(function() {
    gallery_num_imgs++;
    $(this).click(function() {
        var id = this.id;
        var the_index = id.replace('sitegallery-thumb-','');
        animate_gallery(the_index);
        return false;
    });
  });
  $('a#gallery-nav-prev').click(function() {
   //alert('gallery_current_img = '+gallery_current_img+'\/gallery_num_imgs = '+gallery_num_imgs);
   var index = ((gallery_num_imgs + gallery_current_img - 1) % gallery_num_imgs) + 1;
   //alert('index = '+index);
   animate_gallery(index);
   return false;
  });
  $('a#gallery-nav-next').click(function() {
   //alert(gallery_current_img);
   var index = ((gallery_num_imgs + gallery_current_img + 1) % gallery_num_imgs) + 1;
   //alert(index);
   animate_gallery(index);
   return false;
  });
});
$(document).ready(function() {
  var survival_page = $('dl.survival-question').size();
  $('table.searchable-table').css('background-color','#eeeeee');
  $('table.searchable-table td').css('border-top','solid 1px #ffffff');
  $('table.searchable-table td').css('padding-bottom','12px');
  $('table.searchable-table').each(function() {
      var keywords = new Array();
      var row_index = 0;
      $(this).find('tr').each(function() {
          if(row_index > 0) {
            $(this).addClass('searchable-table-row-'+row_index);
            $(this).addClass('nonsticky-table-row');
            //$(this).children().eq(0).prepend('<a name="searchable_row_'+row_index+'">Row '+row_index+'<\/a><br \/>');
            $(this).children().eq(0).each(function() {
//var my_html = $(this).html();
//if(row_index == 3) alert(my_html);
//my_html = 'Hi<br \/>there!';
//this.innerHTML = my_html;
//$(this).html(my_html);
//my_html = this.innerHTML;
//if(row_index == 3) alert(my_html);
//var my_subjects = my_html.split(/<br \/>/m);
//$(this).prepend('Row '+row_index+' ['+my_subjects.length+' subjects]<br \/>');
                var my_html = this.innerHTML;
                var my_subjects = my_html.split(/<br[^>]*>/mgi);
                for(i = 0; i < my_subjects.length; i++) {
                  var subject = my_subjects[i];
                  var subject_cleaned = subject.replace(/\([^)]*\)/g,'');
                  subject_cleaned = subject_cleaned.replace(/\s+/gm,' ');
                  subject_cleaned = subject_cleaned.replace(/\s+$/gm,'');
                  subject_cleaned = subject_cleaned.replace(/^\s+/gm,'');
                  if(subject_cleaned.length > 0) {
                    if(!keywords[subject_cleaned]) {
                      keywords[subject_cleaned] = new Array();
                    }
                    keywords[subject_cleaned].push(row_index);
//if(row_index == 1) alert(subject_cleaned);
                    //$(this).prepend('Entry #'+i+' added for "'+subject_cleaned+'"<br \/>');
                  }
                }
                //$(this).prepend('Row '+row_index+' ['+my_subjects.length+' subjects]<br \/>');
              });
            $(this).children().eq(1).each(function() {
                var phone = $(this).next().html();
                $(this).append('<br />'+phone);
                $(this).next().html("");
                var email = $(this).next().next().html();
                $(this).append('<br />'+email);
                $(this).next().next().html("");
              });
          } else {
            $(this).addClass('sticky-table-row');
            $(this).children().eq(0).each(function() {
                var select_title = $(this).text();
                $(this).html('<select style="font-size: 12px; border: solid 1px black;" class="searchable-selector"><option value="">'+select_title+'...</option></select>');
              });
          }
          row_index++;
        });
      var subject_keys = [];
      for (k in keywords) subject_keys.push(k);
      subject_keys.sort();
      for (i = 0; i < subject_keys.length; ++i) {
        var keyword = subject_keys[i];
        var tag_string = keywords[keyword].join('.');
        $(this).find('select.searchable-selector').append('<option value="'+tag_string+'">'+keyword+'</option>');
      }
      var table = this;
      $(this).find('select.searchable-selector').change(function() {
//alert($(this).val());
          if($(this).val() == "") {
            $(table).find('tr').not(0).show();
          } else {
            var tag_string = $(this).val().split('.');
            $(table).find('tr.nonsticky-table-row').hide();
            for(i = 0; i < tag_string.length; i++) {
              $(table).find('tr.searchable-table-row-'+tag_string[i]).show();
            }
          }
          return false;
        });
    });
  $('dl.survival-question').children('dd').addClass('dynamic-text');
  $('dl.survival-question').children('dd').not('.survival-intro').slideUp();
  $('dl.survival-question').children('dt').css('cursor','pointer');
  $('dl.survival-question').children('dt').click(function() {
      var my_text = $(this).next()[0];
      $('#content_scroller > p').slideUp();
      $(this).parent().children('dd').not(my_text).slideUp();
      $(my_text).slideDown();
      return false;
    });
});
