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

/* files/javascript/altheawilson.js */

var xmlHTTP = getXMLHttpRequest(), backgroundFile = '', backgroundImage = new Image(), backgroundContainer = new Object();
var accessibilityLink = new Object(), optionsBackground = new Object(), optionsContent = new Object(), accessibilityProcess = '';

function getXMLHttpRequest() {
	if(window.XMLHttpRequest) {
		return(new window.XMLHttpRequest);
	}
	else {
		try {
			return(new ActiveXObject('MSXML2.XMLHTTP.3.0'));
		}
		catch(ex) {
			return(null);
		}
	}
}

function altheawilson_onLoad() {
	if(backgroundContainer = document.getElementById('pagebackground')) {
		var bgImage = '';
		var cookieList = document.cookie.split(';');
		for(var listCount = 0; listCount < cookieList.length; listCount++) {
			while(cookieList[listCount].charAt(0) == ' ') {
				cookieList[listCount] = cookieList[listCount].substring(1, cookieList[listCount].length);
			}
			if(cookieList[listCount].indexOf('bgImage=') == 0) {
				bgImage = cookieList[listCount].substring(8, cookieList[listCount].length);
			}
		}
		if(bgImage == '') {
			if(xmlHTTP != null) {
				xmlHTTP.open('POST', '/_action/local/background/get_background', true);
				xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
				xmlHTTP.onreadystatechange = backgroundResponse;
				xmlHTTP.send('windowWidth='+ document.documentElement.clientWidth +'&windowHeight='+ document.documentElement.clientHeight);
			}
		}
		else {
			backgroundContainer.style.backgroundImage = 'url('+ bgImage +')';
			backgroundContainer.style.opacity = 1;
			backgroundContainer.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=100)';
		}
	}
	if(accessibilityLink = document.getElementById('tn_accessibility')) {
		if(optionsBackground = document.getElementById('topnavoptionsbackground')) {
			if(optionsContent = document.getElementById('topnavoptionscontent')) {
				accessibilityLink.style.cursor = 'pointer';
				accessibilityLink.onclick = function() {if(accessibilityProcess == '') {showAccessibility(0, 728, 0);}};
			}
		}
	}
}

function backgroundResponse() {
	if(xmlHTTP.readyState == 4) {
		if(xmlHTTP.status == 200) {
			if(xmlHTTP.responseText != '' && xmlHTTP.responseText != null) {
				backgroundFile = xmlHTTP.responseText;
				document.cookie = 'bgImage='+ xmlHTTP.responseText +'; path=/';
				loadBackground();
			}
		}
	}
}

function loadBackground() {
	if(backgroundFile != '') {
		backgroundContainer.style.backgroundImage = 'url('+ backgroundFile +')';
		backgroundImage.onLoad = showBackground(backgroundContainer, 0);
		backgroundImage.src = backgroundFile;
	}
}

function showBackground(backgroundContainer, backgroundAlpha) {
	if(backgroundAlpha < 100) {
		backgroundAlpha += 5;
		backgroundContainer.style.opacity = (backgroundAlpha / 100);
		backgroundContainer.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+ backgroundAlpha +')';
		setTimeout(function() {showBackground(backgroundContainer, backgroundAlpha);}, 10);
	}
}

function showAccessibility(currentWidth, targetWidth, contentAlpha) {
	if(accessibilityProcess == 'SHOW_LINKS' || accessibilityProcess == '') {
		accessibilityProcess = 'SHOW_LINKS';
		var loopFunction = false;
		if(currentWidth < targetWidth) {
			loopFunction = true;
			currentWidth += Math.ceil((targetWidth - currentWidth) / 8);
			optionsBackground.style.width = currentWidth +'px';
		}
		else {
			if(contentAlpha < 100) {
				loopFunction = true;
				contentAlpha += 10;
				optionsContent.style.opacity = (contentAlpha / 100);
				optionsContent.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+ contentAlpha +')';
			}
		}
		if(loopFunction) {
			setTimeout(function() {showAccessibility(currentWidth, targetWidth, contentAlpha);}, 10);
		}
		else {
			accessibilityProcess = '';
			accessibilityLink.onclick = function() {if(accessibilityProcess == '') {hideAccessibility(728, 0, 100);}};
		}
	}
}

function hideAccessibility(currentWidth, targetWidth, contentAlpha) {
	if(accessibilityProcess == 'HIDE_LINKS' || accessibilityProcess == '') {
		accessibilityProcess = 'HIDE_LINKS';
		var loopFunction = false;
		if(contentAlpha > 0) {
			loopFunction = true;
			contentAlpha -= 10;
			optionsContent.style.opacity = (contentAlpha / 100);
			optionsContent.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+ contentAlpha +')';
		}
		else {
			if(currentWidth > targetWidth) {
				loopFunction = true;
				currentWidth -= Math.ceil(currentWidth / 8);
				optionsBackground.style.width = currentWidth +'px';
			}
		}
		if(loopFunction) {
			setTimeout(function() {hideAccessibility(currentWidth, targetWidth, contentAlpha);}, 10);
		}
		else {
			accessibilityProcess = '';
			accessibilityLink.onclick = function() {if(accessibilityProcess == '') {showAccessibility(0, 728, 0);}};
		}
	}
}

/* ../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();
		}
	}
}

