//
//	netforge javascript api
//
function netforge_class() {
	var mouse_coord_x = 0;
	var mouse_coord_y = 0;
	
	// Browser checks
	navigator.isOpera = window.opera && opera.buildNumber;
	navigator.isWebKit = /WebKit/.test(navigator.userAgent);
	navigator.isIE = !this.isWebKit && !this.isOpera && (/MSIE/gi).test(navigator.userAgent) && (/Explorer/gi).test(navigator.appName);
	navigator.isIE6 = this.isIE && /MSIE [56]/.test(navigator.userAgent);
	navigator.isGecko = !this.isWebKit && /Gecko/.test(navigator.userAgent);
	navigator.isMac = navigator.userAgent.indexOf('Mac') != -1;
	navigator.isAir = /adobeair/i.test(navigator.userAgent);
	
	this.internalMouseCoord = function(e) {
		if (!e) var e = window.event;
		if (e.pageX || e.pageY) {
			mouse_coord_x = e.pageX;
			mouse_coord_y = e.pageY;
		} else if (e.clientX || e.clientY) {
			mouse_coord_x = e.clientX;
			mouse_coord_y = e.clientY;
		}
	}
	
	if(!window.captureEvents) 
		document.onmousemove= this.internalMouseCoord
	else {
		window.captureEvents(Event.MOUSEMOVE);
		window.onmousemove= this.internalMouseCoord; //e should not be defined
	}

	
	//
	//	get element by id cross browser class
	//
	this.getElementByID = function(id){
		var obj = null;
		if(document.getElementById){
			//	w3c dom method
			obj = document.getElementById(id);
		}else if(document.all){
			//	id's must be unique and not coincide with name
			obj = document.all[id];
		}
		//	will return null if no element exists
		return obj;
	}
	
	//
	//	preloads images
	//
	this.preloadImages = function(){
		var arguments = this.preloadImages.arguments;
		for (var i = 0; i < arguments.length; i++) 
		{
			var image = new Image();
			image.src = arguments[i];
		}
	}
	
	//
	//	addevent
	//	@referenced http://ejohn.org/blog/flexible-javascript-events/
	//
	this.addEvent = function(obj, type, fn ) {
	  if ( obj.attachEvent ) {
		obj['e'+type+fn] = fn;
		obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
		obj.attachEvent( 'on'+type, obj[type+fn] );
	  } else
		obj.addEventListener( type, fn, false );
	}
	
	this.removeEvent = function( obj, type, fn ) {
	  if ( obj.detachEvent ) {
		obj.detachEvent( 'on'+type, obj[type+fn] );
		obj[type+fn] = null;
	  } else
		obj.removeEventListener( type, fn, false );
	}
	
	//
	//	make currentStyle compliant
	//
	this.getCurrentStyleValue = function(obj,property) {
		if(!obj.currentStyle) {
			if(document.defaultView && document.defaultView.getComputedStyle){
			   return document.defaultView.getComputedStyle(obj, "").getPropertyValue(property);
			}
		}
		else
			return obj.currentStyle[property];
	}
	
	//
	//	writes text into a frame
	//
	this.writeIntoFrame = function(frameid, html) {
		var frame = this.getElementByID(frameid);
		var doc = frame.contentDocument;
        if (doc == undefined || doc == null)
            doc = frame.contentWindow.document;
		
        doc.open();
        doc.write(text);
        doc.close();
	}
	
	//
	//	sets the visibility of a list of elements
	//
	this.setVisibility = function(visible) {
		var arguments = this.setVisibility.arguments;
		this.altlist = Array(arguments.length);
		for (var i = 1; i < arguments.length; i++) 
		{
			var element = this.getElementByID(arguments[i]);
			if(visible == false){
				element.style.visibility = 'hidden'; 
				element.style.display = 'none';
			} else {
				element.style.visibility = 'visible'; 
				element.style.display = '';
			}
		}
	}
	
	//
	//	toggles visibility of multiple element base
	//
	this.toggleVisible = function() {
		var arguments = this.toggleVisible.arguments;
		this.altlist = Array(arguments.length);
		for (var i = 0; i < arguments.length; i++) 
		{
			var element = this.getElementByID(arguments[i]);
			if(element.style.visibility != 'hidden'){
				element.style.visibility = 'hidden'; 
				element.style.display = 'none';
			} else {
				element.style.visibility = 'visible'; 
				element.style.display = '';
			}
		}
	}
	
	//
	//  array removal function
	//
	this.array_remove = function(array, from, to) {
		var rest = array.slice((to || from) + 1 || array.length);
		array.length = from < 0 ? array.length + from : from;
		return array.push.apply(array, rest);
	}

	
	this.root = '';
	
	//	will be initialized if you include window.js
	this.window = null;
	//	will be initialized if you include slideshow.js
	this.slideshow = null;
	//	will be initialize if you include validate.js
	this.validator = null;
	//	will be initialized if you include ajax.js (or installPlugins(root, "ajax"))
	this.ajax = null;
	//	will be initialized if you include comments.js (or installPlugins(root, "comments"))
	this.comments = null;
	//  will be initialized if you include table.js (or installPlugins(root, "table"))
	this.table = null;
	//	will be initialized if you include string.js (or installPlugins(root, "string"))
	this.string = null;
	//
	this.gallery = null;
	//
	this.effects = null;
	
	//
	//	loads the plugins for you
	//
	this.installPlugins = function(root){
		this.root = root;
		sroot = root + 'jscript/';
		
		document.write('<link rel="stylesheet" href="'+root+'netforge.css" type="text/css" media="screen" />');
		
		var arguments = this.installPlugins.arguments;
		this.altlist = Array(arguments.length);
		for (var i = 1; i < arguments.length; i++) 
		{
			document.write('<script language="javascript" src="'+sroot+arguments[i]+'.js"></script>');
		}
	}
}

var netforge = new netforge_class();
