// gaybar.js
// Ron Lau 2009
// Copyright Netcast Platform 2009
//
// Created       : 14/03/2009
// For source of playlist, refer to playlist.js
// <script>

function grIconUp(e)
{
    getEventElement(e).src = 'images/gaybar/gaybar_grbutton.jpg';
}

function grIconDown(e)
{
    getEventElement(e).src = 'images/gaybar/gaybar_grbutton_press.jpg';
}

function hideRadio()
{
    document.getElementById('ddList_radio').style.display = 'none';
    document.getElementById('radioButton').className = 'ddListIconBox ddListIconOff';
}

function hideBlog()
{
    document.getElementById('ddList_blog').style.display = 'none';
    document.getElementById('blogButton').className = 'ddListIconBox ddListIconOff';
}

function hideForum()
{
    document.getElementById('ddList_forum').style.display = 'none';
    document.getElementById('forumButton').className = 'ddListIconBox ddListIconOff';
}

function hideChat()
{
    document.getElementById('chatBox').style.display = 'none';
    document.getElementById('chatButton').className = 'chatIconUp ptcur';
}

function hideAChat()
{
    document.getElementById('AchatBox').style.display = 'none';
    document.getElementById('AchatButton').className = 'AchatIconUp ptcur';
}

function showRadio()
{
    document.getElementById('ddList_radio').style.display = '';
    document.getElementById('radioButton').className = 'ddListIconBox ddListIconOn';
}

function showBlog()
{
    document.getElementById('ddList_blog').style.display = '';
    document.getElementById('blogButton').className = 'ddListIconBox ddListIconOn';
}

function showForum()
{
    document.getElementById('ddList_forum').style.display = '';
    document.getElementById('forumButton').className = 'ddListIconBox ddListIconOn';
}

function showChat()
{
    document.getElementById('chatBox').style.display = '';
    document.getElementById('chatButton').className = 'chatIconDown ptcur';
}

function showAChat()
{
    document.getElementById('AchatBox').style.display = '';
    document.getElementById('AchatButton').className = 'AchatIconDown ptcur';
}

function toggleRadio(event)
{
    if(typeof toggleRadio.show == 'undefined')
        toggleRadio.show = false;
    if(toggleRadio.show)
        hideRadio();
    else
    {
        showRadio();
        hideBlog();
        hideForum();
        toggleBlog.show = false;
        toggleForum.show = false;
    }
    toggleRadio.show = !toggleRadio.show;
}

function toggleBlog(event)
{
    if(typeof toggleBlog.show == 'undefined')
        toggleBlog.show = false;
    if(toggleBlog.show)
        hideBlog();
    else
    {
        hideRadio();
        showBlog();
        hideForum();
        toggleRadio.show = false;
        toggleForum.show = false;
    }
    toggleBlog.show = !toggleBlog.show;
}

function toggleForum(event)
{
    if(typeof toggleForum.show == 'undefined')
        toggleForum.show = false;
    if(toggleForum.show)
        hideForum();
    else
    {
        hideRadio();
        hideBlog();
        showForum();
        toggleRadio.show = false;
        toggleBlog.show = false;
    }
    toggleForum.show = !toggleForum.show;
}

function toggleChat(event)
{
    if(typeof toggleChat.show == 'undefined')
        toggleChat.show = false;
    if(toggleChat.show)
        hideChat();
    else
    {
        hideRadio();
        hideBlog();
        hideForum();
        hideAChat();
        toggleRadio.show = false;
        toggleBlog.show = false;
        toggleForum.show = false;
        toggleAChat.show = false;
        showChat();
    }
    toggleChat.show = !toggleChat.show;
}

function toggleAChat(event)
{
    if(typeof toggleAChat.show == 'undefined')
        toggleAChat.show = false;
    if(toggleAChat.show)
        hideAChat();
    else
    {
        hideRadio();
        hideBlog();
        hideForum();
        hideChat();
        toggleRadio.show = false;
        toggleBlog.show = false;
        toggleForum.show = false;
        toggleChat.show = false;
        showAChat();
    }
    toggleAChat.show = !toggleAChat.show;
}

function blueLine(event)
{
    var ele = getEventElement(event);
    if(ele.tagName == 'NOBR')
        ele = ele.parentNode;
    ele.style.backgroundColor = '#CCCCCC';
}

function revertLine(event)
{
    var ele = getEventElement(event);
    if(ele.tagName == 'NOBR')
        ele = ele.parentNode;
    ele.style.backgroundColor = '';
}

function gotoURL(url)
{
    var ele = document.getElementById('contIFrame');
    if(ele.contentDocument)
        ele.contentDocument.location.href = url;
    else
        ele.src = url;
    hideRadio();
    hideBlog();
    hideForum();
}

function resizeIF()
{
    if(pageLoaded.gbcss)
    {
        var wid = pageLoaded.oriWidth * (document.body.clientWidth / screen.width);
        pageLoaded.gbcss.style.width = pageLoaded.gbcss.style.minWidth = pageLoaded.gbcss.style.maxWidth = wid;
    }
}

function pageLoaded()
{
    window.onresize = function onresize(event) { resizeIF(event); };
    resizeIF();

/*
    var ele = document.getElementById('contIFrame');
    var defaultIndexPage = 'indexpage.php';
    if(ele.contentDocument)
        ele.contentDocument.location.href = (document.location.hash ? unescape(document.location.hash.substr(1)) : defaultIndexPage);
    else
        ele.src = (document.location.hash ? unescape(document.location.hash.substr(1)) : defaultIndexPage);
*/
    pageLoaded.loaded = true;

    var index;
    for(index = document.styleSheets.length - 1; index >= 0 ; --index)
    {
        if(document.styleSheets[index].href.search(/gaybar.css$/) != -1)
            break;
    }
    if(index != -1)
    {
        pageLoaded.gbcss = document.styleSheets[index];
        if(pageLoaded.gbcss.cssRules)
            pageLoaded.gbcss = pageLoaded.gbcss.cssRules;
        else if(pageLoaded.gbcss.rules)
            pageLoaded.gbcss = pageLoaded.gbcss.rules;
        else
        {
            pageLoaded.gbcss = null;
            return;
        }
        for(index = pageLoaded.gbcss.length - 1; index >= 0; --index)
        {
            if(pageLoaded.gbcss[index].selectorText == ".contBox")
                break;
        }
        if(index != -1)
        {
            pageLoaded.gbcss = pageLoaded.gbcss[index];
            pageLoaded.oriWidth = pageLoaded.gbcss.style.width.substr(0, pageLoaded.gbcss.style.width.length - 2);
        }
        else
            pageLoaded.gbcss = null;
    }
    else
        pageLoaded.gbcss = null;

    //pageLoaded.updInt = setInterval(updateLists, 300000);
    //document.getElementById('contIFrame').width = screen.availWidth;
}

function iFrefresh()
{
    var ele = document.getElementById('contIFrame');
    if(ele.contentWindow)
        ele.contentWindow.location.reload();
    else
        ele.window.location.reload();
}

function fixchat()
{
    var fme = document.getElementById('chatIFrame');
    var ele = getFirstChild(getNextSib(getFirstChild(fme.contentDocument.body)));
    for(var index = 0; index < 4; ++index)
    {
        ele.removeChild(getNextSib(ele));
    }
}

function getEventElement(e)
{
    var targ;
    if(!e)
        var e = window.event;
    if(e.target)
        targ = e.target;
    else if(e.srcElement)
        targ = e.srcElement;
    if(targ.nodeType == 3)
        targ = targ.parentNode;
    return targ;
}

// </script>

