﻿// Declare the namespacesif (Kinsail.Positioning == null || typeof(Kinsail.Positioning) != "object") {Kinsail.Positioning = new Object();}// JavaScript element positioning functionsKinsail.Positioning = {    // passing in a null offset does not modify the position in that axis     // [ie if you only want to change the x location of an item pass in null for the y]    setPositions: function (AnchorObjectName, SetObjectName, OffsetX, OffsetY, ScrolledParentObjectName) {        // handle bad offsets being passed in        if (OffsetX != null && isNaN(OffsetX)) {            OffsetX = 0;        }        if (OffsetY != null && isNaN(OffsetY)) {            OffsetY = 0;        }        // adjust for an element within a scrolled div/etc        if (ScrolledParentObjectName != null) {            ScrolledObject = eval(strGetItemPrefix + ScrolledParentObjectName + strGetItemSuffix)            OffsetX -= ScrolledObject.scrollLeft;            OffsetY -= ScrolledObject.scrollTop;        }		// get the anchor object        if (typeof(AnchorObjectName) == 'string'){	        objAnchor = eval(strGetItemPrefix + AnchorObjectName + strGetItemSuffix);	    } else if (typeof(AnchorObjectName) == 'object'){	    	objAnchor = AnchorObjectName;	    }	    	        if (objAnchor == null)        	return;        // create the array that will contain the X & Y positions for the anchor element        aryAnchorLocation = new Array();        // populate the array with the anchor's X & Y positions        aryAnchorLocation = Kinsail.Positioning.findPos(objAnchor);        // reset the SetObject's positions using these values with the offsets        if ( OffsetX != null ) {            // Reset X position            eval(strGetItemPrefix + SetObjectName + strGetItemSuffix + strStyle + '.left = "' + parseInt(parseInt(aryAnchorLocation[0]) + parseInt(OffsetX)) + 'px"');        }        if ( OffsetY != null ) {            // Reset Y position            eval(strGetItemPrefix + SetObjectName + strGetItemSuffix + strStyle + '.top = "' + parseInt(parseInt(aryAnchorLocation[1]) + parseInt(OffsetY)) + 'px"');        }    },        SetX: function(ObjectName, XValue) {        eval(strGetItemPrefix + ObjectName + strGetItemSuffix + strStyle + '.left = "' + parseInt(XValue) + 'px"');    },    SetY: function(ObjectName, YValue) {        eval(strGetItemPrefix + ObjectName + strGetItemSuffix + strStyle + '.top = "' + parseInt(YValue) + 'px"');    },    // http://www.quirksmode.org/js/findpos.html    // modified by Kinsail    findPos: function (ObjectName) {        //obj = eval(strGetItemPrefix + ObjectName + strGetItemSuffix);        if (typeof(ObjectName) == 'string'){	        obj = eval(strGetItemPrefix + ObjectName + strGetItemSuffix);	    } else if (typeof(ObjectName) == 'object'){	    	obj = ObjectName;	    }    	if (obj == null) return;        var curleft = curtop = 0;        if (obj.offsetParent) {            curleft = obj.offsetLeft            curtop = obj.offsetTop            while (obj = obj.offsetParent) {                curleft += obj.offsetLeft                curtop += obj.offsetTop            }        }        return [curleft,curtop];    },        // center an object in the middle of the window	centerInWindow: function (divID) {		// get the div object		objDiv = eval(strGetItemPrefix + divID + strGetItemSuffix);		if (objDiv == null) return;				// get the inner dimensions of the browser		var width,height;		if (self.innerHeight) // all except Explorer		{			width = self.innerWidth;			height = self.innerHeight;		}		else if (document.documentElement && document.documentElement.clientHeight)			// Explorer 6 Strict Mode		{			width = document.documentElement.clientWidth;			height = document.documentElement.clientHeight;		}		else if (document.body) // other Explorers		{			width = document.body.clientWidth;			height = document.body.clientHeight;		}				//get how much the page has scrolled		var x,y;		if (self.pageYOffset) // all except Explorer		{			x = self.pageXOffset;			y = self.pageYOffset;		}		else if (document.documentElement && document.documentElement.scrollTop)			// Explorer 6 Strict		{			x = document.documentElement.scrollLeft;			y = document.documentElement.scrollTop;		}		else if (document.body) // all other Explorers		{			x = document.body.scrollLeft;			y = document.body.scrollTop;		}				strWidth = eval('objDiv' + strStyle + '.width')		intWidth = parseInt(strWidth.substring(0, strWidth.length-2));		eval(strGetItemPrefix + divID + strGetItemSuffix + strStyle + '.left = "' + parseInt(parseInt(parseInt(width)/2) + parseInt(x) - parseInt(intWidth/2)) + 'px"');		eval(strGetItemPrefix + divID + strGetItemSuffix + strStyle + '.top = "' + parseInt(parseInt(parseInt(height)/3) + parseInt(y)) + 'px"');	},		//figure out the width of the window	getWindowWidth: function () {		var theWidth = 0;				if (window.innerWidth) {theWidth = window.innerWidth;}		else if (document.documentElement && document.documentElement.clientWidth) {theWidth = document.documentElement.clientWidth;}		else if (document.body) {theWidth = document.body.clientWidth;}				return theWidth;	},		//figure out the width of the window	getWindowHeight: function () {		var theHeight = 0;				if (window.innerHeight) {theHeight = window.innerHeight;}		else if (document.documentElement && document.documentElement.clientHeight) {theHeight = document.documentElement.clientHeight;}		else if (document.body) {theHeight = document.body.clientHeight;}				return theHeight;	},		getWindowScrollX: function () {	    var scrollX = 0;	            if(window.innerWidth) {
            scrollX = window.pageXOffset;
        }
        if(document.documentElement && document.documentElement.clientWidth) {
            scrollX = document.documentElement.scrollLeft;
        }
        if(document.body.clientWidth) {
            scrollX = document.body.scrollLeft;
        }                return scrollX;	},		getWindowScrollY: function () {	    var scrollY = 0;	            if(window.innerWidth) {
            scrollY = window.pageYOffset;
        }
        if(document.documentElement && document.documentElement.clientWidth) {
            scrollY = document.documentElement.scrollTop;
        }
        if(document.body.clientWidth) {
            scrollY = document.body.scrollTop;
        }                return scrollY;	}}; //end Kinsail.Positioning