/*
 * file: qwertyflash.js
 *
 * implements intercommunication between different flash movies
 *
 * Id: $Id$
 */

var swf_scroller;
var swf_menu;
var gtswf = new Object();

gtswf.swf = function(id) {
    this._id = id;
    if (document.getElementById) {
        this._swf = document.getElementById(id);
        if ((this._swf.localName == "OBJECT") || (this._swf.localName == "object")) {
            this._swf = this._swf.getElementsByTagName("embed")[0];
        }
    } else {
        this._swf = document[id];
    }
    if (typeof this._swf == 'undefined')
        return;
    gtswf.swf._clips[id] = this;
};

gtswf.swf._clips = new Object();

gtswf.flash_call = function() {
    var callee = gtswf.swf._clips[arguments[0]];
    if (callee != undefined) {
        if (typeof callee[arguments[1]] != "function")
            return;
        try {
            if (arguments.length > 2)
                callee[arguments[1]].apply(callee, arguments[2]);
            else
                callee[arguments[1]]();
        } catch (err) {
            // just ignore errors
            //alert([err.name, err.message]);
        }
    }
}


function onMenuItemSelected(itemid) {
    frames['main_placeholder'].location.href='/flasharticle.php?linkid='+itemid;
    onMenuItemSelected._state = (onMenuItemSelected._state != true);
    
    swf_scroller._swf.scroll_visible(false);
    Element.removeClassName('loading_mask','invisible');
}

function onLoadCompleted() {
    refreshScroll();
    Element.addClassName('loading_mask','invisible');
}

function refreshScroll() {
    if ((swf_scroller != undefined) && (typeof frames['main_placeholder'].$ == 'function')) {
        var mainn = frames['main_placeholder'].$('main');
        if (mainn) {
            if (mainn.scrollHeight != refreshScroll.oldHeight) {
                frames['main_placeholder'].$('main').scrollTop = 0;
                if (mainn.scrollHeight>370) {
                    var height = frames['main_placeholder'].Element.getHeight('main');
                    swf_scroller._swf.scroll_update(mainn.scrollHeight,370);
                    swf_scroller._swf.scroll_offset(0);
                    swf_scroller._swf.scroll_visible(true);
                }
                else {
                    swf_scroller._swf.scroll_visible(false);
                }
            }
            refreshScroll.oldHeight = mainn.scrollHeight;
        }
    }
}

function onLangSwitch(lang) {
    setTimeout(
        function() {
            if (swf_menu!=undefined) {
                swf_menu._swf.switch_to_lang(lang);
            }
        },
        50);
}

function onIntroLangSelected(lang) {
    setTimeout(
        function() {
            Element.removeClassName('main_placeholder','main_disabled_placeholder');
            Element.removeClassName('left_inner_pane','hidden');
            Element.removeClassName('right_inner_pane','hidden');
            Element.removeClassName('bottom_inner_pane','hidden');
            setTimeout(
                function() {
                    swf_menu._swf.switch_to_lang(lang);
                    $('intro_pane').remove();
                }, 200);
        },
        50);
}

function onIntroStarted() {
}

function onScrollbarChange(offset) {
//    frames['main_placeholder'].$('main').innerHTML = offset;
   if (typeof frames['main_placeholder'].$ == 'function') {
       frames['main_placeholder'].$('main').scrollTop = offset;
   }
}

document.observe("dom:loaded", function() {
    initSwfMenu();
    initSwfScroller();
    setInterval(refreshScroll,500);
});

function initSwfScroller() {
    if ($('scroll_swf')!=undefined) {
        swf_scroller = new gtswf.swf('scroll_swf');
    }
    else {
        setTimeout(initSwfScroller,100)
    }
}

function initSwfMenu() {
    if ($('scroll_swf')!=undefined) {
        swf_menu = new gtswf.swf('menu_swf');
    }
    else {
        setTimeout(initSwfMenu,120)
    }
}


