$(function(){

	$('#header .quickLinks .button').bind('click', function(){
		$(this).parent().toggleClass('quickLinksExpanded').find('ul').toggle();
	});

	$('div.newsEventsBlock .tab').bind('click', function(){
		$(this).parents('.newsEventsBlock').toggleClass('eventsBlock');
		$(this).parents('.newsEventsBlock').find('.news').toggle();
		$(this).parents('.newsEventsBlock').find('.events').toggle();
		return false;
	});

	$('div.igxDwmCal .content .date a').map(function(index){
		$(this).bind('click', function(){
			$(this).parents('li').toggleClass('expanded').find('ul').eq(0).slideToggle();
			return false;
		});
	});

	$(".hiddenLi").hide();
	$(".blockGrid .more").show();
	//when you click more, show additional links, hide the more button, and resize the divs.
	$(".blockGrid .more a").map(function(index){
		$(this).bind('click', function(){
			//show hidden links
			$(this).parents('.linksBlock .body').find('li.hiddenLi').toggle();
			//hide the more button
			$(this).parents('.more').hide();
			
			//get the row class
			var classList = $(this).parents('div.linksBlock').attr('class').split(/\s+/);
			$.each( classList, function(index, item){
			    if (item.indexOf("row") == 0) {
					normalizeRowHeights(item);
			    }
			});
			return false;
		});
	});
	//resize all the rows at page load
	normalizeRowHeights("row1");
	normalizeRowHeights("row2");
	normalizeRowHeights("row3");
	normalizeRowHeights("row4");
});

function normalizeRowHeights(rowClass) {
	$(".blockGrid ." + rowClass + " .body").height("auto");
	var maxHeight = Math.max.apply(null, $(".blockGrid ." + rowClass + " .body").map(function ()
	{
	    return $(this).height();
	}).get());

	$(".blockGrid ." + rowClass + " .body").height(maxHeight);
}
