Event.observe(window, 'load', function(e) {
  if($('catParaMetTabset1').select('dt').length > 0) {
		Df.MyCustomTabset = Class.create(Df.Tabset,{
		  buildItems: function($super){
			 $super();
		
			 this.minHeight = 100;
			 this.tabHeight = 38;
			 this.contentElement = 'dd';
			 this.tabElement = 'dt';
		
			 this.attachTabsetHeightEvents();
			 this.updateTabsetHeight(this.element.select(this.tabElement)[0]);
		  },
		
		  updateTabsetHeight: function(elem){
			 var content = elem.next(this.contentElement);
			 if(content.getHeight() < this.minHeight){
				content.style.height = parseInt(this.minHeight - this.tabHeight) + 'px';
			 }
			 var newHeight = parseInt(content.getHeight() + this.tabHeight);
			 this.element.style.height = newHeight + 'px';		
		  },
		
		  attachTabsetHeightEvents: function(){
			 obj = this;
			 obj.element.select(obj.tabElement).each(function(elem){
				elem.observe('click', function(){
				  obj.updateTabsetHeight(elem);
				});
			 });
		  }
		});
		
		$$('#catParaMetTabset1 dd').each(function(elem){
		  elem.setStyle({opacity: 0})
		});
		
		var para = {
		  animate: {
			 time: 100,
			 opacity: 1
		  }
		}
	
		new Df.MyCustomTabset($('catParaMetTabset1'), para).showItem(0);
	
  }
	
// The following JS is used on the category pages to determine if there is a 
//   long title within the category name, and adjusts the entire row.
    if ($$('.catCategoryTitle').length > 0) {
    	var itemsInCategoryRow = 4
    	var catTitleRef = $$('.catCategoryTitle')
    	for(var i=0;i<catTitleRef.length;i+=itemsInCategoryRow) {
      		var catTitleArray = []
      		for(var j=0;j<itemsInCategoryRow;j++) { 
      			if (catTitleRef[i+j]) {catTitleArray.push(catTitleRef[j])}
      		}
          var maxTitleHeight = catTitleRef[0].getDimensions().height
 
      		catTitleArray.each(function(v) {  
         		// Check the height of the title
         		if(maxTitleHeight < v.select('span a')[0].getDimensions().height) {
         		   maxTitleHeight = v.select('span a')[0].getDimensions().height
         		} 
         	});
         	if(maxTitleHeight != catTitleRef[0].getDimensions().height) {
         		maxTitleHeight += 7 //to give some buffer
      		  catTitleArray.each(function(v) {         			 
         		   v.setStyle({height:maxTitleHeight + 'px'})        		  
         	  });
         	}
   	  }
   	}

});
