$(document).ready(function() {
	var viewportheight = window.innerHeight ? window.innerHeight : $(window).height();
	var viewportwidth = window.innerWidth ? window.innerWidth : $(window).width();

	if(viewportheight > viewportwidth)
		$('#bckgr .image').css('height', '100%');
	else
		$('#bckgr .image').css('width', '100%');
});

$(window).load(function() {
	scaleBckgr();
	scaleNavBar();
});

var isMobile = false;
if (window.navigator && navigator.userAgent ) {
    isMobile = !!navigator.userAgent.match(/Mobile\//)
}
if (isMobile && jQuery.browser.safari) {
	//nothing to render
} else {
	$(window).resize(function() {
		scaleBckgr();
		scaleNavBar();
	});
}

function scaleNavBar() {
	var viewportheight = window.innerHeight ? window.innerHeight : $(window).height();
	$('#navigation').each(function() {
		$('#navigation').css('height', viewportheight);
	});
}

function scaleBckgr() {
	var imageheight;
	var imagewidth;
	
	if(viewportheight > viewportwidth)
		$('#bckgr .image').css('height', '100%');
	else
		$('#bckgr .image').css('width', '100%');
	
	$('#bckgr .image').each(function(){
			imageheight = $(this).height();
			imagewidth = $(this).width();
	});
		
	var viewportheight = window.innerHeight ? window.innerHeight : $(window).height();
	var viewportwidth = window.innerWidth ? window.innerWidth : $(window).width();

	if(viewportheight > viewportwidth) {

		$('#bckgr .image').css('height', viewportheight);
		if(imagewidth < viewportwidth) {
		$('#bckgr .image').css('width', viewportwidth);
		$('#bckgr .image').css('height', (viewportwidth/imagewidth)*imageheight);
		}else {
		$('#bckgr .image').css('width', '');
		}

		}else {

		$('#bckgr .image').css('width', viewportwidth);
		if(imageheight < viewportheight) {
		$('#bckgr .image').css('height', viewportheight);
		$('#bckgr .image').css('width', (viewportheight/imageheight)*imagewidth);
		}else {
		$('#bckgr .image').css('height', '');
		}
	
	}
}
