$(document).ready(function() {

	$('#topOfPage').click(function(e) {
		e.preventDefault();
		$('html,body').stop(true).animate({scrollTop:0},500);
	});

//	equalHeight($('.col.grid').not('.width12'));
//	equalHeight($('.col.grid2').not('.width12'));
	equalHeight($('ul.release-grid li'));
	$('.invisible').hide().removeClass('invisible').fadeIn('slow');
	$('.post-it').after('<div class="post-it-footer">&nbsp;</div>');
	$('.calendar-date').append('<div class="calendar-date-footer">&nbsp;</div>');
	/* set release info box min-height to height of packshot & buttons col */
	/*$('.release-info').css({'min-height': $('.release-packshot-buttons').height()-42});*/
	$('.list ul').each(function() {
		$(this).children('li:even').addClass('alt');
	});

	$('.article-text hr').wrap('<div class="hr clear" />');
	$('.grid-article-3cols .col').each(function() {
		$(this).children('.panel:last').addClass('last-panel');
	});

	var bgHeight = 683;
	var windowHeight = ($(window).height()-222);

	if (windowHeight > bgHeight)
		bgHeight = windowHeight
	$('.container').css('min-height', bgHeight-$('.footer').height());

	$("a[href='#']").each(function() {
		var myText = $(this).html();
		myText = myText.replace(/<[^>]*>/g, "");
		myText = myText.replace(/ /g, "_");
		myText = myText.replace(/&amp;/g, "And");
		this.href = '#'+myText;
		//this.href = 'javascript:';
	});
});


function equalHeight(group) {
	var tallest = 0;
	group.each(function() {
		var thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}

function getTallest(group) {
	var tallest = 0;
	group.each(function() {
		var thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	return tallest;
}


function smoothLoadContent(ele, sourceURL) {
	$(ele).parent().height($(ele).height());
	$(ele).animate( {'opacity':0}, 500, function() {

		$(ele).load(sourceURL, {}, function() {
		
			var newheight = $(ele).height();
			$(ele).parent().animate(
				{height: newheight},
				{duration: 500});

			$(ele).fadeIn('slow');
			$(ele).animate( {'opacity':1}, 500);

		})
	});
}

function validEmail(email) {
	var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
	return emailPattern.test(email);
}
function jqLoadContent(elementSelector, sourceURL) {

	var ele = "#"+elementSelector;
	
	var addHeight = 0;
	if ($.browser.msie) {
		$(ele).load(sourceURL);
		return true;
	} else if ($.browser.mozilla) {
		if (elementSelector == 'events-list')
			addHeight = 12;
	}

	$(ele).parent().height($(ele).height());
	$(ele).animate( {'opacity':0}, 250, function() {

		$(ele).load(sourceURL, {}, function() {
		
			var newheight = $(ele).height()+addHeight;
			$(ele).parent().animate(
				{height: newheight},
				{duration: 250});

			$(ele).fadeIn('slow');
			$(ele).animate( {'opacity':1}, 250);

		})
	});
}

