function netCatWindows() {
	this.currentWindow = null;
	this.currentShim = null;
	this.infoBar = null;
	this.closeButton = null;
	this.message = null;
	this.actions = function(){};
	this.windowArray = new Array();
	this.eventArray = new Array();
	
	this.colCountLeft = 0;
	this.colCountCenter = 0;
	
	this.makeWindow = ncW_makeWindow;
	this.drawShim = ncW_drawShim;
	this.processAction = ncW_processAction;
	this.closeWindows = ncW_closeAll;
	this.parameters = null;

	return this;
}

function ncW_closeAll() {
	theShim = this.currentShim;
	if (theShim) {
		theShim.parentNode.removeChild(theShim);
		(ncW_manager.infoBar).parentNode.removeChild(ncW_manager.infoBar);
		(ncW_manager.closeButton).parentNode.removeChild(ncW_manager.closeButton);
	}
	
	for (var ncW_i = 0; ncW_i < this.windowArray.length; ncW_i++) {
		theObj = ncW_manager.windowArray[ncW_i][0];
		
		theObj.parentNode.removeChild(theObj);
	}
	this.currentShim = null;
	this.windowArray = new Array();
	this.eventArray = new Array();
	this.message = null;
	
	this.colCountLeft = 0;
	this.colCountCenter = 0;
}

function ncW_makeWindow( showShim, position, name, caption ) {
	ncW_objDiv = ncW_drawWindow( showShim, position, name, caption );
	this.windowArray[(this.windowArray).length] = [ncW_objDiv, position, name];
	return (this.windowArray).length - 1;
}

function ncW_drawWindow( showShim, position, name, caption ) {
	var db=document.body, dd=document.documentElement;
  	var topOffset = (150 + db.scrollTop + dd.scrollTop) + 'px';
  	
	if (showShim) {
		ncW_manager.drawShim(caption); 
		ncW_manager.infoBar = ncW_drawLayer( '10%', 110, '75%', 40, 'infoBar', 'ncWcol_infobar' );
		ncW_manager.infoBar.innerHTML = '<div>' + ncW_manager.message + '</div>';
		ncW_manager.closeButton = ncW_drawLayer( '10%', 94, '75%', 16, 'closeButton', 'ncWcol_infobar' );
		ncW_manager.closeButton.innerHTML = '<span><a href="javascript:;" onclick="ncW_manager.closeWindows();return false;">Close</a></span>';
	}
	switch(position) {
		case 'left':
			var width = "20%";
			var top = 150;
			var left = "10%";
			var height = 400;
			var className = "ncWcol_left";
			ncW_manager.colCountLeft++;
			break;
		case 'center':
			var width = "55%";
			var top = 150;
			var left = "30%";
			var height = 400;
			var className = "ncWcol_centre";
			ncW_manager.colCountCenter++;
			break;
		default:
			var width = "55%";
			var top = topOffset;
			var left = "25%";
	}

	if (ncW_manager.colCountLeft >0 && ncW_manager.colCountCenter >0 ) {
		ncW_manager.infoBar.style.left='10%';
		ncW_manager.infoBar.style.width='75%';
	}
	
	if (ncW_manager.colCountLeft ==0 && ncW_manager.colCountCenter >0 ) {
		ncW_manager.infoBar.style.left='30%';
		ncW_manager.infoBar.style.width='55%';
	}
	
	if (ncW_manager.colCountLeft >0 && ncW_manager.colCountCenter ==0 ) {
		ncW_manager.infoBar.style.left='20%';
		ncW_manager.infoBar.style.width='10%';
	}
	
	ncW_myWindow =  ncW_drawLayer( left, top, width, height, name, className );
	ncW_manager.eventArray[(ncW_manager.eventArray).length] = ['AJAX', null, 'init_' + name, ncW_myWindow];
	ncW_manager.processAction(null, 'init_' + name);
	
	return ncW_myWindow;
}

function ncW_drawLayer( left, top, width, height, name, className ) {
	var isIE6 = navigator.userAgent.toLowerCase().indexOf('msie 6') != -1;
	var db=document.body, dd=document.documentElement;
	var topOffset = (db.scrollTop + dd.scrollTop);
	var newWindowDiv = document.createElement('div');  
	newWindowDiv.id = 'ncW_' + name;  
	newWindowDiv.style.position = 'fixed';  
	if (isIE6) { newWindowDiv.style.position = 'absolute'; }
	newWindowDiv.style.top = top + 'px';  
	if (isIE6) { newWindowDiv.style.top = (document.documentElement.scrollTop + top) + 'px'; }
	newWindowDiv.style.left = left;  
	newWindowDiv.style.width = width;  
	newWindowDiv.style.height = height +'px';  
	newWindowDiv.style.backgroundColor = '#000'; 
	newWindowDiv.style.zIndex = 9100;
	newWindowDiv.className = className + " ncWcol_element ncWcolumn";
	newWindowDiv.innerHTML="<div style=\"position: absolute; top: 50%;left: 50%;display: table-cell; vertical-align: middle;\" class=\"site_uploadStatusIndicator\">Loading...</div>";
	document.body.appendChild(newWindowDiv);

	return newWindowDiv;
}

function ncW_drawShim( caption ) {
	var isIE6 = navigator.userAgent.toLowerCase().indexOf('msie 6') != -1;
  var db=document.body, dd=document.documentElement;
  var topOffset = (0 + db.scrollTop + dd.scrollTop) + 'px';

  var shimDiv = document.createElement('div');  
	shimDiv.id = 'ncW_shim';  
	shimDiv.style.position = 'fixed';
	if (isIE6) { shimDiv.style.position = 'absolute'; }
	shimDiv.style.top = "0px"; 
	/*if (isIE6) { shimDiv.style.top = document.documentElement.scrollTop + 'px'; }*/
	shimDiv.style.left = "0px";  
	shimDiv.style.width = "100%"; 
	shimDiv.style.height = "100%";
	if (isIE6) { shimDiv.style.height = jQuery(document).height() + 'px'; }
	shimDiv.style.backgroundColor = '#333333'; 
	shimDiv.style.zIndex = 9000;
	shimDiv.style.opacity = '0.60';
	shimDiv.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=60)';
	shimDiv.innerHTML = '<div id="ncW_caption">' + caption + '</div><div id="ncW_closeLink">&nbsp;</div>'; /*<a href="javaScript:ncW_manager.closeWindows()"><span>Close</span></a></div>';*/
	document.body.appendChild(shimDiv);
	
	this.currentShim = shimDiv;	
}

function ncW_processAction( data, eventID ) {
	/* find event */
	var theEvent = -1;
	for (var ncWe_i = 0; ncWe_i < ncW_manager.eventArray.length; ncWe_i++) {
	    if (ncW_manager.eventArray[ncWe_i][2] == eventID)
	      theEvent = ncWe_i;
	}
	
	if (theEvent>=0) {
		mostRecentEvent=ncW_manager.eventArray[theEvent];
		type= mostRecentEvent[0];
		queryObject = mostRecentEvent[1];
		eventIdentifier = mostRecentEvent[2];
		divObject = mostRecentEvent[3];
		ncW_manager.actions(type,queryObject,eventIdentifier,data,divObject);
	} else {
	
	}
}

var ncW_manager = new netCatWindows();