// --------------------------------------
// -- Â© Mono Graphcs AW -----------------
// -- www.monographics.fi----------------
// --------------------------------------

// Modified by JR 1.3.2010

// ---------------------------
// -- IE 6 or later detection 
// ---------------------------
var browserModel = jQuery.browser.msie;
var browserVersion = parseInt(jQuery.browser.version.substr(0,1));

function ie6lteCheck() {
	return(browserModel == true && browserVersion < 7);
}
var ie6lte = ie6lteCheck(); // true or false

// -- Document Ready --
$(document).ready(function() {		
	// Skip IE6
	if (!ie6lte) {
		resizeBgImg();
	}	
});
// -- Window onResize --
$(window).resize(function() {
	// Skip IE6
	if (!ie6lte) {
		resizeBgImg();
	}
});


// ---------------------------
// -- Fullscreen background --
// ---------------------------

// STATIC MAIN VARIABLES

var imgRealWidth = 1300; 
var imgRealHeight = 908;

function resizeBgImg() {
	
	// Final variables
	var newWidth;
	var newHeight;
	var newTop;
	var newLeft;
				
	// Gather browser and current image size
	var imgWidth = imgRealWidth;
	var imgHeight = imgRealHeight;
	var winWidth = getWindowWidth();
	var winHeight = getWindowHeight() - 90;
	
	// Define window aspect ratio
	var winRatio = winWidth / winHeight;
	
	// Define image aspect ratio
	var imgRatio = imgWidth / imgHeight;
	
	// Resize image to proper ratio
	if (winRatio > imgRatio) {
		// scale pic to fit window width
		var newHeight = Math.round((winWidth / imgWidth) * imgHeight);
		var newWidth = winWidth;
	} else {
		// scale pic to fit window height		
		var newHeight = winHeight;
		var newWidth = Math.round((winHeight / imgHeight) * imgWidth);
	}
		
	// Center image
	newTop = Math.round(0 - ((newHeight - winHeight) / 2)) +45;
	newLeft =  Math.round(0 - ((newWidth - winWidth) / 2));
	
	// Apply styles
	$("#supersize").css({ height: newHeight, width: newWidth});
	$("#supersize img").css({ height: newHeight, width: newWidth, top: newTop, left: newLeft});
	
}

// Dependable function to get Window Height
function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
};

// Dependable function to get Window Width
function getWindowWidth() {
	var windowWidth = 0;
	if (typeof(window.innerWidth) == 'number') {
		windowWidth = window.innerWidth;
	}
	else {
		if (document.documentElement && document.documentElement.clientWidth) {
			windowWidth = document.documentElement.clientWidth;
		}
		else {
			if (document.body && document.body.clientWidth) {
				windowWidth = document.body.clientWidth;
			}
		}
	}
	return windowWidth;
};
