//Navigation jQuery
$(document).ready(function(){
	
	
		$("ul#topnav li").mouseover(function() {
			$(this).find("ul.subnav").stop().animate({height:'150px'},{queue:false, duration:100});
		});
		
		$("ul#topnav li").mouseout(function() {
			$(this).find("ul.subnav").stop().animate({height:'0px'},{queue:false, duration:100});
		});
		
		$("ul#topnavactive li").mouseover(function() {
			$(this).find("ul.subnav").stop().animate({height:'150px'},{queue:false, duration:100});
		});
		
		$("ul#topnavactive li").mouseout(function() {
			$(this).find("ul.subnav").stop().animate({height:'0px'},{queue:false, duration:100});
		});
		

});


 


function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel({
        auto: 1,
        wrap: 'last',
        initCallback: mycarousel_initCallback
    });
});




if (document.images) {
    img1 = new Image();
    img1.src = "../images/280border.png";
	img2 = new Image();
    img2.src = "../images/34border.png";
	img3 = new Image();
    img3.src = "../images/about.png";
	img4 = new Image();
    img4.src = "../images/bgspannav1.png";
	img5 = new Image();
    img5.src = "../images/darkshadow.png";
	img6 = new Image();
    img6.src = "../images/darkshadow2.png";
	img7 = new Image();
    img7.src = "../images/footerbg.jpg";
	img8 = new Image();
    img8.src = "../images/greybg.jpg";
	img9 = new Image();
    img9.src = "../images/greybgreverse.png";
	img10 = new Image();
    img10.src = "../images/headerbg.png";
	img11 = new Image();
    img11.src = "../images/newdonate.png";
	img12 = new Image();
    img12.src = "../images/newdonatehover.png";
	img13 = new Image();
    img13.src = "../images/search.png";
	img14 = new Image();
    img14.src = "../images/shadowtop.png";
	img1 = new Image();
    img1.src = "../images/280border.png";

}

		//Bottom images for photo galleries and projects
		$(document).ready(function(){  
			

			$("#beforetwo").mouseover(function(){
				$('.beforehover').stop().animate({height:'40px'},{queue:false, duration:600, easing: 'easeOutBounce'})
			});
			
			$("#beforetwo").mouseout(function(){
				$('.beforehover').stop().animate({height:'17px'},{queue:false, duration:600, easing: 'easeOutBounce'})
			});
			
			$("#beforetwo").mouseover(function(){
				$('#beforetwo img').stop().animate({'opacity':'0.5'})
			});
			
			$("#beforetwo").mouseout(function(){
				$('#beforetwo img').stop().animate({'opacity':'1'})
			});
			


			$("#threebefore").mouseover(function(){
				$('.twobeforehover').stop().animate({height:'40px'},{queue:false, duration:600, easing: 'easeOutBounce'})
			});
			
			$("#threebefore").mouseout(function(){
				$('.twobeforehover').stop().animate({height:'17px'},{queue:false, duration:600, easing: 'easeOutBounce'})
			});
			
			$("#threebefore").mouseover(function(){
				$('#threebefore img').stop().animate({'opacity':'0.5'})
			});
			
			$("#threebefore").mouseout(function(){
				$('#threebefore img').stop().animate({'opacity':'1'})
			});
			
			
			
			//$("#biglogo").mouseover(function(){
			//	$('#biglogo').stop().animate({marginTop:'-78px',paddingBottom:'30px'},{queue:false, duration:600, easing: 'easeOutQuad'})
			//});
			
			//$("#biglogo").mouseout(function(){
			//	$('#biglogo').stop().animate({marginTop:'-48px',paddingBottom:'0'},{queue:false, duration:100, easing: 'easeInQuad'})
			//});


			//Begin Calendar Code		   
			calendarAjax();
			
			function calendarAjax() {
				
					$('.prevMonth').live('click', (function() {
							$('#calBlockContain').load($('.prevMonth').attr('id'), function(){
								$('#calBlockContain').show();
							});
							$('#calEvents').hide().load($('.prevMonthEvents').attr('id'), function(){
								$('#calEvents').show('slide', {direction:'up'}, 500);
							});
							$('#calEventsTitle').hide().load($('.prevMonthEventsTitle').attr('href'), function(){
								$('#calEventsTitle').show('slide', {direction:'up'}, 500);
							});
							return false;
					}));
					
					$('.nextMonth').live('click', (function() {
						$('#calBlockContain').load($('.nextMonth').attr('id'), function(){
								$('#calBlockContain').show();
						});
						$('#calEvents').hide().load($('.nextMonthEvents').attr('id'), function(){
								$('#calEvents').show('slide', {direction:'down'}, 500);
						});
						$('#calEventsTitle').hide().load($('.nextMonthEventsTitle').attr('href'), function(){
								$('#calEventsTitle').show('slide', {direction:'down'}, 500);
						});
						return false;
					}));
			};


			calendarAjax2();
			
			function calendarAjax2() {
				
					$('.prevMonthinside').live('click', (function() {
							$('#calBlockContaininside').load($('.prevMonthinside').attr('id'), function(){
								$('#calBlockContaininside').show();
							});
							$('#calEventsinside').hide().load($('.prevMonthEventsinside').attr('id'), function(){
								$('#calEventsinside').show();
							});

							return false;
					}));
					
					$('.nextMonthinside').live('click', (function() {
						$('#calBlockContaininside').load($('.nextMonthinside').attr('id'), function(){
								$('#calBlockContaininside').show();
						});
						$('#calEventsinside').hide().load($('.nextMonthEventsinside').attr('id'), function(){
								$('#calEventsinside').show();
						});

						return false;
					}));
			};


			//Begin image slide code
			
			
				/* This code is executed after the DOM has been completely loaded */
				
				var totWidth=0;
				var positions = new Array();
				var currentPosition=0;
				
				$('#slides .slide').each(function(i){
					
					/* Traverse through all the slides and store their accumulative widths in totWidth */
					
					positions[i]= totWidth;
					totWidth += $(this).width();
					
					/* The positions array contains each slide's commulutative offset from the left part of the container */
					
					if(!$(this).width())
					{
						alert("Please, fill in width & height for all your images!");
						return false;
					}
					
				});
				
				$('#slides').width(totWidth);
			
				/* Change the cotnainer div's width to the exact width of all the slides combined */
				
				$('#next-button').click(function(e,keepScroll) {		
					if (currentPosition < positions.length-1) {			
						var pos = currentPosition+1;
						currentPosition = pos;
						var menuPosition = pos+1;
						
						/* Need max click handling */
						
						$('.menuItem').removeClass('act').addClass('inact');
						$("#menu .menuItem:nth-child("+menuPosition+")").addClass('act');
							
						$('#slides').stop().animate({marginLeft:-positions[pos]+'px'},450);
						/* Start the sliding animation */	
						
						e.preventDefault();
						/* Prevent the default action of the link */
						
						
						// Stopping the auto-advance if an icon has been clicked:
						if(!keepScroll) clearInterval(itvl);			
						
					}else if(currentPosition==positions.length-1){
						var finalPosition = positions.length-1;
						var pos = currentPosition-finalPosition;
						currentPosition = pos;
						var menuPosition = pos+1;
						
						/* Need max click handling */
						
						$('.menuItem').removeClass('act').addClass('inact');
						$("#menu .menuItem:nth-child("+menuPosition+")").addClass('act');
							
						$('#slides').stop().animate({marginLeft:-positions[pos]+'px'},450);
						/* Start the sliding animation */	
						
						e.preventDefault();
						/* Prevent the default action of the link */
						
						
						// Stopping the auto-advance if an icon has been clicked:
						if(!keepScroll) clearInterval(itvl);	
					}
					
				});
				
				$('#prev-button').click(function(e,keepScroll) {		
					if (currentPosition != 0) {			
						var pos = currentPosition-1;
						currentPosition = pos;
						var menuPosition = pos+1;
						
						/* Need min click handling */
						
						$('.menuItem').removeClass('act').addClass('inact');
						$("#menu .menuItem:nth-child("+menuPosition+")").addClass('act');
							
						$('#slides').stop().animate({marginLeft:-positions[pos]+'px'},450);
						/* Start the sliding animation */
						
						e.preventDefault();
						/* Prevent the default action of the link */
						
						
						// Stopping the auto-advance if an icon has been clicked:
						if(!keepScroll) clearInterval(itvl);
						
						
					}else if(currentPosition==0){
						var finalPosition = positions.length-1;
						var pos = finalPosition;
						currentPosition = pos;
						var menuPosition = pos+1;
						
						/* Need max click handling */
						
						$('.menuItem').removeClass('act').addClass('inact');
						$("#menu .menuItem:nth-child("+menuPosition+")").addClass('act');
							
						$('#slides').stop().animate({marginLeft:-positions[pos]+'px'},450);
						/* Start the sliding animation */	
						
						e.preventDefault();
						/* Prevent the default action of the link */
						
						
						// Stopping the auto-advance if an icon has been clicked:
						if(!keepScroll) clearInterval(itvl);	
					}
					
				});
			
				$('#menu .menuItem a').click(function(e,keepScroll){
			
						/* On a thumbnail click */
			
						$('.menuItem').removeClass('act').addClass('inact');
						$(this).parent().addClass('act');
						
						var pos = $(this).parent().prevAll('.menuItem').length;
						currentPosition = pos;
						
						$('#slides').stop().animate({marginLeft:-positions[pos]+'px'},450);
						/* Start the sliding animation */
						
						e.preventDefault();
						/* Prevent the default action of the link */
						
						
						// Stopping the auto-advance if an icon has been clicked:
						if(!keepScroll) clearInterval(itvl);		
						
				});
				
				$('#menu .menuItem:first').addClass('act').siblings().addClass('inact');
				/* On page load, mark the first thumbnail as active */
				
				/*****
				 *
				 *	Enabling auto-advance.
				 *
				 ****/
				 
				var current=1;
				function autoAdvance()
				{
					if(current==-1) return false;
					
					$('#menu .menuItem a').eq(current%$('#menu .menuItem a').length).trigger('click',[true]);	// [true] will be passed as the keepScroll parameter of the click function on line 28
					current++;
				}
			
				// The number of seconds that the slider will auto-advance in:
				
				var changeEvery = 5;
			
				var itvl = setInterval(function(){autoAdvance()},changeEvery*1000);
			
				/* End of customizations */
				
				
				
				/* Get Value */
					var getNum = $(".getNum").val();
				/*
				SPAM FILTER
				*/				
				$(".getNum").change(function() {

					if($(".getNum").val() == 7) {
						$("#submitCommentButton").removeAttr("disabled");
						$("#commentDisplay").html("Correct!");
					}
					else {
						$("#submitCommentButton").attr("disabled","disabed");
						$("#commentDisplay").html("Incorrect! Try again...");
					}

				});
					/* Default display */
					$("#submitCommentButton").attr("disabled","disabled");
					$("#commentDisplay").html("Please enter the answer!");
				
						
				
					

});
