/* Author: Skyhook Internet Marketing
 * Site: Kroc Center
 */
jQuery(document).ready(function($){
	
	/* Countdown */
	var newYear = new Date(),
			newYear = new Date(newYear.getFullYear() + 1, 1 - 1, 1); 

	$('#countdown').countdown({ 				 
		until: new Date(2012, 5 - 1, 18), timezone: +6,
		layout: '<span class="counter-title">Our doors open in:</span> ' +
						'<span class="days">{d<}{dn}</span> {dl}, {d>}' + 
    				'<span class="hours">{hn}</span> {hl}, ' +
    				'<span class="minutes">{mn}</span> min, <span class="amp">&amp;</span> ' +
    				'<span class="seconds">{sn}</span> sec'
	}); 

	/* Slideshow */
	$('#slideshow').cycle({
	  // fx:      'scrollRight',
	  fx:      'fade',
	  speed: 	 'slow',
	  timeout:  8000,
	  //easing:  'easeInOutBack',
	  prev:    '#prev',
	  next:    '#next'
	});

	/* Colorbox */
	$(".colorbox").colorbox({width:"640px", height:"480px", iframe:true});


	var nav 				= $('#nav li.nav-item a'),
			navDefault	= $('#nav li.about a'),
			homeNav 		= $('#logo a');

	$.address.init(function() {

		// Initializes the plugin
		nav.address();
		homeNav.address();
             
	}).change(function(event) {

		homeNav.each( function() {
			
			var link  						= this,
					homeCurrentLink 			= '/' + $(link).attr('href').replace(/^#/, ''),
					homeCurrentLinkHash 	= '#' + $(link).attr('href').replace(/^#/, '');
			
			if ( homeCurrentLink == $.address.value() ) {
				$.smoothScroll({
					offset: 0,
					direction: 'top',
		      scrollTarget: homeCurrentLinkHash,
		      afterScroll: function(){
		      	$.address.title('Home | Ray and Joan Kroc Community Center | Phoenix South Mountain');
		      	nav.parent().removeClass('active');
		      	navDefault.parent().addClass('active');
		      },
		      speed: 400
	    	});
			}
		});

		// Do each Nav Links
		nav.each( function() {
			
			var link  						= this,
					currentLink 			= '/' + $(link).attr('href').replace(/^#/, ''),
					currentLinkHash 	= '#' + $(link).attr('href').replace(/^#/, '');
			
			if ( currentLink == $.address.value() ) {
				
				if ( currentLinkHash === '#about' ){

		    	$.smoothScroll({
			    	offset: -50,
			    	direction: 'top',
			      scrollTarget: currentLinkHash,
			      afterScroll: function(){
			      	$.address.title($(link).text() + ' | Ray and Joan Kroc Community Center | Phoenix South Mountain');
			      	nav.parent().removeClass('active');
			      	$(link).parent().addClass('active');
			      },
			      speed: 400
		    	});

    		} else {
	    		
	    		$.smoothScroll({
			    	offset: -20,
			    	direction: 'top',
			      scrollTarget: currentLinkHash,
			      afterScroll: function(){
			      	$.address.title($(link).text() + ' | Ray and Joan Kroc Community Center | Phoenix South Mountain' );
			      	nav.parent().removeClass('active');
							$(link).parent().addClass('active');
			      },
			      speed: 400
		    	});

		    }

		  }

		});

	});

	$(window).scroll(updateHeight).trigger("scroll");

});

function updateHeight() {
			
	var	mainContent				= $('#main'),
			offset						= mainContent.offset(),
			scrollTop					= $(window).scrollTop(),
			homeLoc  					= 0,
			ourMissionLoc 		= 1132,
			ourProgramsLoc 		= 1806,
			getInvolvedLoc		= 2588,
			temporaryHomeLoc 	= 3095;
	
	// console.log(scrollTop);
	
	// Home and About
	if ( scrollTop >= 0 && scrollTop < 1037 ){
		// $.address.value( 'home' );
		$('#nav li').removeClass('active');
		$('#nav li.about').addClass('active');
	} 

	// Our Mission
	if ( scrollTop >= 1037 && scrollTop < 1696 ) {
		// $.address.value( 'our-mission' );
		$('#nav li').removeClass('active');
		$('#nav li.our-mission').addClass('active');
	} 

	// Our programs
	if ( scrollTop >= 1696 && scrollTop < 2490 ) {
		// $.address.value( 'our-programs' );
		$('#nav li').removeClass('active');
		$('#nav li.our-programs').addClass('active');
	}

	// Get Involved
	if ( scrollTop >= 2490 && scrollTop < 2975 ) {
		// $.address.value( 'get-involved' );
		$('#nav li').removeClass('active');
		$('#nav li.get-involved').addClass('active');
	}
	
	// Temporary Location
	if ( scrollTop >= 2975 ) {
		// $.address.value( 'temporary-location' );
		$('#nav li').removeClass('active');
		$('#nav li.temp-loc').addClass('active');	
	}

}






















