var slider_html = '';

jQuery(function($){
	if($('#slider').length) {
		slider_html = $('#slider').html();
		initSlider();
	}

	/*$('.twitter-text').each(function() {
		$(this).html($(this).html().replace('Camp Highland', 'Camp Highlands'));
		$(this).html($(this).html().replace('CampHighland', 'Camp Highlands'));
	});*/

	$('.facebook-text span').each(function() {
		$(this).html($(this).html().replace('Camp Highland', 'Camp Highlands'));
		$(this).html($(this).html().replace('CampHighland', 'Camp Highlands'));
	});

	$('.twitter-status .twitter-text a').each(function() {
		$(this).remove();
	});

	$('p:not(.dnd)')
    .filter(function() {
        return $.trim($(this).text()) === ''
    })
    .remove();

    $('.slider .container ul li img').each(function(){
    	$(this).parent().parent().parent().parent().find('.captions').append('<li>'+$(this).attr('alt')+'</li>');
    });

    $('.slider .container ul br').each(function(){
    	$(this).remove();
    });

	if($('.slider').length) {
		$('.slider').each(function() {
			$(this).jcarousel({
				visible: 1,
				scroll: 1,
				animation: 500,
				wrap: 'both',
				initCallback: function(carousel) {
					var leng = carousel.container.find('.container li').length;
					carousel.container.find('.idx span:eq(1)').text(leng);

					carousel.container.find('.prev').bind('click', function() {
						carousel.prev();
						return false;
					});
					carousel.container.find('.next').bind('click', function() {
						carousel.next();
						return false;
					});
					carousel.container.find('.slider-nav li:eq(0)').addClass('current').stop().show();
				},
				itemFirstInCallback: function(carousel,item,idx,state) {
					carousel.container.find('.idx span:eq(0)').text(idx);
					if($('.shell').width() > 480) {
						carousel.container.find('.slider-nav li.current').hide();
						carousel.container.find('.slider-nav li').eq(idx-1).show(0, function() {
							$(this).addClass('current').siblings().removeClass('current');
						});
					}
				},
				buttonPrevHTML: null,
				buttonNextHTML: null
			});
		});
	}

	$('#sub-nav a').each(function() {
		$(this).click(function() {
			$('#sub-nav a').each(function() {
				to_show = $(this).attr('class');
				$('h2[id='+to_show+']').parent().hide();
			});
			to_show = $(this).attr('class');
			$('h2[id='+to_show+']').parent().slideDown();
			return false;
		});
	});

	$('.testimonials li').each(function() {
		$(this).find('p:first').prepend('“');
		$(this).find('p:first').append('”');
	});
});

jQuery(window).resize(function() {
	var cur_wid = jQuery('.shell').width();
	if(jQuery('#slider').length) {
		if(jQuery(window).width() <= 1024 && jQuery(window).width() >=768) {
			var new_wid = jQuery('.shell').width();
			if(new_wid < cur_wid) {
				resetSlider();
			}
		} else if(jQuery(window).width() > 1024) {
			var new_wid = jQuery('.shell').width();
			if(new_wid > cur_wid) {
				resetSlider();
			}
		}
	}
	
});

function resetSlider() {
	jQuery('#slider').html(slider_html);
	initSlider();
}

function initSlider() {
	jQuery('#slider .container').jcarousel({
		visible: 1,
		scroll: 1,
		auto: 8,
		animation: 500,
		wrap: 'both',
		itemFirstInCallback: function(carousel, item, idx, state) {
			if(jQuery('.shell').width() > 750) {
				jQuery('#slider .caption').css('bottom', '-415px');
				jQuery('#slider li').eq(idx-1).find('.caption').animate({
					bottom: 0
				}, 300);
			}
		},
		buttonPrevHTML: null,
		buttonNextHTML: null
	});
}
