jQuery.fn.vjustifyHeight=function() {
  var maxHeight=0;
  this.each(function(){
    if (this.offsetHeight>maxHeight) {maxHeight=this.offsetHeight;}
  });
  this.each(function(){
    jQuery(this).css('height',(maxHeight + "px"));
    if (this.offsetHeight>maxHeight) {
      jQuery(this).css('height',((maxHeight-(this.offsetHeight-maxHeight))+"px"));
    }
  });
};
//Modified version of vjustify that applies the value as a min-height rather than a height
jQuery.fn.vjustifyMinHeight=function() {
  var maxHeight=0;
  this.each(function(){
    if (this.offsetHeight>maxHeight) {maxHeight=this.offsetHeight;}
  });
  this.each(function(){
    jQuery(this).css('min-height',(maxHeight + "px"));
    if (this.offsetHeight>maxHeight) {
      jQuery(this).css('min-height',((maxHeight-(this.offsetHeight-maxHeight))+"px"));
    }
  });
};
jQuery.fn.vjustifyMinHeightMinusMarginsAndPadding=function() {
  var maxHeight=0;
  this.each(function(){
    if (this.offsetHeight>maxHeight) {maxHeight=this.offsetHeight;}
  });
  this.each(function(){
    var pt = parseInt(jQuery(this).css('padding-top'));
    var pb = parseInt(jQuery(this).css('padding-bottom'));
    var mt = parseInt(jQuery(this).css('margin-top'));
    var mb = parseInt(jQuery(this).css('margin-bottom'));
    var p = pt + pb;
    var m = mt + mb;
    jQuery(this).css('min-height',((maxHeight-p-m) + "px"));
    if (this.offsetHeight>maxHeight) {
      jQuery(this).css('min-height',((maxHeight-(this.offsetHeight-maxHeight))+"px"));
    }
  });
};


jQuery.fn.setMinHeight = function(setCount) {
  for(var i = 0; i < this.length; i+=2) {
    var curSet = this.slice(i, i+2), 
        height = 0;
    curSet.each(function() { height = Math.max(height, $(this).height()); })
          .css('min-height', height);
  }
  return this;
};


// OVERLABEL: Position the label over the form element and hide it when given focus or if there is content
jQuery.fn.overlabel = function( options ) {
	// build main options before element iteration
	var opts = $.extend( {}, $.fn.overlabel.defaults, options );
	var selection = this.filter( 'label[for]' ).map( function() {
		var label = $( this );
		var id = label.attr( 'for' );
		var field = document.getElementById( id );
		if ( !field ) return;
		// build element specific options
		var o = $.meta ? $.extend( {}, opts, label.data() ) : opts;
		label.addClass( o.label_class );
		var hide_label = function() { label.css( o.hide_css ) };
		var show_label = function() { this.value || label.css( o.show_css ) };
		$( field )
			 .parent().addClass( o.wrapper_class ).end()
			 .focus( hide_label ).blur( show_label ).each( hide_label ).each( show_label );
		return this;
	} );
	return opts.filter ? selection : selection.end();
};
// publicly accessible defaults
jQuery.fn.overlabel.defaults = {
	label_class:   'overlabel-apply',
	wrapper_class: 'overlabel-wrapper',
//	hide_css:      { 'text-indent': '-10000px' },
//	show_css:      { 'text-indent': '0px', 'cursor': 'text' },
	hide_css:      { 'display': 'none' },
	show_css:      { 'display': 'block', 'cursor': 'text' },
	filter:        false
};



//Build accordion
jQuery.fn.buildAccordion = {
 init: function(){
  $('.collapsible-items dd').hide();
  $('.collapsible-items').addClass('active');
  $('.collapsible-items dt').click(function() {
  	$(this).next('dd').slideToggle('fast');
  	$(this).toggleClass('open');
  });
 } // End init
}


jQuery(document).ready(function(){
	
	jQuery('body').addClass('has-js');
	
	jQuery.fn.buildAccordion.init();
		
	//jQuery('.searchbox label[for=query]').overlabel();
	
	//jQuery('.content .list-items').each(function(index) {
	//	jQuery(this).children('dl').setMinHeight(2);
	//	jQuery(this).find('li').setMinHeight(2);
	//});
	
	//jQuery('.quicklinks').each(function(index) {
	//	jQuery(this).find('.item div').vjustifyMinHeight();
	//});
	
	//jQuery('.content').each(function(index) {
	//	jQuery(this).children('div').vjustifyMinHeightMinusMarginsAndPadding();
	//});
	
	/* Add GA tracking onto each external registration link */
	jQuery('a.register').each(function() {
		var registerURL = jQuery(this).attr('href');
		_gaq.push(function() {  
			var pageTracker = _gat._getTrackerByName();  
			registerURL = pageTracker._getLinkerUrl(registerURL);  
		});
		jQuery(this).attr('href', registerURL);
	});

	jQuery('a.register').colorbox({iframe:true,width:'1100px',height:'700px',opacity:'0.75',overlayClose:false});
	 
	jQuery('.breadcrumb li a[href$="/events/"], .breadcrumb li a[href$="/fae/"], .breadcrumb li a[href$="/info/"], .breadcrumb li a[href$="/partners/"], .breadcrumb li a[href$="/colophon/"]').parent('li').remove();
	 
});
