﻿// JScript File

function $(id){
    return document.getElementById(id)
}

var Win = {
    "Width" : function(){
	    return this.FilterResults (
		    window.innerWidth ? window.innerWidth : 0,
		    document.documentElement ? document.documentElement.clientWidth : 0,
		    document.body ? document.body.clientWidth : 0
        );
    },
    "Height" : function(){
	    return this.FilterResults (
		    window.innerHeight ? window.innerHeight : 0,
		    document.documentElement ? document.documentElement.clientHeight : 0,
		    document.body ? document.body.clientHeight : 0
	    );
	},
    "ScrollLeft" : function(){
	    return this.FilterResults (
		    window.pageXOffset ? window.pageXOffset : 0,
		    document.documentElement ? document.documentElement.scrollLeft : 0,
		    document.body ? document.body.scrollLeft : 0
	    );
	},
	"ScrollTop" : function(){
	    return this.FilterResults (
		    window.pageYOffset ? window.pageYOffset : 0,
		    document.documentElement ? document.documentElement.scrollTop : 0,
		    document.body ? document.body.scrollTop : 0
	    ); 
	},
	
	"FilterResults" : function(n_win, n_docel, n_body) {
	        var n_result = n_win ? n_win : 0;
	        if (n_docel && (!n_result || (n_result > n_docel)))
		        n_result = n_docel;
	        return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
    }	
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return {"x" : curleft,"y" : curtop};
}

function getFlowTop(elementIDs){
    var els = elementIDs.split(",")
    var totalHeight = 0 //page top margin
    for (x = 0; x<els.length; x++){
        if (document.getElementById(els[x])){
            totalHeight += document.getElementById(els[x]).offsetHeight
        }else{
            alert(els[x] + " element not found.")
        }
    }
    return totalHeight
}