/* prevent execution of Coomsy if included more than once */
if(typeof window.Coomsy == "undefined") {
	var Coomsy = function () {
		var _private = {
			privateVariable: "private variable contents",
			aPrivateFunction: function (){
				return 1;
			}
		};

		var _public = {
			$: function () {
				var elements = [];
				var element;
				for (var i = 0; i < arguments.length; i++) {
					element = arguments[i];
					if (typeof element === 'string'){
						element = document.getElementById(element);
					}
					if(arguments.length == 1){
						return element;
					}
					elements.push(element);
				}
				return elements;
			}
			,
			printEmail: function (user, domain){
				document.write(user+"@"+domain);
			}
			,

			/*
			 * Supply a class name as a string.
			 * (optional) Supply a node. This can be obtained by getElementById, or simply by just throwing in “document” (it will be document if don’t supply a node)). It’s mainly useful if you know your parent and you don’t want to loop through the entire D.O.M.
			 * (optional) Limit your results by adding a tagName. Very useful when you’re toggling checkboxes and etcetera. You could just supply “input“. Or, if you’re like me, and you said Good Bye to IE5, you can use the “*” asterisk as a catch-all (meaning ‘any element).
			 */
			getElementsByClass: function (searchClass, node, tag) {
				var classElements = new Array();
				if(node == null)
					node = document;
				if(tag == null)
					tag = '*';
				var els = node.getElementsByTagName(tag);
				var elsLen = els.length;
				var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
				for (i = 0, j = 0; i < elsLen; i++) {
					if ( pattern.test(els[i].className) ) {
						classElements[j] = els[i];
						j++;
					}
				}
				return classElements;
			}
			,

			accessPrivate : function () {
				return _private.privateVariable;
			}
			,
			toggle: function (obj) {
				var el = document.getElementById(obj);
				if ( el.style.display != 'none' ) {
					el.style.display = 'none';
				}
				else {
					el.style.display = '';
				}
			}
			,
			insertAfter: function (parent, node, referenceNode) {
				parent.insertBefore(node, referenceNode.nextSibling);
			}
			,
			getCookie: function (name) {
				var start = document.cookie.indexOf( name + "=" );
				var len = start + name.length + 1;
				if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
					return null;
				}
				if ( start == -1 ) return null;
				var end = document.cookie.indexOf( ';', len );
				if ( end == -1 ) end = document.cookie.length;
				return unescape( document.cookie.substring( len, end ) );
			}
			,
			setCookie: function (name, value, expires, path, domain, secure) {
				var today = new Date();
				today.setTime( today.getTime() );
				if ( expires ) {
					expires = expires * 1000 * 60 * 60 * 24;
				}
				var expires_date = new Date( today.getTime() + (expires) );
				document.cookie = name+'='+escape( value ) +
					( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString()
					( ( path ) ? ';path=' + path : '' ) +
					( ( domain ) ? ';domain=' + domain : '' ) +
					( ( secure ) ? ';secure' : '' );
			}
			,
			deleteCookie: function (name, path, domain) {
				if ( getCookie( name ) ) document.cookie = name + '=' +
						( ( path ) ? ';path=' + path : '') +
						( ( domain ) ? ';domain=' + domain : '' ) +
						';expires=Thu, 01-Jan-1970 00:00:01 GMT';
			}
			,

			// Returns the absolute position of an object, as an object with "x" and "y" properties.
			// If limitObject is reached, calculation stops there.
			absolutePosition : function(obj, limitObject){
				var retValue = {
					"x": 0,
					"y": 0
				};

				do{
					retValue.x += obj.offsetLeft;
					retValue.y += obj.offsetTop;
				} while( (obj = obj.offsetParent) && (obj != limitObject) );

				return retValue;
			}
			,
			size : function(){
			}
			,
			getWindowHeight : function(){
				if(document.all) return (document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.body.clientHeight;
				else return window.innerHeight;
			}
			,
			getScrollLeft : function(){
				if(document.all) return (document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;
				else return window.pageXOffset;
			}
			,
			getScrollTop : function(){
				if(document.all) return (document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
				else return window.pageYOffset;
			}
			,
			scrollSmoothly : function(objId){
				var obj   = Coomsy.$(objId);
				var coord = core_absoluteCoordinates(obj);
				var dif_height = Math.round(Coomsy.getScrollTop()  - coord[1]);
				obj.style.top  = (coord[1] + dif_height) + "px";

			}
		};

		return _public;
	}();
}