$(document).ready(function(){
// Making page column heights the same as the largest
	var rightCol = $('#mainContent .rightCol').height();
	if($('#content > div').hasClass('home') != true && $('#content > div').hasClass('forKids') != true && $('#content > div').hasClass('partners') != true) { if(rightCol < 655) { $('#mainContent .rightCol').height(655); }}
	else if($('#content > div').hasClass('forKids') == true){ if(rightCol < 915) { $('#mainContent .rightCol').height(915); }}
});

$(function() {
//overlays
	//Player Profile Overlay
	$('.overlayContent').hide();
	$('.showOverlay').click(function() {
		var overlayID = $(this).attr('rel');
		if(overlayID != "") { $('#'+overlayID).show(); }
		else { return false; }
		openOverlay();
		return false;
	});
	
	//Photo Carousel Overlay
	var pos = 0;
	$('#imgViewer a').click(function() {
		var gallery = $('#imgViewer img');
		var arr = new Array();
		var arrTitle = new Array();
		var imgIndex = $('#imgViewer a').index(this);
		var title = $(this).children('img').attr('alt');
		
		pos = imgIndex;
		
		for(var i=0;i<gallery.length;i++) { 
			arr[i] = $('#imgViewer a:eq('+i+')').html();
			arrTitle[i] = $('#imgViewer img:eq('+i+')').attr('alt');
		}
		openOverlay();
		$('#overlayContainer .close').after('<div id="imgGallery" class="overlayContent"><h2>Photo Title</h2><div id="galleryContainer"><div id="prevImg"><a href="#"><img src="images/btn_previous.gif" alt="Previous" /></a></div><ul id="gallery"></ul><div id="nextImg"><a href="#"><img src="images/btn_next.gif" alt="Next" /></a></div></div></div>');
		$('#imgGallery h2').text(arrTitle[imgIndex]);
		for(var j=0;j<arr.length;j++){ $('<li></li>').html(arr[j]).appendTo('#gallery'); }
		$('#gallery li').hide().filter('#gallery li:eq('+imgIndex+')').show();
		//alert(imgIndex+" "+arr+" "+arrTitle);
		$('#prevImg a').click(function() { previousImage(arr, arrTitle); return false; });
		$('#nextImg a').click(function() { nextImage(arr, arrTitle); return false; });
		return false;
	});
	
	$('#overlayBg, .close').click(function() {
		$('#overlay').fadeOut(100);
		$('.overlayContent').hide();
		$('#overlayBg').hide();
		return false;
	});
	
	function openOverlay() {		
		$('#overlayBg').show();
		$('#overlay').fadeIn(400);
	}
	function previousImage(aImg,aTitle) {
		pos = pos-1;
		if (pos == -1) { pos = aImg.length-1; }		
		$('#gallery li').hide().filter('#gallery li:eq('+pos+')').fadeIn(400);
		$('#imgGallery h2').text(aTitle[pos]);
	}
	function nextImage(aImg,aTitle) {
		pos = pos+1;
		if (pos ==  aImg.length-1) { pos = 0; }
		$('#gallery li').hide().filter('#gallery li:eq('+pos+')').fadeIn(400);
		$('#imgGallery h2').text(aTitle[pos]);
	}
});