
function loadContent(elementSelector, sourceURL) {
	$(""+elementSelector+"").load(""+sourceURL+"",function(response, status, xhr) {
	if (status == "error") {
		var msg = "Sorry but there was an error: ";
		$(""+elementSelector+"").html(msg + xhr.status + " " + xhr.statusText);
	}
	});
};


function startCloudCarousel(elementSelector, containerWidth, containerHeight) {
	$(""+elementSelector+"").CloudCarousel(		
		{			
			xPos: containerWidth/2,
			yPos: containerHeight/8,
			yRadius: containerHeight/4,
			reflHeight: 50,
			reflGap: 2,
			buttonLeft: $("#left-but"),
			buttonRight: $("#right-but"),
			altBox: $("#alt-text"),
			titleBox: $("#title-text"),
			bringToFront: true
		}
	);

}

function loadGallery() {
	$('#carouselInfoContainer1').hide();
	$('#carouselButtonContainer1').hide();
	$('#Advertisement').hide();
	$('#YouHaveAFriendInMe').hide();
	$('#sidebar2').hide();
	$('#contentContainer1').show();
	$('#contentContainer1').css("width",680);
	$('#contentContainer2').show();
	$('#contentContainer2').css("height","auto");
	$('#contentContainer2').css("width",680);
	loadContent('#contentContainer1', 'gallery.htm');	

	jQuery("#contentContainer2").EmbedPicasaGallery('102381035055443706058',{
		matcher: /./,
	//  auto_open: true,
	//  hide_back: true,
	//  show_more: 5,
		size: 144,
		loading_animation: 'Site/images/loading.gif',
		album_title_tag:    '<h3/>'
	 })
}


function loadGoogleCalendar(searchForText) {
	searchText = searchForText;
	google.setOnLoadCallback(getGoogleCalendar());
	
}

function homePage() {
	$('#carouselInfoContainer1').hide();
	$('#carouselButtonContainer1').hide();
	$('#Advertisement').show();
	$('#YouHaveAFriendInMe').show();
	$('#contentContainer1').hide();
	$('#contentContainer2').hide();
	$('#sidebar2').show();
	LoadCollegiateAnnouncement();
	$('body').css({'backgroundImage' : defaultbackgroundimage});
	$('body').css({'background-size' : defaultbackgroundsize});
	document.title = "Kids Kingdom Sports Center";
	$('#emailAddress')[0].innerHTML = 
		'Email: <a href="mailto:eurostarsgymnastics@gmail.com" title="eurostarsgymnastics@gmail.com" id="emailAddress">Euro Stars Gymnastics</a>';
}

function contentContainerLoad(pageURL1, pageURL2, containerWidth, pageTitle, emailAddress, background) {
	if (!containerWidth) {
		var containerWidth = 560;
	}
		
	if (containerWidth <= 560) {
		$('#sidebar2').show();
	}
	else {
		$('#sidebar2').hide();
	}
	
	if (!pageURL1 && !pageURL2) {
		$('#carouselInfoContainer1').show();
		$('#carouselButtonContainer1').show();
		$('#Advertisement').show();
		$('#YouHaveAFriendInMe').show();
	}
	
	if (pageURL1) {
		if (pageURL1.indexOf(".pdf", 0)>=0) {
			window.open(pageURL1,"_new");
		}
		else if (pageURL1.indexOf("http://", 0)>=0) {
			window.open(pageURL1,"_new");
		}
		else {
			$('#carouselInfoContainer1').hide();
			$('#carouselButtonContainer1').hide();
			$('#Advertisement').hide();
			$('#YouHaveAFriendInMe').hide();
			
			loadContent('#contentContainer1', pageURL1);	
			$('#contentContainer1').show();
			$('#contentContainer1').css("width",containerWidth);
			$('#contentContainer1').css("height","auto");
			$('#contentContainer1').css("background","#ffffff");
			$('#contentContainer1').css("color","#000");
		}
	}
	
	if (pageURL2) {
		$('#carouselInfoContainer2').hide();
		$('#carouselButtonContainer2').hide();
		$('#Advertisement').hide();
		$('#YouHaveAFriendInMe').hide();

		loadContent('#contentContainer2', pageURL2);	
		$('#contentContainer2').show();
		$('#contentContainer2').css("height","auto");
		$('#contentContainer2').css("width",containerWidth);
	
		if (!pageURL1) {
			var new_position = $('#contentContainer2').offset();
			window.scrollTo(new_position.left,new_position.top);		
		}
	}
	else {
		$('#contentContainer2').hide();
	}
		
	if (!pageTitle) {
		document.title = "Kids Kingdom Sports Center";
	}
	else {
		document.title = "Kids Kingdom Sports Center - " + pageTitle;
	}
	
	if (emailAddress) {
		if (emailAddress == "Jingle Bell Rock") {
			$('#emailAddress')[0].innerHTML = 
			'Email: <a href="mailto:jinglebellrock2011@gmail.com" title="jinglebellrock2011@gmail.com" id="emailAddress">Jingle Bell Rock 2011</a>';
		}
		else if (emailAddress == "Spring Spectacular") {
			$('#emailAddress')[0].innerHTML = 
			'Email: <a href="mailto:springspect2012@gmail.com" title="springspect2012@gmail.com" id="emailAddress">Spring Spectacular 2012</a>';
		}
		else {
			$('#emailAddress')[0].innerHTML = 
			'Email: <a href="mailto:eurostarsgymnastics@gmail.com" title="eurostarsgymnastics@gmail.com" id="emailAddress">Euro Stars Gymnastics</a>';
		}
	}
	else {
		$('#emailAddress')[0].innerHTML = 
		'Email: <a href="mailto:eurostarsgymnastics@gmail.com" title="eurostarsgymnastics@gmail.com" id="emailAddress">Euro Stars Gymnastics</a>';
	}
	
	if (background) {
		$('body').css({'backgroundImage' : 'url(Site/images/BackgroundThemes/' + background + ')'});
		$('body').css({'background-size' : 'cover'});
	}
	else {
		$('body').css({'backgroundImage' : defaultbackgroundimage});
		$('body').css({'background-size' : defaultbackgroundsize});
	}

}
