function getDeviceType(){
	scrWidth = screen.width;
	deviceType = (scrWidth < 600)?'mobile':'desktop';
	if(scrWidth >=600 && scrWidth <=800) deviceType = 'tablet';
};
function getViewType(){
	viewWidth = $(window).width();
	viewType = (viewWidth <= 640)?'oneColumn':'twoColumn';
};
function imgReplace(){
	$('.build-image').each(function(){
    var imgSrc = $(this).data('src');
    var imgWidth = $(this).data('width');
	var imgTitle = $(this).data('title');
	var thisImg = $('<img class="thumbnail" title="'+imgTitle+'" src="http://src.sencha.io/x'+imgWidth+'/'+imgSrc+'" width="'+imgWidth+'%" height="auto" alt="'+imgTitle+'" />');
    $(this).replaceWith(thisImg);
	});
};
function mobileNav(){
	$('#header').prepend('<div id="menu-close" class="menu-trigger">&larr; Back</div>');
	$('#header').prepend('<div id="menu-open" class="menu-trigger">Menu &rarr;</div>');
	$('#nav').slideUp();
	$('#menu-open').click(function(){
		$('#nav').slideDown();
		$('#menu-close').fadeIn();
		$('#menu-open').fadeOut();
	});
	$('#menu-close').click(function(){
		$('#menu-close').fadeOut();
		$('#nav').slideUp();
		$('#menu-open').fadeIn();
	});
};
function setUp(){
	getDeviceType();
	getViewType();
	showImg = 0;
	switch(deviceType){
		case 'desktop':
			imgReplace();
			showImg = 1;
		break;
		case 'tablet':
			imgReplace();
			showImg = 1;
		break;
	}
	if(viewType == 'oneColumn') mobileNav();;
	oldViewType = viewType;
};
$(document).ready(function(){
	setUp();
	$(window).resize(function() {
	getViewType();
	if(viewType != oldViewType) {
		switch(viewType){
			case 'twoColumn':
				$('.menu-trigger').remove();
			break;
			case 'oneColumn':
				mobileNav();
			break;
		}
		oldViewType = viewType;
	}
	});
});
