var JsWindow =
{	
	addFrag : function(str)
	{
		var frag = document.createDocumentFragment();
		frag.appendChild(document.createTextNode(str));
		document.body.appendChild(frag);	
	},
	
	addStr : function(str)
	{
		if( document.layers && window.Layer && document.classes ) {
			//create a layer 350px wide
			document.layers['newName'] = new Layer( 350 );
			//write its content
			document.layers['newName'].document.open();
			document.layers['newName'].document.write(str);
			document.layers['newName'].document.close();
			//style it
			document.layers['newName'].left = 0;
			document.layers['newName'].top = 0;
			document.layers['newName'].visibility = 'show';
		} else if( document.body ) {
			var theString = '<div style="position:absolute;left:0px;top:0px;' +
				'width:350px;">'+str+'</div>';
			if( document.body.insertAdjacentHTML ) {
				document.body.insertAdjacentHTML( 'beforeEnd', theString );
			} else if( typeof( document.body.innerHTML ) != 'undefined' ) {
				document.body.innerHTML += theString;
			} else {
				//FAILURE, nothing works
			}
		} else {
		  //FAILURE, nothing works
		}
	},
	
	bgColor : function(color)
	{
		if( document.documentElement && document.documentElement.style ) 
		{
			document.documentElement.style.backgroundColor = color; 
		}
		if( document.body && document.body.style ) 
		{
			document.body.style.backgroundColor = color; 
		}
		document.bgColor = color;	
	},
	
	alertSize : function() {
	  var myWidth = 0, myHeight = 0;
	  if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	  }
	
	  return [myWidth, myHeight];
	},
	
	getScrollXY : function() {
	  var scrOfX = 0, scrOfY = 0;
	  if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	  }
	  return [ scrOfX, scrOfY ];
	},
	
	getAllSheets : function() {
	  //if you want ICEbrowser's limited support, do it this way
	  if( !window.ScriptEngine && navigator.__ice_version ) {
		//IE errors if it sees navigator.__ice_version when a window is closing
		//window.ScriptEngine hides it from that
		return document.styleSheets; }
	  if( document.getElementsByTagName ) {
		//DOM browsers - get link and style tags
		var Lt = document.getElementsByTagName('link');
		var St = document.getElementsByTagName('style');
	  } else if( document.styleSheets && document.all ) {
		//not all browsers that supply document.all supply document.all.tags
		//but those that do and can switch stylesheets will also provide
		//document.styleSheets (checking for document.all.tags produces errors
		//in IE [WHY?!], even though it does actually support it)
		var Lt = document.all.tags('LINK'), St = document.all.tags('STYLE');
	  } else { return []; } //lesser browser - return a blank array
	  //for all link tags ...
	  for( var x = 0, os = []; Lt[x]; x++ ) {
		//check for the rel attribute to see if it contains 'style'
		if( Lt[x].rel ) { var rel = Lt[x].rel;
		} else if( Lt[x].getAttribute ) { var rel = Lt[x].getAttribute('rel');
		} else { var rel = ''; }
		if( typeof( rel ) == 'string' && rel.toLowerCase().indexOf('style') + 1 ) {
		  //fill os with linked stylesheets
		  os[os.length] = Lt[x];
		}
	  }
	  //include all style tags too and return the array
	  for( var x = 0; St[x]; x++ ) { os[os.length] = St[x]; } return os;
	},

	changeStyle : function() {
	  for( var x = 0, ss = getAllSheets(); ss[x]; x++ ) {
		//for each stylesheet ...
		if( ss[x].title ) {
		  //disable the stylesheet if it is switchable
		  ss[x].disabled = true;
		}
		for( var y = 0; y < arguments.length; y++ ) {
		  //check each title ...
		  if( ss[x].title == arguments[y] ) {
			//and re-enable the stylesheet if it has a chosen title
			ss[x].disabled = false;
		  }
		}
	  }
	  if( !ss.length ) { alert( 'Your browser cannot change stylesheets' ); }
	}	
	
};

