/* 
 * Needs Jquery!
 */

var counter, pageFrameID, webContainerID, flashWrapperID, flashContainerID, swfMinHeight, swfWidth, swfMenuWidth, pageUrl, swfMenuFoldoutWidth, pageOn, menuOpen, swfMinWidth;


function setFlashContainerID(Id) {
    flashContainerID = '#'+Id;
}

function setFlashWrapperID(Id) {
    flashWrapperID = '#'+Id;
}

function setWebContainerID(Id) {
    webContainerID = '#'+Id;
}

function setFrameID(Id) {
    pageFrameID = '#'+Id;
}


function alertSWF(message) {
    //alert(message);
}

function alertSwf(msg) {
   // alert(msg);
}

function setDefaultHeight(movieMinimalHeight) {
    swfMinHeight = movieMinimalHeight;
    swfMinWidth = '1000px';
    $(flashContainerID).css('min-height', swfMinHeight);
    $(flashContainerID).css('height', swfMinHeight);
    $(flashContainerID).css('min-width', swfMinWidth);
    $(pageFrame).css('min-height', swfMinHeight);
    $(pageFrame).css('height', swfMinHeight);
    init();
}

function removePage(movieWidth) {
    pageOn = false;
    swfWidth = movieWidth;
    $(flashWrapperID).css('width', '100%');
    $(flashContainerID).css('width', '100%');
    $(pageFrameID).css('visibility', 'hidden');
    $(flashContainerID).css('min-width', swfMinWidth);
}

function setMenuWidth(menuFoldoutWidth) {
    var x = $(flashWrapperID).scrollTop();
    scrollbar = false;
    if(pageOn == true) {

        if(menuFoldoutWidth == '0') {
            menuOpen = false;
            counter = 0;
        } else {
            menuOpen = true;
            scrollbar = true;
        }

        if(menuOpen) {
            //$(flashWrapperID).css('overflow-y', 'scroll');
            $(flashWrapperID).css('width', parseFloat(swfMenuWidth)+parseFloat(menuFoldoutWidth)+parseFloat(getScrollerWidth()));
        } else {
            $(flashWrapperID).css('width', parseFloat(swfMenuWidth)+parseFloat(getScrollerWidth()));
        }
        $(flashContainerID).css('width', parseFloat(swfMenuWidth)+parseFloat(menuFoldoutWidth));
    }
}

function showPage(menuWidth, url) {
    counter = 0;
    pageOn = true;
    swfMenuWidth = menuWidth;
    pageUrl = url;
    $(flashContainerID).css('min-width', '0px');
    loadIframe();
    changeDivWidth();
}

function loadIframe() {
    $(pageFrameID).attr('src', pageUrl);
    $(pageFrameID).css('visibility', 'visible');
}

function changeDivWidth() {
    $(flashWrapperID).css('width', parseFloat(swfMenuWidth)+parseFloat(getScrollerWidth()));
    $(flashContainerID).css('width', swfMenuWidth);
    if(getViewPortHeight() < swfMinHeight) {
        $(pageFrameID).css('left', parseFloat(swfMenuWidth)+parseFloat(getScrollerWidth()));
        $(pageFrameID).css('width', (parseFloat(getViewPortWidth())-parseFloat(swfMenuWidth)-parseFloat(getScrollerWidth()))+'px');
        $(pageFrameID).css('height', parseFloat(getViewPortHeight())+'px');
    } else {
        $(pageFrameID).css('left', parseFloat(swfMenuWidth));
        $(pageFrameID).css('width', (parseFloat(getViewPortWidth())-parseFloat(swfMenuWidth))+'px');
        $(pageFrameID).css('height', parseFloat(getViewPortHeight())+'px');
    }
}

function resizer() {
    if(pageOn == false) {
        if(getViewPortHeight() < swfMinHeight) {
            $(flashContainerID).css('height', swfMinHeight);
            $('#flashContent').css('height', swfMinHeight);
            $('#nn').css('height', swfMinHeight);
        } else {
            $(flashContainerID).css('height', getViewPortHeight());
            $('#flashContent').css('height', getViewPortHeight());
            $('#nn').css('height', getViewPortHeight());
        }
    } else {
       if(getViewPortHeight() < swfMinHeight) {
            $(pageFrameID).css('left', parseFloat(swfMenuWidth)+parseFloat(getScrollerWidth()));
            $(pageFrameID).css('width', (parseFloat(getViewPortWidth())-parseFloat(swfMenuWidth)-parseFloat(getScrollerWidth()))+'px');
        } else {
            $(pageFrameID).css('left', parseFloat(swfMenuWidth));
            $(pageFrameID).css('width', (parseFloat(getViewPortWidth())-parseFloat(swfMenuWidth))+'px');
        }
        $(pageFrameID).css('height', parseFloat(getViewPortHeight())+'px');
    }
}

function init() {
    if(getViewPortHeight() < swfMinHeight) {
        $(flashContainerID).css('height', swfMinHeight);
        $('#flashContent').css('height', swfMinHeight);
        $('#nn').css('height', swfMinHeight);
    } else {
        $(flashContainerID).css('height', getViewPortHeight());
        $('#flashContent').css('height', getViewPortHeight());
        $('#nn').css('height', getViewPortHeight());
    }
}
