﻿if (!window.BIG) {
	throw "BIG.Window.js: BIG.js does not appear to have been loaded"
}

BIG.Window = {};

BIG.Window.Size = function () {};
BIG.Window.Size.prototype = {
	Width: 0,
	Height: 0
}

BIG.Window.GetWindowSize = function () {
	var size = new BIG.Window.Size();
	
	if (typeof(self.innerWidth) == "number")
	{
		size.Width = self.innerWidth;
		size.Height = self.innerHeight;
	}	
	else if (document.documentElement && document.documentElement.clientWidth)
	{
		size.Width = document.documentElement.clientWidth;
		size.Height = document.documentElement.clientHeight;
	}
	else if (document.body)
	{
		size.Width = document.body.clientWidth;
		size.Height = document.body.clientHeight;
	}
	else return null;
	
	size.Width = parseInt(size.Width);
	size.Height = parseInt(size.Height);
	
	return size;
}

BIG.Window.PositionElement = function (elem, x, y, horizontalAlignment, verticalAlignment) {
	var size = BIG.Window.GetWindowSize();	
	
	if (horizontalAlignment != BIG.Alignment.Fixed) {
		var left = null;
		
		if (horizontalAlignment ==  BIG.Alignment.Left) {
			left = 0;
		} else
		
		if (horizontalAlignment ==  BIG.Alignment.Right) {
			left = (size.Width - parseInt(elem.style.width));
		} else
		
		if (horizontalAlignment ==  BIG.Alignment.Center) {
			left = Math.floor((size.Width / 2) - (parseInt(elem.clientWidth) / 2));
		}
		
		left = left !== null ? left + x : x;
		elem.style.left = left + "px";
	}	
	
	if (verticalAlignment != BIG.Alignment.Fixed) {	
		var top = null;
		
		if (verticalAlignment ==  BIG.Alignment.Top) {
			top = 0;
		} else
		
		if (verticalAlignment ==  BIG.Alignment.Bottom) {
			top = (size.Height - parseInt(elem.style.height));
		} else
		
		if (verticalAlignment ==  BIG.Alignment.Center) {
			top = Math.floor((size.Height / 2) - (parseInt(elem.clientHeight) / 2));
		}
		
		top = top !== null ? top + y : y;
		elem.style.top = top + "px";
	}		
}