window.onload = function() {
	core_onLoad();
	core_admin_onLoad();
}

/* files/javascript/core.js */

function core_onLoad() {
	setupResource();
}

function setupResource() {
	if(resourceLayer = document.getElementById('resourcelayer')) {
		if(resourceLink = document.getElementById('resourcelink')) {
			resourceLayer.style.height = '0px';
			resourceLayer.style.opacity = 0;
			resourceLayer.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)';
			resourceLink.style.display = 'inline';
		}
	}
}

function showResource() {
	if(resourceLayer = document.getElementById('resourcelayer')) {
		if(resourceLink = document.getElementById('resourcelink')) {
			var currentHeight = resourceLayer.offsetHeight;
			resourceLayer.style.height = 'auto';
			var targetHeight = resourceLayer.offsetHeight;
			resourceLayer.style.height = currentHeight +'px';
			openResource(resourceLayer, currentHeight, targetHeight, 0);
			resourceLink.innerHTML = '<a href="javascript:hideResource();" title="hide information about Autoclaves">Hide information about Autoclaves</a>';
		}
	}
}

function openResource(resourceLayer, currentHeight, targetHeight, layerOpacity) {
	if(currentHeight != targetHeight) {
		if(currentHeight > targetHeight) {
			currentHeight -= Math.ceil((currentHeight - targetHeight) / 15);
		}
		else {
			currentHeight -= Math.floor((currentHeight - targetHeight) / 15);
		}
		resourceLayer.style.height = currentHeight +'px';
		setTimeout(function() {openResource(resourceLayer, currentHeight, targetHeight, layerOpacity);}, 10);
	}
	else {
		if(layerOpacity == 0) {
			resourceLayer.style.height = 'auto';
		}
		if(layerOpacity < 100) {
			layerOpacity += 4;
			resourceLayer.style.opacity = layerOpacity / 100;
			resourceLayer.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+ layerOpacity +')';
			setTimeout(function() {openResource(resourceLayer, currentHeight, targetHeight, layerOpacity);}, 10);
		}
	}
}

function hideResource() {
	if(resourceLayer = document.getElementById('resourcelayer')) {
		if(resourceLink = document.getElementById('resourcelink')) {
			var currentHeight = resourceLayer.offsetHeight;
			resourceLayer.style.height = currentHeight +'px';
			closeResource(resourceLayer, currentHeight, 0, 100);
			resourceLink.innerHTML = '<a href="javascript:showResource();" title="find out more about Autoclaves">Find out more about Autoclaves</a>';
		}
	}
}

function closeResource(resourceLayer, currentHeight, targetHeight, layerOpacity) {
	if(layerOpacity > 0) {
		layerOpacity -= 4;
		resourceLayer.style.opacity = layerOpacity / 100;
		resourceLayer.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+ layerOpacity +')';
		setTimeout(function() {closeResource(resourceLayer, currentHeight, targetHeight, layerOpacity);}, 10);
	}
	else {
		if(currentHeight != targetHeight) {
			if(currentHeight > targetHeight) {
				currentHeight -= Math.ceil((currentHeight - targetHeight) / 15);
			}
			else {
				currentHeight -= Math.floor((currentHeight - targetHeight) / 15);
			}
			resourceLayer.style.height = currentHeight +'px';
			setTimeout(function() {closeResource(resourceLayer, currentHeight, targetHeight, layerOpacity);}, 10);
		}
	}
}

/* ../arxcore/modules/core/1.0.0/files/javascript/core_admin.js */

if(window.XMLHttpRequest) {
	var _core_xmlHTTP = new XMLHttpRequest();
}
else {
	var _core_xmlHTTP = new ActiveXObject('Microsoft.XMLHTTP');
}

var _core_oldMouseMove, _core_oldMouseUp, _core_cursorOrigX, _core_cursorOrigY;
var _core_dialogButtons = new Array(), _core_calendarResultFunction;

function core_admin_onLoad() {
	if(navigator.userAgent.toLowerCase().indexOf('safari') != -1) {
		if(iconContainer = document.getElementById('_core_icon_container')) {
			var iconHolders = new Array();
			loginIcons = iconContainer.getElementsByTagName('div');
			for(iconCount = 0; iconCount < loginIcons.length; iconCount++) {
				if(loginIcons[iconCount].getAttribute('iconName') != 'core') {
					iconHolders[iconHolders.length] = loginIcons[iconCount];
				}
				else {
					coreIcon = loginIcons[iconCount];
				}
			}
			loginIcons = new Array();
			loginIcons[0] = coreIcon;
			for(iconCount = 0; iconCount < iconHolders.length; iconCount++) {
				loginIcons[loginIcons.length] = iconHolders[iconCount];
			}
			setTimeout(function(){_core_showIcons(loginIcons, (loginIcons.length - 1), true, -25, 62, 2, 2);}, 1000);
		}
		if(dockHori = document.getElementById('_core_dock_hori')) {
			dockHori.style.marginLeft = '-'+ Math.round(dockHori.offsetWidth / 2) +'px';
			dockHori.style.visibility = 'visible';
		}
	}
}

