$(function(){ $(document).ready(function() {

	/* Clients
	-------------------------------------------------------*/

	$('.scrollTo a').click(function() {
	
		theId = $(this).attr('href');		
		$('.client-wrap').stop().scrollTo(theId, 1000);
	
	});
	
	$('.clients .col3').hover(function() {
		$(this).find('h4').last().stop().animate({'marginTop' : '-35px'});
	}, function() {
		$(this).find('h4').last().stop().animate({'marginTop' : '-10px'});
	});
	
	Shadowbox.init();

	
	/* Featured
	-------------------------------------------------------*/
	
	$('#topimg .slideshow').cycle({
		prev:	"#topimg .prev",
		next:	"#topimg .next"
	});
	
	$('#topimg').hover(function() {	
		$('#topimg .slidenav').fadeIn();	
	}, function() {		
		$('#topimg .slidenav').fadeOut();		
	});
	
	
	/* Calculator
	-------------------------------------------------------*/
	
	$('.category-products .expand').each(function() {
		$(this).slideUp(0);
	});
	
	$('.category-products h2 a').click(function() {
	
		var cat = '.category-products .' + $(this).attr('href').replace('#', '');
		var catPos = $(cat).position();
		
		
		if ($(cat).hasClass('expanded')) {
			$(cat).stop().slideUp().removeClass('expanded');
		} else {
			$(cat).stop().slideDown().addClass('expanded');			
		}		
	
	});
	
	
	/* Calculator
	-------------------------------------------------------*/
	
	$('.output li').fadeOut(0);
	$('.sqfeet').jStepper({minValue:0, decimalSeparator:"."});
	
	$('.thickness input#sqcalc').click(function() {
		
		var sqft = $('.sqfeet').val(),
			k = $('input#sqcalc').attr('class') / 100,
			thickness = 1;

		if (sqft != '') {

			for (i=0; i<9; i++) { 
				thickness = $('.output li').eq(i+1).attr("id") / 10000;
				$('.output li').eq(i+1).html(Math.ceil((sqft / k*thickness)));
			}
			
			var x = 0;
			$('.output li').each(function(){
				$(this).delay(x * 500).fadeIn('fast');
				x++;
			});	
		
		}
	});

	$('.misc input#sqcalc').click(function() {
	
		var sqft = $('.sqfeet').val(),
			thickness = 1;
			
		if (sqft != '') {
			
			for (i=0; i<9; i++) {
				thickness = $('.output li').eq(i+1).attr('id') / 10000;

				
				if ($('.output li').eq(i+1).hasClass('sand')) {
					$('.output li').eq(i+1).html(Math.floor((sqft / thickness)+0.5) + " - 100 lb bags of sand required.");
				} else {
					$('.output li').eq(i+1).html(Math.ceil(sqft / thickness));
				}
				
			}
			
			var x = 0;
			$('.output li').each(function() {
				$(this).delay(x * 500).fadeIn('fast');
				x++;
			});	
		}	
	});
	
	/* Misc
	-------------------------------------------------------*/
	
	if ($('.rborder').length) {
	
		var rHeight = 0;
		
		$('.rborder').each(function() {
			rHeight += $(this).height();
			log(rHeight)
		});
		
		
		if (rHeight < $('.sidebar').height()) {
			$('.rborder').css({ 'min-height' : $('.sidebar').height() });
		}
	
	}
	
	/* Loading
	-------------------------------------------------------*/
	
	$(window).load(function() {
		$('.clients .client-loading').fadeOut();		
	});
	
}); });
