/* Author: 
 denham@bmdbrands.com.au - @denhamhaynes test
*/
$(document).ready(function() {

	var hashw = window.location.hash;
	if(hashw=='' || !hashw){
		//$('#mainNav a').removeClass('active');
	}else{
		scrollToSection(hashw);
	}
	
	if(Modernizr.touch){
		var os = 0;
	}else{
		var os = 132;
	}
	
	
	$('#top').click(function(){
		$('html, body').animate({scrollTop:0}, 'slow');
		return false;
	});
	
	$('#mainNav a.scroll').click(function(){
		var p = $(this).attr('href');
		scrollToSection(p);
		return false;
	})
	
	$('.downArrow').click(function(){
		var s = $(this).parent().parent().parent('section').next('section'),	
				spos = s.offset();
		$('html, body').animate({scrollTop:spos.top-os}, 'slow');
		return false;
	})
	
	$('.sub').colorbox({inline:true, width:'702px'})

	$('#subscribe .button').click(function(){
		$('#subscribe .form').after('<div class="loading">Loading</div>')
	})

	function scrollToSection(hashp){
		var pos = $(hashp).offset();
		$('html, body').animate({scrollTop:pos.top-os}, 'slow');
	}
	
	var path = window.location.pathname;
	
	if (path=='/'){
		$(window).scroll(function(){
			var toppos = $(window).scrollTop();
			if (toppos >= 1050 && toppos <= 2100){
				$('#mainNav a[href=#aboutUs]').addClass('active').siblings('a').removeClass('active');
			}else if (toppos >= 2100 && toppos <= 3340){
				$('#mainNav a[href=#range]').addClass('active').siblings('a').removeClass('active');
			}else if (toppos >= 3340){
				$('#mainNav a[href=#stores]').addClass('active').siblings('a').removeClass('active');
			}else{
				$('#mainNav a').removeClass('active');
			}
		});
	}

});



















