$(document).ready(function(){

  $(function() {   

		var theWindow        = $(window),
		    $bg              = $("#bg"),
		    aspectRatio      = $bg.width() / $bg.height();

		function resizeBg() {

			if ( (theWindow.width() / theWindow.height()) < aspectRatio ) {
			    $bg
			    	.removeClass()
			    	.addClass('bgheight');
			} else {
			    $bg
			    	.removeClass()
			    	.addClass('bgwidth');
			}

		}

		theWindow.resize(function() {
			resizeBg();
		}).trigger("resize");

	});
	
$('ul.sf-menu').superfish();


	$.waypoints.settings.scrollThrottle = 30;
	$('body').waypoint(function(event, direction) {
	}, {
	}).find('#content-wrapper').waypoint(function(event, direction) {
		$('body').toggleClass('sticky', direction === "down");
		event.stopPropagation();
	});
	
	
	if($("aside article").length > 0) {
	$('aside article:last-child').addClass('last');
}

  if($("#archives").length > 0) {
  $("#archives").niceScroll({cursorcolor:"#666",cursoropacitymax:1,cursoropacitymin:.25});  
}


//email spam protection - Example Markup: <span class="email">name[at]domain[dot]com</span>
$('.email').each(function() {
	var $email = $(this);
	var address = $email.text()
	.replace(/\s*\[at\]\s*/, '@')
	.replace(/\s*\[dot\]\s*/g, '.');
	$email.html('<a href="mailto:' + address + '">'+ address +'</a>');
});


// Loads real estate first
/*
if($('#filterOptions').length > 0) {
  
  $("#filterOptions li").removeClass('active');
	$("#filterOptions a.real-estate").parent().addClass('active');
	
  // get and assign the ourHolder element to the
	// $holder varible for use later
  var $holder = $('ul.ourHolder');

  // clone all items within the pre-assigned $holder element
  var $data = $holder.clone();
	var $filteredData = $data.find('li[data-type=real-estate]');
	$holder.quicksand($filteredData, {
		duration: 800,
		easing: 'easeInOutQuad'
	});
	return false;
	
}*/

// Add print header to top of page
 	$("body").prepend("<h5 class=\"print\">Vovia Online Marketing</h5>");

 	// Add print footer to bottom of page
 	$("body").after("<h6 class=\"print\"><strong>Vovia Online Marketing</strong><br />1815 - 10th Avenue SW<br />Calgary, Alberta, T3C 0K2</h5>");

});
