﻿
var _tween;
var _xmlhttp;
var _tmpurl;
var _debug = true;

function centerContainer() {
    var container = $('wrapper');
    var window = $window();

    if (window.height > container.offsetHeight)
        container.style.top = ((window.height / 2) - (container.offsetHeight / 2)) + 'px';
    else
        container.style.top = '0';
}

function highlightMenu(index) {

    var yPos = index * 190;
    var bgPos = "left -" + yPos + "px";
    $('menu').style.backgroundPosition = bgPos;

}




window.onresize = centerContainer;

function loadXMLDoc(url, noHistory) {

    if (url.contains("http://")) {
        url = url.replace("http://", "");
        url = url.substring(url.indexOf("/"));
    }

    var randy = Math.random() * Date.parse(new Date())

    if (!noHistory)
        dhtmlHistory.add(url, randy);

    _tmpurl = url;

    if (typeof pageTracker != "undefined")
        pageTracker._trackPageview(url);

    if (url.contains("?"))
        _tmpurl += "&";
    else
        _tmpurl += "?";

    _tmpurl += "content=1&r=" + randy;
    $("loading").style.display = 'block';

    if (_tween)
        _tween.stop();
    _tween = Ekina.UI.Effects.Tween.alpha($("contents_holder"), 0, { duration: .5, func: Ekina.UI.Effects.Tween.Regular.Out });
    _tween.start();

    _tween.onTweenFinished = function() {


        _xmlhttp = null;
        if (window.XMLHttpRequest) {// code for all new browsers
            _xmlhttp = new XMLHttpRequest();
        }
        else if (window.ActiveXObject) {// code for IE5 and IE6
            _xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }

        if (_xmlhttp != null) {
            _xmlhttp.onreadystatechange = state_Change;
            _xmlhttp.open("GET", _tmpurl, true);
            _xmlhttp.send(null);

        }
        else {
            alert("Your browser does not support XMLHTTP.");
        }

    };

    return false;
}

function state_Change() {
    if (_xmlhttp.readyState == 4) { // 4 = "loaded"
        //if (_xmlhttp.status == 200) { // 200 = OK
        $("loading").style.display = 'none';
        $('contents_holder').innerHTML = _xmlhttp.responseText;
        _tween.stop();
        _tween = Ekina.UI.Effects.Tween.alpha($("contents_holder"), 100, { duration: .5, func: Ekina.UI.Effects.Tween.Regular.Out });
        _tween.start();
        _tween.onTweenFinished = null;
        //                }
        //                else {
        //                    alert(_xmlhttp.responseText);
        //                    alert("Problem retrieving XML data");
        //                }
    }
}