// FUNCTION : SLIDE FADE TOGGLE
$.fn.slideFadeToggle = function(speed, easing, callback) {
	return this.animate({height: 'toggle', opacity: 'toggle'}, speed, easing, callback);};

// PAGE READY
$(document).ready(function () {

	// SETUP FancyZoom
	setupZoom();

	// SLIDESHOW
    $('#slides').cycle({
		    fx: 'fade',
	 	    delay: 4000,
			timeout: '4000',
			speed: '1000',
			next: '#next', 
			prev: '#prev',
			pager: '#slideshow_nav'
    	}
	);
	$(".slide a").hover(
		function() {
			$(this).append("<img class='featured_overlay' src='/workspace/img/featured_overlay.png' width='315' height='120' />");
		},
		function() {
			$(".featured_overlay").remove();
		}
	);


	// NAV CHOOSE LOCATION DROP DOWN
	$("#nav_choose_location").parent().hover(
		function(){
			$("#choose_location_list").slideDown('fast');
		},
		function() {
			$("#choose_location_list").slideUp('fast');
		}
	);


	// SUB NAV ACCORDION
	if ( $('#sub_nav').length > 0 ) {
		$('#sub_nav').accordion({
			active: false,
			header: '> li > a.plus',
			icons: { 'header': 'plus', 'headerSelected': 'minus'},
			collapsible: true,
			autoHeight: false
		});
		$('#sub_nav > li > ul').accordion({
			active: false,
			header: '> li > a.plus',
			icons: { 'header': 'plus', 'headerSelected': 'minus'},
			collapsible: true,
			autoHeight: false
		});
	}


	// THIS SUNDAY NIGHT IS
	$("#this-sunday-night-is strong, .this-sunday-night-is strong").html(whichSunday());


	// MORE INFO LINKS
	$('.link-more, .link-less').click(function() {
		var current_id = "#more-info-" + this.id.substring(15);

		$(this).toggleClass("link-less").toggleClass("link-more");

		$(current_id).slideFadeToggle();
		return false;
	});


	// TABS
	$('#tabs').tabs({ fx: { opacity: 'toggle', duration: 100 } });


	// DROP DOWN FILTERS
	$('.filter').change(function() {
		window.location = $('.filter :selected').val(); 
	});


	$(".encodeurl").click(function() {
		url = $(this).attr("href");
		$(this).attr({href: encodeURIComponent(url)});
		alert("its getting down"+encodeURIComponent(url));
	});


	// SHARE
	$(".share_on_facebook").load(function() {
		alert("test");
		//t=document.title;
		url = location.href;
		link = $(this).attr("href") + "testing!!!";
		
		$(this).attr({href: link});

		//window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
		return true;
	});


	/*************************************************************************
	***** ALL JS BELOW THIS LINE IS LEGACY CODE AND NEEDS WORK OR REMOVAL *****
	*************************************************************************/

	// Form Volunteer Opp Select
	$('form ul#volunteer-opp li').click(function() {
		$('form ul#volunteer-opp li').removeClass("selected").removeAttr("checked");
		$(this).addClass("selected").find("input").attr("checked","checked");
	});

});


// Change Input
function changeInput(input,text) {
	if (input.value == text) {input.value = '';} 
	else if (input.value.length == 0) {input.value = text;}
}