function _core_showIcons(loginIcons, iconCount, fadeIcon, iconLeft, iconOpacity, imageWidth, imageHeight) {
	currentIcon = loginIcons[iconCount];
	currentIcon.style.left = '50%';
	currentIcon.style.marginLeft = iconLeft;
	if(fadeIcon) {
		iconOpacity = iconOpacity + Math.ceil((100 - iconOpacity) / 2);
		imageWidth = imageWidth + Math.ceil((40 - imageWidth) / 2);
		imageHeight = imageHeight + Math.ceil((40 - imageHeight) / 2);
		
		if(imageWidth >= 40 && imageHeight >= 40) {
			fadeIcon = false;
			iconOpacity = 100;
			imageWidth = 40;
			imageHeight = 40;
		}
		
		iconImages = currentIcon.getElementsByTagName('img');
		for(imageCount = 0; imageCount < iconImages.length; imageCount++) {
			iconImages[imageCount].style.width = imageWidth;
			iconImages[imageCount].style.height = imageHeight;
			iconImages[imageCount].style.marginLeft = '-'+ (imageWidth / 2);
		}
		currentIcon.style.opacity = iconOpacity / 100;
		currentIcon.style.filter = 'alpha(opacity='+ iconOpacity +')';
	}
	else {
		iconPosition = Math.ceil(iconCount / 2);
		if(iconCount % 2 == 0) {
			iconLeft = iconLeft + Math.ceil((((iconPosition * 50) + -25) - iconLeft) / 2);
			if(iconLeft >= (iconPosition * 50) + -25) {
				iconCount--;
				fadeIcon = true;
				iconOpacity = 62;
				imageWidth = 2;
				imageHeight = 2;
				iconLeft = (iconPosition * 50) + -25;
			}
		}
		else {
			iconLeft = iconLeft + Math.floor((((iconPosition * -50) + -25) - iconLeft) / 2);
			if(iconLeft <= (iconPosition * -50) + -25) {
				iconCount--;
				fadeIcon = true;
				iconOpacity = 62;
				imageWidth = 2;
				imageHeight = 2;
				iconLeft = (iconPosition * -50) + -25;
			}
		}
		currentIcon.style.marginLeft = iconLeft;
		if(fadeIcon) {
			iconLeft = -25;
		}
	}
	if(iconCount >= 0) {
		setTimeout(function(){_core_showIcons(loginIcons, iconCount, fadeIcon, iconLeft, iconOpacity, imageWidth, imageHeight);}, 30);
	}
	else {
		if(loginContainer = document.getElementById('_core_logincontainer')) {
			targetWidth = loginContainer.offsetWidth;
			loginContainer.style.width      = '0px';
			loginContainer.style.visibility = 'visible';
			_core_openLoginContainer(loginContainer, targetWidth, 0);
		}
	}
}

function _core_openLoginContainer(loginContainer, targetWidth, fieldOpacity) {
	if(loginContainer.offsetWidth < targetWidth) {
		loginContainer.style.width      = loginContainer.offsetWidth + Math.round((targetWidth - loginContainer.offsetWidth) / 2) +'px';
		loginContainer.style.marginLeft = '-'+ Math.round(loginContainer.offsetWidth / 2) +'px';
		setTimeout(function(){_core_openLoginContainer(loginContainer, targetWidth, fieldOpacity);}, 60);
	}
	else {
		document.getElementById('_core_loginerror').style.visibility  = 'visible';
		document.getElementById('_core_loginfields').style.visibility = 'visible';
	}
}

function _core_submitLoginForm(loadedIcons, iconCount, iconOpacity) {
	iconOpacity -= 10;
	loadedIcons[iconCount].style.opacity = iconOpacity / 100;
	loadedIcons[iconCount].style.filter  = 'alpha(opacity='+ iconOpacity +')';
	if(iconOpacity > 0) {
		setTimeout(function(){_core_submitLoginForm(loadedIcons, iconCount, iconOpacity);}, 20);
	}
	else {
		if(iconCount < (loadedIcons.length - 1)) {
			setTimeout(function(){_core_submitLoginForm(loadedIcons, (iconCount + 1), 100);}, 20);
		}
		else {
			document.getElementById('frmLogin').submit();
		}
	}
}

