function FixFlash(containerID){
	var flashContainer = document.getElementById(containerID);
	var flashMovie = document.createElement("div");
	flashMovie.innerHTML = flashContainer.innerHTML.replace(/</g, "<").replace(/>/g, ">");
	flashContainer.parentNode.insertBefore(flashMovie, flashContainer);
	flashContainer.parentNode.removeChild(flashContainer);
	flashMovie.setAttribute("id",containerID);
}

function ToggleVisibility(elid){
	if (document.getElementById(elid)){
		if (document.getElementById(elid).style.display == 'none'){
			document.getElementById(elid).style.display = 'block';
		}else{
			document.getElementById(elid).style.display = 'none';
		}
	}
}

function setEventCalendar(month, year) {
	document.frmEventCalendar.month.value = month;
	document.frmEventCalendar.year.value = year;
	document.frmEventCalendar.submit();
}

var askedForDonation = false;
function setupDonation() {
	$(document).ready(function () {
		$('a.askdonationonce').each(function (index) {
			var currentLink = $(this);
			currentLink.click(function () {
				if (!askedForDonation) {
					$.fancybox({
						'showCloseButton': false,
						'overlayColor': '#fff',
						'overlayOpacity': 0.7,
						'padding': 0,
						'margin': 0,
						'href': '#askdonationblock',
						'onStart': function () {
							$('#askdonationblock').css('display', 'block');
						},
						'onClosed': function () {
							askedForDonation = true;
							$('#askdonationblock').css('display', 'none');
							window.open(currentLink.attr('href'));
						}
					});
					return false;
				}
				return true;
			});
		});
	});
}

function setupCarouselFocus() {
	$('.carouselfocus').jCarouselLite({
		btnPrev: '.carouselfocusprev',
		btnNext: '.carouselfocusnext',
		visible: 1,
		start: 0,
		circular: false,
		afterEnd: function(a) {
			var ul = $('.carouselfocus > ul');
			ul.css({ height: $(a).height() });
		}
	});
}

function setupCarouselHome(carouselclassname) {
	$('.' + carouselclassname).jCarouselLite({
		btnPrev: '.' + carouselclassname + 'prev',
		btnNext: '.' + carouselclassname + 'next',
		visible: 1,
		start: 0,
		circular: false,
		afterEnd: function (a) {
			var ul = $('.' + carouselclassname + ' > ul');
			ul.css({ height: $(a).height() });
		}
	});
}

function loadAjaxContentPopup(selector, url) {
	$.get(url, function (data) {
		$(selector).empty().append($(data));
	});
}

function setupDownloadLinkTracking() {
	$(document).ready(function () {
		$('a[href^="/upl/"]').click(function () {
			_gaq.push(['_trackPageview', $(this).attr('href')]);
		});
	});
}
