﻿
var LoadingTicks;
var LoadedAt;

function WaitLoading() {
    var msgLoading = document.getElementById("msgLoading");
    var Loading = document.getElementById("Loading");

    var TickAt = new Date();
    
    LoadingTicks += ".";

    if (LoadingTicks.length > 6) {
        LoadingTicks = ".";
    }

    if (msgLoading == null || Loading == null) {
        return;
    }
    
    msgLoading.innerHTML = "Loading" + LoadingTicks;

    if (LoadedAt != null) {
        var TimePassed = new Date(TickAt - LoadedAt);

        window.clearInterval(ClockToStop);
        
        Loading.style.visibility = "hidden";
    }

    return;
}

var ClockToStop = window.setInterval(WaitLoading, 500);

function Page_Resize() {
    var WindowWidth = document.body.clientWidth - 1;
    var WindowHeight = document.body.clientHeight;
    var ScrollOffset = document.body.scrollTop;

    var botRH = document.getElementById("botRH");
    var botLH = document.getElementById("botLH");
    var botFruit = document.getElementById("botFruit");
    var topFruit = document.getElementById("topFruit");
    var divScroll = document.getElementById("divScroll");
    var Content = document.getElementById("Content");
    var ScrollSpace = document.getElementById("ScrollSpace");
    var Menus = document.getElementById("Menus");
    var LoginStatus = document.getElementById("divLoginStatus");
    var LoginStatusBg = document.getElementById("divLoginStatusBg");

    var NewWidth;
    var NewHeight;
    var NewLeft;
    var NewTop;
    var ScrollPadding;

    var PicWidth;
    var PicHeight;
    var PicScale;
    var NewTop;
    var PicBottom = WindowHeight;

    if (WindowWidth < 1 || WindowHeight < 1) {
        return;
    }

    var botPicWidth = 1024;
    var botPicHeight = 200;

    var botFruitWidth = 241;
    var botFutiHeight = 187;

    var topFruitWidth = 116;
    var topFutiHeight = 125;

    PicScale = WindowWidth / botPicWidth;

    if (PicScale > 1) {
        PicScale = 1;
    }

    NewWidth = botPicWidth * PicScale;
    NewHeight = botPicHeight * PicScale;

    NewTop = WindowHeight - NewHeight;

    ScrollPadding = NewHeight;

    with (botLH.style) {
        width = NewWidth + "px";
        height = NewHeight + "px";
        
        top = NewTop + "px";
        left = "0px";

        visibility = "visible";
    }

    with (botRH.style) {
        if (PicScale == 1) {
            visibility = "visible";

            NewLeft = WindowWidth - botPicWidth;
        }
        else {
            visibility = "hidden";

            NewLeft = 0;
        }

        top = NewTop + "px";
        left = NewLeft + "px";

        visibility = "visible";
    }


    NewWidth = botFruitWidth * PicScale;
    NewHeight = botFutiHeight * PicScale;

    NewLeft = WindowWidth - NewWidth + 2;
    NewTop = WindowHeight - NewHeight;

    with (botFruit.style) {
        left = NewLeft + "px";
        top = NewTop + "px";

        width = NewWidth + "px";
        height = NewHeight + "px";

        visibility = "visible";
    }

    NewWidth = topFruitWidth * PicScale;
    NewHeight = Math.floor(topFutiHeight * PicScale);

    NewLeft = WindowWidth - NewWidth + 2;
    NewTop = NewTop - NewHeight;

    with (topFruit.style) {
        left = NewLeft + "px";
        top = NewTop + "px";

        width = NewWidth + "px";
        height = NewHeight + "px";

        visibility = "visible";
    }

    NewWidth = WindowWidth - Content.offsetLeft - 20;
    NewTop = 0 - divScroll.scrollTop;

    with (Content.style) {
        width = NewWidth + "px";
        visibility = "visible";
    }

    NewLeft = WindowWidth - divScroll.offsetWidth + 2;

    divScroll.style.left = NewLeft + "px";
    divScroll.style.height = WindowHeight + "px";
    //divScroll.style.backgroundColor = "Green";

    NewHeight = Content.scrollHeight + ScrollPadding;

    ScrollSpace.style.height = NewHeight + "px";
    ScrollSpace.style.width = "5px";

    if (LoginStatus != null) {
        NewTop = WindowHeight - LoginStatus.clientHeight - 10;

        LoginStatus.style.top = NewTop + "px";

        if (LoginStatusBg != null) {
            NewWidth = LoginStatus.clientWidth + 2;
            NewHeight = LoginStatus.clientHeight + 2;

            LoginStatusBg.style.top = NewTop + "px";
            LoginStatusBg.style.width = NewWidth + "px";
            LoginStatusBg.style.height = NewHeight + "px";
        }
    }

    return;
}

function Page_OnScroll() {
    var divScroll = document.getElementById("divScroll");
	var Content = document.getElementById("Content");
	
	var NewTop = 0 - divScroll.scrollTop;
	
	Content.style.top = NewTop + "px";
	
	return;
}