/**
 * @file       home.js
 * @author     Pavel Sokolov
 * @brief      TurnAges home page interface management operations
 *
 * Copyright (C) 2007-2011, TurnAges.com.
 *
 * The copyright notice above does not evidence any actual or intended publication of such 
 * source code. The code contains Edge Beyond Confidential Proprietary Information.
 */
 
function toggleLayer(id0, id1) {
    var c = document.getElementById(id0);
    c.style.display = 'none';

    c = document.getElementById(id1);
    c.style.display = 'block';
}

function toggleRatings(id) {
    if (typeof this.cRat == 'undefined') {
        this.cRat = 0;
    }
    
    toggleLayer("rat"+this.cRat, "rat"+id);

    this.cRat = id;
    
    return false;
};

function toggleNewsbit(id) {
    if (typeof this.cNBit == 'undefined') {
        this.cNBit = 0;
    }
    
    toggleLayer("nbit"+this.cNBit, "nbit"+id);
    this.cNBit = id;
    
    return false;
};

function toggleAbout(id) {
    if (typeof this.cAbout == 'undefined') {
        this.cAbout = 0;
    }
    
    toggleLayer("about"+this.cAbout, "about"+id);
    this.cAbout = id;
    
    return false;
};

function openWnd(n, w, h) {
    var newwindow=window.open(n,"name", "height="+(h+10)+",width="+(w+10));
    return false;
};

function post(args, cb) {
    $.ajax({
            type: "GET",
            url: "/ajax/",
            success: cb,
            data: args,
            error: cb
    });
};

function logout() {
    post({tp:0x1001}, function(){});
};

function Dec2Hex(dec,padTo){
 //*** Turns a decimal number into hexadecimal
 //*** If padTo is specified (optional) the result is padded with leading zeros to the specified number of characters
    var h=Math.round(dec).toString(16).toLowerCase();
    if (padTo && h.length<padTo) { 
        h = (Math.pow(10,padTo-h.length)+h).substr(1);
    }
    return h;
};

function fadeLogin() {
//    $('#loginbtn').fadeOut();
    var $d = document.getElementById('loginbtn');
    
    var c = 0xA0;
    var c2 = 0xA0;
    var s = 0xFF - 0xA0;
    var diff = 0xFF - 0xA0;
    var v = 0;
    var t = 500/s;
    s = t*s / 500;
    var dir = 0;
    ( function () {
        if (dir == 0) {
            if (v >= diff) {
                dir = 1;
                v = diff;
            } else {
                v += s;
            }
        } else if (dir == 1) {
            if (v <= 0) {
                dir = 0;
                v = 0;
            } else {
                v -= s;
            }
        }
        
        if (v > diff) {
            v = diff;
        } else if (v < 0) {
            v = 0;
        }
        
        c = 0xA0 + v;
        c2 = 0xA0 - v;
        
        if (c > 0xFF) {
            c = 0xFF;
        } else if (c < 0xA0) {
            c = 0xA0;
        }
        
        if (c2 > 0xFF) {
            c2 = 0xFF;
        } else if (c2 < 0xA0) {
            c2 = 0xA0;
        }

        var h = Dec2Hex(c, 2);
        var h2 = Dec2Hex(c2, 2);
        var color = '#'+h+'A0'+h2;
        $d.style.color = color;
        
        setTimeout(arguments.callee, t);
    })();
};

function onLoad() {
    setTimeout(fadeLogin, 500);
};

onLoad();

