__savedHeight = 550;

function resizeTheColorbox(height) {
  if (height > 0) {
    __savedHeight = new Number(height);
    var newHeight = __savedHeight + 50; // addition is the submit button offset
    
    $('#form_buttons .button').colorbox.resize({
      height : newHeight
    });
  }
}

// If the colorbox is closed and reopened, make sure it stays the proper size
$(document).bind('cbox_complete', function(){
  resizeTheColorbox(__savedHeight);
});

$(document).ready(function() {

  // Input placeholders
  $("input[type=text],input[type=email], textarea").placehold();
  
  // Timeline form lightboxes
  if($('#form_buttons a[href=#form_1]')) {
    $('#form_buttons a[href=#form_1]').colorbox({
      'inline' : true,
      'href': '#form_1 iframe',  // selecting the iframe only!
      'width': 750,
      'innerHeight': $('#form_1 iframe').height()
    });
  }
  if($('#form_buttons a[href=#form_2]')) {
    $('#form_buttons a[href=#form_2]').colorbox({
      'inline' : true,
      'href': '#form_2 iframe',  // selecting the iframe only!
      'width': 750,
      'innerHeight': $('#form_2 iframe').height()
    });
  }
  if($('#form_buttons a[href=#form_3]')) {
    $('#form_buttons a[href=#form_3]').colorbox({
      'inline' : true,
      'href': '#form_3 iframe',  // selecting the iframe only!
      'width': 750,
      'innerHeight': $('#form_3 iframe').height()
    });
  }
  
  // Photos Slider
  if($('#photos_slider')) {
    $('#photos_slider').nivoSlider();
  }
  
  // Questions slider
  if($('#questions_slider')) {
    var $slider = $('#questions_slider');
    // Set initial height
    $slider.height($slider.find('li:first-child').outerHeight()+20);
  
    // loop through the items in the scrollable
    // on each grab the height and assing it as part of it's data
    $("#questions_slider li").each(function(){
        var h = $(this).outerHeight() + 20;
        $(this).data("height", h);
    });
    
    // The Scrollable
    // Set the container's height onSeek.	
    $slider.scrollable({
      circular:true,
      onBeforeSeek : function(event,targetIndex){
        var container = this.getRoot(),
      	items = this.getItems(),
      	h = $(items[targetIndex]).data("height");
        container.animate({height:h},350);
      }
    });
  }
  
  
  // Document icons
  // Document and link icons
  $('article a[href$=pdf]').addClass('icon acrobat');
  $('article a[href$=doc]').addClass('icon word');
  $('article a[href$=xls]').addClass('icon excel');
  $('article a[href$=ppt]').addClass('icon powerpoint');
  $('article a[href$=pps]').addClass('icon powerpoint');
  $('article li a[href$=pdf]').parents('li').addClass('icon').parent('ul').addClass('icon');
  $('article li a[href$=doc]').parents('li').addClass('icon').parent('ul').addClass('icon');
  $('article li a[href$=xls]').parents('li').addClass('icon').parent('ul').addClass('icon');
  $('article li a[href$=ppt]').parents('li').addClass('icon').parent('ul').addClass('icon');
  $('article li a[href$=pps]').parents('li').addClass('icon').parent('ul').addClass('icon');
  //$('article li a[href^=http]').parents('li').addClass('icon').parent('ul').addClass('icon');
  //$('article ul.icon a').addClass('icon weblink').parents('li').addClass('icon').parent('ul').addClass('icon');
  
  // Location Maps
  if($('body').hasClass('schools')) {
    if ($('#map').length > 0) $('#map').jMapping({
      side_bar_selector: "#map_locations:first",
      location_selector: ".location",
      link_selector: "a.map_item",
      info_window_selector: ".info_box"
    });
    //if ($('#map').length > 0) $('#map').jMapping();
    
    $('#map_container').stickyScroll({ mode: 'manual', bottomBoundary: 225, topPadding: 10 }); 
  }
   
  
});
