function contentObject(fa,fb,fc,fd) {
    this.path = fa;
    this.description = fb;
    this.myWidth = fc;
    this.myHeight = fd;
}

function pageObject(fa,fb,fc) {
    this.name = fa;
    this.anchor = fb;
    this.inner = fc;
}

var contents = null;
var contentsIndex = 0;
var pagesArray = new Array();
var order = null;
var newScript = null;
var needsId = !document.all;
var timer = null;
var lastAnchor = "";
var theIframe = null;
var iframeDoc = "iframe.htm";
var imagesArray = new Array();
    imagesArray[0] = new Image(100,50);
    imagesArray[0].src = "button2.png";

function getAnchor(page) {
    var fragments = page.split(".");
    return (fragments[0]);
}

function getPage(anchor) {
    if (anchor == "")
        return pagen;
    else
        if (anchor.indexOf("?") == -1)
            return (anchor.substring(1) + ".php");
        else {
            var fragments = anchor.substring(1).split("?");
            return (fragments[0] + ".php?" + fragments[1]);
        }
}

function initialize() {
    contents = new Array();
    contentsIndex = 0;
    var anchors = document.getElementsByTagName('a');
    for (i = 0; i < anchors.length; i++)
        if (anchors[i].className == "external") {
            anchors[i].onclick = function() {
                window.open(this.href);
                return false;
            }
        }
        else
            if (anchors[i].className == "externalimage") {
                anchors[i].onclick = function() {
                    contents[contentsIndex] = new contentObject(this.href,"",0,0);
                    showScreenshot();
                    return false;
                }
            }
    if (needsId) {
        b1 = document.getElementById('b1');
        b2 = document.getElementById('b2');
        b3 = document.getElementById('b3');
        infolayer = document.getElementById('infolayer');
        floatingimage = document.getElementById('floatingimage');
    }
    if (document.getElementById('scriptlayer')) {
        newScript = document.createElement('script');
        newScript.type = 'text/javascript';
        newScript.src = document.getElementById('scriptlayer').innerHTML;
        document.getElementsByTagName('head')[0].appendChild(newScript);
    }
    if (pagesArray.length == 0)
        lastAnchor = "";
    else
        lastAnchor = window.location.hash;
    if (!needsId && theIframe == null && (/MSIE (\d+\.\d+);/.test(navigator.userAgent))) {
        var ieversion = new Number(RegExp.$1);
        if (ieversion < 8 || (ieversion >= 8 && document.compatMode == "BackCompat")) {
            theIframe = document.createElement("iframe");
            theIframe.src = iframeDoc + "?new=" + window.location.hash.substring(1);
            document.body.appendChild(theIframe);
        }
    }
    if (theIframe == null)
        timer = setInterval("check('');",200);
    document.title = "XAKLSE'S ZONE";
}

function newOrder() {
    if (window.XMLHttpRequest)
        order = new XMLHttpRequest();
    else
        if (window.ActiveXObject) {
            order = new ActiveXObject("Msxml2.XMLHTTP");
            if (!order)
                order = new ActiveXObject("Microsoft.XMLHTTP");
        }
}

function change(num) {
    if (imagesArray && imagesArray != null) {
        var str="b" + num + ".className = 'button2';";
        eval(str);
    }
}

function restore(num) {
    if (imagesArray && imagesArray != null) {
        var str="b" + num + ".className = 'button1';";
        eval(str);
    }
}

function goToPage(page) {
    if (page != "") {
        if (timer != null)
            clearInterval(timer);
        if (newScript != null) {
            document.getElementsByTagName('head')[0].removeChild(newScript);
            newScript = null;
        }
        var found = false;
        for (i = 0; i < pagesArray.length; i++)
            if (pagesArray[i].name == page) {
                found = true;
                break;
            }
        if (!found) {
            pagesArray[pagesArray.length] = new pageObject(page,getAnchor(page),"");
            infolayer.innerHTML = "<div id='loading'></div>";
            newOrder();
            order.onreadystatechange = process;
            order.open("GET",page,true);
            order.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
            order.send(".?.");
        }
        else {
            infolayer.innerHTML = pagesArray[i].inner;
            window.location.hash = pagesArray[i].anchor;
            if (theIframe != null)
                theIframe.src = iframeDoc + "?new=" + pagesArray[i].anchor;
            initialize();
        }
    }
}

function process() {
    if (order.readyState == 4) {
        infolayer.innerHTML = order.responseText;
        if (pagesArray[pagesArray.length - 1].inner == "")
            pagesArray[pagesArray.length - 1].inner = infolayer.innerHTML;
        window.location.hash = pagesArray[pagesArray.length - 1].anchor;
        if (theIframe != null)
            theIframe.src = iframeDoc + "?new=" + pagesArray[pagesArray.length - 1].anchor;
        initialize();
    }
}

function check(route) {
    if (theIframe == null) {
        if (lastAnchor != window.location.hash)
            goToPage(getPage(window.location.hash));
    }
    else {
        if (route != "" && route.indexOf("=") != -1) {
            var fragments = route.split("=");
            if (lastAnchor != "#" + fragments[1])
                goToPage(getPage("#" + fragments[1]));
        }
        document.title = "XAKLSE'S ZONE";
    }
}

function clicked(num) {
    var page = "";
    switch (num) {
        case 1: page = pagen;
                break;
        case 2: page = pagea;
                break;
        case 3: page = pagep;
    }
    goToPage(page);
}

function showScreenshot() {
    if (needsId)
        var bodyHeight = document.body.clientHeight;
    else
        var bodyHeight = document.body.offsetHeight + 1;
    var imageHeight = 600;
    if (contents[contentsIndex].myHeight != 0)
        imageHeight = contents[contentsIndex].myHeight;
    if (bodyHeight > imageHeight)
        floatingimage.style.paddingTop = ((bodyHeight - imageHeight) / 2) + "px";
    else
        floatingimage.style.paddingTop = "0px";
    var str = "<img src='" + contents[contentsIndex].path + "' ";
    if (contents[contentsIndex].myHeight == 0)
        str += "height='600' ";
    if (contents[contentsIndex].description != "") {
        str += "title='" + clickHide + ". " + contents[contentsIndex].description + "' alt='" + clickHide + ". " + contents[contentsIndex].description + "' />";
        str = str.replace(/<br \/>/g," ");
    }
    else
        str += "title='" + clickHide + "' alt='" + clickHide + "' />";
    floatingimage.innerHTML = str;
    floatingimage.style.display = "inline";
}

function hideScreenshot() {
    floatingimage.style.display = "none";
}

function changeScreenshot(num) {
    contentsIndex += num;
    if (contentsIndex < 0)
        contentsIndex = 0;
    else
        if (contentsIndex > contents.length - 1)
            contentsIndex = contents.length - 1;
    document.images.screenshot.src = contents[contentsIndex].path;
    document.images.screenshot.width = "0";
    description.innerHTML = contents[contentsIndex].description;
    if (contentsIndex == 0) {
        arrowl.style.visibility = "hidden";
        arrowr.style.visibility = "visible";
    }
    else {
        arrowl.style.visibility = "visible";
        if (contentsIndex == contents.length - 1)
            arrowr.style.visibility = "hidden";
        else
            arrowr.style.visibility = "visible";
    }
}

function loadedScreenshot() {
    document.images.screenshot.width = "600";
}

