(function ($) {
    $.fn.equalizeHeights = function() {
	return this.each(function() {
	    maxHeight = 0;
		$(this).find('.adjustHeight').each(function() {
		if (parseInt($(this).height()) > maxHeight) {
		    maxHeight = parseInt($(this).height());
		}
	    });
	    $(this).find('.adjustHeight').each(function() {
		var borders = parseInt(parseInt($(this).css('borderTopWidth')) + parseInt($(this).css('borderBottomWidth')));
		$(this).height(parseInt(maxHeight-borders)+'px');
	    });
	});
    };
    $.fn.dropDown = function() {
	return this.each(function() { 
		$(this).hover(
			    function() { $(this).children().filter('ul').show();}, 
			    function() { $(this).children().filter('ul').hide(); });
	});
    };
    $.fn.setWidth = function(width) {
	return this.each(function() {
	    var borders = parseInt(parseInt($(this).css('borderLeftWidth')) + parseInt($(this).css('borderRightWidth')));
	    $(this).css('width', parseInt(width-borders));
	});
    };
    $.fn.startRotating = function(ds) {
	return this.each(function() {
	    $(this).ctRotator(ds, {
		showCount: 1,
		speed: 3500,
		fadeInSpeed: 750,
		fadeOutSpeed: 750,
		itemRenderer: function(item) {
		    image = new Image(355, 260);
		    return $(image).attr({'src': item.url, 'alt': item.caption, 'title': item.caption});
		}
	    });
	});
    };
})(jQuery);
$(function() {
    $('.adjustableHeightsContainer').equalizeHeights();
    $('#menu > ul > li').dropDown();
    if ($('#yearlyReports img')) {
	$('#yearlyReports img').hover( 
	    function() {
		var newImage = $(this).attr('src').replace('.jpg','_hover.jpg');
		$(this).attr('src', newImage);
	    }, function() {
		var newImage = $(this).attr('src').replace('_hover.jpg','.jpg');
		$(this).attr('src', newImage);
	    });
    }
    if ($('#topImageContainer') && (dataSource !== 'undefined')&& (dataSource.length > 0)) {
	$('#topImageContainer').startRotating(dataSource);
    }
});
