// Frequently used checks in straightforward js
// Feel free to add more functions here.
// Add appropriate comments in the list
// and before the function's body, please.
// Don't forget to remove comments when including in projects.
//
// LIST OF INCLUDED FUNCTIONS
// 
// viewportdims - returns an array containing
// current dimensions [width,heght] of user agent's viewport
//
// bodydim - returns an array containing
// current dimensions [width,heght] of the rendered document
// ATTENTION! - not cleared floats escapes this calculation
//
// pageScrolled - returns an array containing
// current vieport sroll offset [horizontal, vertical]
// of currently rendered document
//
// IEdetect - detects Internet Explorer (returns boolean)
//
// IElt7 - detects Internet Explorer less than version 7 (returns boolean)
// 
// findAbsPos - absolute (relative to viewport) offset of an html block
// takes the block element reference as argument
// retuns an array [horizontal_position,vertical_position]
//

//viewportdims - returns an array containing
//current dimensions [width,heght] of user agent's viewport
function viewportdims(){
	var w = 0;
	var h = 0;
	if (!window.innerWidth) {

		if (!(document.documentElement.clientWidth == 0)) {
			w = document.documentElement.clientWidth;
			h = document.documentElement.clientHeight;
		} else {
			w = document.body.clientWidth;
			h = document.body.clientHeight;
		}
	} else {
		w = window.innerWidth;
		h = window.innerHeight;
	}
	return [w,h];
}

//bodydim - returns an array containing
//current dimensions [width,heght] of the rendered document
//ATTENTION! - not cleared floats escapes this colculation
function bodydim() {
	var width = document.body.offsetWidth;
	var height  = document.body.offsetHeight;
	return [width,height];
}

//pageScrolled - returns an array containing
//current vieport sroll offset [horizontal, vertical]
//of currently rendered document
function pageScrolled() {
	var x,y;
	if (self.pageYOffset) {
		x = self.pageXOffset;
		y = self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop) {
		x = document.documentElement.scrollLeft;
		y = document.documentElement.scrollTop;
	}
	else if (document.body) {
		x = document.body.scrollLeft;
		y = document.body.scrollTop;
	}
	return [x,y];
}

//IEdetect - detects Internet Explorer (returns boolean)
function IEdetect() {
	var brr = navigator.appVersion;
	var isie = new RegExp(/MSIE\s\d/);
	var ie = isie.exec(brr);
	if ( ie != null ) return true;
	else return false;
}

//IElt7 - detects Internet Explorer less than version 7 (returns boolean)
function IElt7() {
	var brr = navigator.appVersion;
	var isie = new RegExp(/MSIE\s\d/);
	var ie = isie.exec(brr);
	if ( ie != null ) {
		ie = ie.toString();
		var vernum = ie.substr(4);
		var ver =  parseInt(vernum);
		if ( ver < 7 ) return true;
		else return false;
	} else return false
}

//findAbsPos - absolute (relative to viewport) offset of an html block
//takes the block element reference as argument
//retuns an array [horizontal_position,vertical_position]
function findAbsPos(obj) {
	var curleft, curtop;
	curleft = 0;
	curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		obj = obj.offsetParent;
		while (obj) {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	return [curleft,curtop];
}