
var viewModel = {
    name: "Brian Cary",
    email: "brian@briancary.com"
		/*nav: new navigation(pages),*/
    
};

function ensureTemplates(list) {

    var loadedTemplates = [];

    ko.utils.arrayForEach(list, function(name) {

        $.get(name + ".html", function(template) {

            $("body").append("<script id=\"" + name + "\" type=\"text/html\">" + template + "<\/script>");

            loadedTemplates.push(name);

            if (list.length === loadedTemplates.length) {
                ko.applyBindings(viewModel);
                /**
                * Log user client capabilities
                */
                //logFeatures();

            }
        });
    });
}



/**
 * Load in default templates
 */
$(document).ready(function() {
	
	// BG
	
	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");
	


  ensureTemplates(["templates/footer"]);
  

    //ko.applyBindings(viewModel);

});

$(document).ready(function() {
	
	// Grid BG
	$("body").gridBuilder({
		color: '#f9f9f9', // color of the primary gridlines
		secondaryColor: '#f9f9f9', // color of the secondary gridlines
		vertical: 30, // height of the vertical rhythm
		horizontal: 30, // width of horizontal strokes
		gutter: 50, // width of the gutter between strokes
	});
	
	// Additional initializations
	
	$('#topbar').scrollSpy();
	$('.btn').button();

	
	$('#link_skills').popover({
		animate: true,
	});
	$('#link_posse').popover({
		animate: true,
	});
	$('#link_message').popover({
		animate: true,
	});
	
	$('#s_1').popover({
		animate: true,
	});
	
	$('.circle').bind("mouseenter mouseleave", function(event){
		$(this).toggleClass("circle_hover");
	});

	
});

function open_skills() {
	
	$('#modal_skills').modal('show');
	
	$("html,body").animate({scrollTop: $("#modal_skills").offset().top - 100}, 1000);
	
}
function close_skills() {
	
	$("html,body").animate({scrollTop: $("body").offset().top - 100}, 1000);
	$('#modal_skills').modal('close');
}

function open_portfolio() {

	$('#modal_portfolio').modal('show');
	$("html,body").animate({scrollTop: $("#modal_portfolio").offset().top - 100}, 1000);
	
}
function close_portfolio() {

	$("html,body").animate({scrollTop: $("body").offset().top - 100}, 1000);
	$('#modal_portfolio').modal('close');
}

function open_posse() {

	$('#modal_posse').modal('show');
}
function close_posse() {

	$("html,body").animate({scrollTop: $("body").offset().top - 100}, 1000);
	$('#modal_posse').modal('close');
}

function open_message() {
	$('#modal_message').modal('show');
	
	$("html,body").animate({scrollTop: $("#modal_message").offset().top - 100}, 1000);
	
}
function close_message() {
	

	$("html,body").animate({scrollTop: $("body").offset().top - 100}, 1000);
	$('#modal_message').modal('close');
	
}
