function toTitleCase(str) {
    return str.substr(0,1).toUpperCase() + str.substr(1);
}      
            
function formatTitle(title) {
     return 'Atlantic Group Coaching' + (title != '/' ? ' / ' + toTitleCase(title.substr(1, title.length - 2).replace(/\//g, ' / ')) : '');
}
             
function getTransport() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        try {
        	return new ActiveXObject('Msxml2.XMLHTTP');
            } catch(e) {
            return new ActiveXObject('Microsoft.XMLHTTP');
    	}
    }
}

function updateContent(html) {
                var content = document.getElementById('content');
                if (com.asual.util.Browser.isIE()) {
                    var _content = document.getElementById('_content');
                    if (_content == null) {
                        var _content = content.cloneNode(false);
                        _content.id = '_content';
                        _content.style.position = 'absolute';
                        _content.style.top = content.offsetTop;
                        _content.style.left = '325px';
                        //_content.style.width = content.offsetWidth;
                        //_content.style.marginLeft = -content.offsetWidth/2;
                        document.body.appendChild(_content);
                    }
                    _content.innerHTML = html;
                    content.style.height = _content.offsetHeight;
					//appear(_content);
                } else {
                    content.innerHTML = html;
					//appear(_content);
                }
                while (html.match(/(<script[^>]+javascript[^>]+>\s*(\/\/*<!\[CDATA\[)?(<!--)?\s*)/i)) {
                    html = html.substr(html.indexOf(RegExp.$1) + RegExp.$1.length);
                    if (!html.match(/((\/\/ *\]\]>)?(-->)?\s*<\/script>)/)) break;
                    block = html.substr(0, html.indexOf(RegExp.$1));
                    html = html.substring(block.length + RegExp.$1.length);
                    eval(block);
                }
}
            
function updateChange(xhr) {
	if (xhr.readyState == 4) {
    	if (xhr.status == 200) {
            updateContent(xhr.responseText);
        } else {
            alert('Error: ' + xhr.status + '!');
        }
	}
}
            
function handleChange(event) {
	var xhr = getTransport();
	xhr.onreadystatechange = function() {
		updateChange(xhr);
	}
   xhr.open('get', 'datasource/' + (event.value == '/' ? 'homes' : event.value.replace(/\//g, '')) + '.xml', true);
   xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
   xhr.send('');
   SWFAddress.setTitle(formatTitle(event.value));
}
            
SWFAddress.addEventListener(SWFAddressEvent.CHANGE, handleChange);

function appear(content, value) {
    if (typeof value == 'undefined') value = 0;
    if (value > 1){
		content.style.filters = null;
		return;
	}
    var property = content.filters ? 'filter' : 'opacity';
    content.style[property] = content.filters ? 'alpha(opacity=' + value*100 + ')' : value;
    setTimeout(function () {appear(content, value + .1)} , 50);
}