jQuery.noConflict(); 
 jQuery(document).ready(function($) { 


// wounded warrior counter --------------------------------- //

function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

// if we are on the homepage
if ($('#wounded_count').length) {
	// get seconds since event for baseline donation figure
	var startDate = new Date("01/22/2012");
	var today = new Date();
	var secs_divide=1000;
	// donation amount
	
	var startDonationAmt = 305000;
	// amount raise per day (roughly)
	var amtPerDay = 2880;
	
	// amount per second
	var amtPerSec = amtPerDay / 86400;
	
	//Get difference in time by seconds
	var curSecs = Math.ceil((today.getTime()-startDate.getTime())/(secs_divide));
	
	
	var dollar = 1;
	function updateWWP() {
	    dollar++;
	    $('#wounded_count').html('$'+addCommas(startDonationAmt + (Math.ceil(curSecs*amtPerSec))+dollar) );
	
	}	
	
	// SHOW THE AMOUNT RAISED AND START THE TIMER

	$('#wounded_count').html('$'+addCommas(startDonationAmt + (Math.ceil(curSecs*amtPerSec))));
	setInterval(updateWWP,30000);
}


// END wounded warrior counter --------------------------------- //


// menu flyouts --------------------------------- //

$('#menu_main').find('li').hover(function() {
    $(this).children('ul.sub-menu').css('display','block');
});

$('#menu_main').find('li').mouseleave(function() {
    $(this).children('ul.sub-menu').css('display','none');
});

// social icon tooltips
$('#social-icons-cont a').each(function(){
	
	$(this).hover(function(){
		console.log( $(this) );
		$(this).children('span.icon_tip').css('display','block');
	});
	$(this).mouseleave(function(){
		$(this).children('span.icon_tip').css('display','none');
	});
});


// END menu flyouts --------------------------------- //



// rotator --------------------------------- //

if ($('.carousel_cont').length ) {

	var isSliding=false;
	var slideWidth;
	var contWidth;
	function slideItLeft(){
	    if(!isSliding){
		$('.carousel_cont .slides').animate({'margin-left':'-='+slideWidth,},500,function(){$('.carousel_cont .slides .slide:first').appendTo($('.carousel_cont .slides'));$('.carousel_cont .slides').css('margin-left',0);isSliding=false;
		});
	    }
	    isSliding=true;
	}
	function slideItRight(){
	    if(!isSliding){
		$('.carousel_cont .slides .slide:last').prependTo($('.carousel_cont .slides'));
		$('.carousel_cont .slides').css('margin-left','-'+slideWidth);
		$('.carousel_cont .slides').animate({'margin-left':'+='+slideWidth,},500,function(){$('.carousel_cont .slides').css('margin-left',0);
		isSliding=false;
		});
	    }
	    isSliding=true;
	}
	
	slideWidth=$('.carousel_cont .slides').first().css('width');
	contWidth=Number($('.carousel_cont .slide').length)*slideWidth.replace('px','');
	$('.carousel_cont .slides').css('width',contWidth+'px');
	var num_slides=$('.carousel_cont .slides .slide').length;
	if(num_slides>1) {
	    var slideAuto=setInterval(slideItLeft,6000);
	    $('.arrow_rt').click(function(){clearInterval(slideAuto);slideItLeft();});
	    $('.arrow_lt').click(function(){clearInterval(slideAuto);slideItRight();});
	    $('.arrow_lt,.arrow_rt').show(0);
	    
	}
	else {
	    $('.arrow_lt,.arrow_rt').hide(0);
	}

}	
	
// END rotator --------------------------------- //


// subpage indication --------------------------------- //

if ( $('.sidebar ul').length>=1) {
	$('.sidebar ul a').each(function(){
		
		// console.log ( $(this) );
		// console.log ( $(this).attr('href') == window.location.pathname);

		if ( $(this).attr('href') == window.location.pathname ) {
			$(this).addClass('active_page');
		}
	});	
}



// END subpage indication --------------------------------- //


// end domready
});
