

function strippx(strPX) {
    var Mylen = strPX.length;
    Mylen = Mylen - 2;
    strNew = strPX.substring(0, Mylen);
    return Number(strNew)
}


// ############################################# 
function hideslidebox() {
    statereset();
    hideit('GP1');
    hideit('GP2');
    stop_f();
    hideit('FlashPlayer');

    if (CurLayer == 'FlashPlayer') {
//        var MyFile = OFlash.url;
//        MyFile = MyFile.toLowerCase();
//        var i = MyFile.indexOf('www.');
//        if (i != -1) {
            kill_f();
//        }
    }
    stop_m();
    hideit('MediaPlayer');

    if (OGP1.type == 'YouTube') {
        document.getElementById('GP1').innerHTML = '';
        OGP1.loaded = false;
    }

    if (OGP2.type == 'YouTube') {
        document.getElementById('GP2').innerHTML = '';
        OGP2.loaded = false;
    }    
}

// ############ Listing Border NEEDS AN EARLY OUT ############
function change_listing_border() {
    // On the main sequence
    // Check all the listing div borders from 0 to urlary.length -1
    // (listing + num) is the IDs of the divs
    // Check if it's a Sub - make the border dashed

//.className='isDOM';
    if (ListOne) return;
    if (NoList) return;
    var i = 0;
    var MyDiv;
    for (i = 0; i <= urlary.length - 1; i++) {
        MyDiv = document.getElementById('listing' + i);
        if (i == MainSeqNum) {
            if (extrefary[MainSeqNum] != 'None') {
                MyDiv.className = 'list_image_sub';
            }
            else MyDiv.className = 'list_image_on';
        }
        else {
            MyDiv.className = 'list_image';
        }
    }
}

//############################################# 
function get_box_size() {
    if (UseMainSeq == true) {
        next_box_height = heightary[MainSeqNum] + slider_top + slider_btm;
        next_box_width = widthary[MainSeqNum];
    }
    if (UseMainSeq == false) {
        next_box_height = sub_heightary[SubSeqNum] + slider_top + slider_btm;
        next_box_width = sub_widthary[SubSeqNum];
    }

    if (NextType == 'Media') {
        next_box_height += 60;
    }
    if (next_box_width < slider_min_width) {
        next_box_width = slider_min_width;
    }
} 

//######### Forced clear of mext type
function force_clear_next_type() {
    // clears the next type  - Just clears loaded
    var cleared = false;
    var MyType = '';
    MyType = (UseMainSeq == true) ? typeary[MainSeqNum] : sub_typeary[SubSeqNum];
    switch (MyType){
        case 'Flash':
            OFlash.loaded = false;
            break;
        case 'Media':
            OMedia.loaded = false;
            break;
        default:
            if (CurLayer != 'GP1') {
                OGP1.loaded = false;
            }
            if (CurLayer != 'GP2') {
                OGP2.loaded = false;
            }
    }
    return;
}

//######### Pre Clear 
function pre_clear_next_type(){
    // clears the next type  - Just clears loaded
    var cleared = false;
    var MyType = '';
    MyType = (UseMainSeq == true) ? typeary[MainSeqNum] : sub_typeary[SubSeqNum];
    switch (MyType) {
        case 'Flash':
            // If it's a remote flash next return false - It won't preload 
            // Need the file name from the array in use
            var MyFile = (UseMainSeq == true) ? urlary[MainSeqNum] : sub_urlary[SubSeqNum];
            MyFile = MyFile.toLowerCase()
            var i = MyFile.indexOf('www.');
            if (i != -1) {
                // it's a remote flash - Just return
            }
            else if (CurLayer != 'FlashPlayer') {
                OFlash.loaded = false;
                cleared = true;
            }
            break;
        case 'Media':
            if (CurLayer != 'MediaPlayer') {
                OMedia.loaded = false;
                cleared = true;
            }
            break;
        default:
            if (CurLayer != 'GP1') {
                OGP1.loaded = false;
                cleared = true;
            }
            if (CurLayer != 'GP2') {
                OGP2.loaded = false;
                cleared = true;
            }
    }
    return cleared;
}

// ################# Transition #################
function transition() {
        OState.enddetecting = false;
        OState.enddetect = false;    
        if (CurLayer == 'MediaPlayer')  stop_m();
        if (CurLayer == 'FlashPlayer') stop_f();
        //if (CurLayer == 'FlashPlayer') stopit(CurLayer);


        // Shutoff end detect
    
    hideit(NextLayer);
    make_z(CurLayer, TopLayerZ - 1)
    make_z(NextLayer, TopLayerZ);
    position_slidebox();

    MyObj = get_object(NextLayer);
    var MyTransition = MyObj.transition;
    TransName = NextLayer;

    // if (CurLayer == 'MediaPlayer' || CurLayer == 'FlashPlayer') MyTransition = 'Cut';

    switch (MyTransition) {
    
        case 'Right':
            //Slide Next in from Right - Next top Right - big
            // Change left starts big at - tot_width
            //make_big(NextLayer)
            MyBox = document.getElementById(NextLayer);
            MyBox.style.left = MyBox.style.width;
            showit(NextLayer);
            slide_right();
            break;
        case 'Left':
            // slide in from left big clipped
            //make_big(NextLayer)
            MyBox = document.getElementById(NextLayer);
            MyBox.style.left = -strippx(MyBox.style.width) + 'px';
            showit(NextLayer);
            slide_left();
            break;
        case 'Top':
            //Top - Next top left - Wide - height = 0
            //make_big(NextLayer)
            MyBox = document.getElementById(NextLayer);
            MyBox.style.top = -tot_height + 'px';
            showit(NextLayer);
            slide_top();
            break;
        case 'Bottom':
            //Bottom - Next bottom left - Wide - height = 0
            //make_big(NextLayer)
            MyBox = document.getElementById(NextLayer);
            MyBox.style.top = tot_height + 'px';
            showit(NextLayer);
            slide_bottom();
            break;
        case 'Fade':
            //Bottom - Next bottom left - Wide - height = 0
            hideit(NextLayer);
            make_z(CurLayer, TopLayerZ);
            make_z(NextLayer, TopLayerZ - 1);
            //make_big(NextLayer)
            showit(NextLayer);
            TransName = CurLayer;
            fadeit();
            break;
        case 'Cut':
            showit(NextLayer);
            //make_big(NextLayer)
            make_z(NextLayer, TopLayerZ);
            hideit(CurLayer);
            make_z(CurLayer, 0);
            // position_slidebox()  // Cut box problem
            state_trans_dly();
            break;
    }
}

function slide_right() {// starts big clipped in fro9m right
    // TransName, Current, slides in from right - Change the width 
    // check OState.transrunning = false
    if (OState.transrunning = false) {
        state_trans_dly();
        return;
    }
    MyBox = document.getElementById(TransName);
    var MyLeft = strippx(MyBox.style.left);
    //if (MyLeft > 0) {
        MyLeft = MyLeft - movesize;
        if (MyLeft < 0) MyLeft = 0;
        MyBox.style.left = MyLeft + 'px';
    //}
    //All done?
    if (MyLeft > 0) {
        window.setTimeout("slide_right()", timeint);
    }
    else {
        state_trans_dly();
    }
}

function slide_left() {
    // Current slides in from the left width 
    // check OState.transrunning = false
    if (OState.transrunning = false) {
        state_trans_dly();
        return;
    }
    MyBox = document.getElementById(TransName);
    var MyLeft = strippx(MyBox.style.left);
    if (MyLeft < 0) {
        MyLeft = MyLeft + movesize;
        if (MyLeft > 0) MyLeft = 0;
        MyBox.style.left = MyLeft + 'px';
    }
    //All done?
    if (MyLeft < 0) {
        window.setTimeout("slide_left()", timeint);
    }
    else {
        state_trans_dly();
    }
}

function slide_top() {
    MyBox = document.getElementById(TransName)
    //Change the top to 0
    var MyTop = strippx(MyBox.style.top);
    if (MyTop < 0) {
        MyTop = MyTop + movesize;
        if (MyTop > 0) MyTop = 0
    }
    MyBox.style.top = MyTop + 'px';
    //All done?
    if (MyTop < 0) {
        window.setTimeout("slide_top()", timeint);
    }
    else {
        state_trans_dly();
    }
}

function slide_bottom() {
    MyBox = document.getElementById(TransName)
    //Change the top 
    var MyTop = strippx(MyBox.style.top);
    if (MyTop > 0) {
        MyTop = MyTop - movesize;
        if (MyTop < 0) MyTop = 0
        MyBox.style.top = MyTop + 'px';
   }
    //All done?
   if (MyTop > 0) {
        window.setTimeout("slide_bottom()", timeint);
    }
    else {
        state_trans_dly();
    }
}

function fadeit() {
    MyBox = document.getElementById(TransName);
    var dofade = false;
    if (ie) {
       if (MyBox.filters.alpha.opacity == 0) return;
       MyBox.filters.alpha.opacity = MyBox.filters.alpha.opacity - fadeamt;
        if (MyBox.filters.alpha.opacity <= 0) {
            state_trans_dly();
        }
        else {
            setTimeout('fadeit()', timeint);
        }
    }

    if (ns) {
        if (MyBox.style.MozOpacity == 0) return;
       MyBox.style.MozOpacity = MyBox.style.MozOpacity - (fadeamt / 100);
        if (MyBox.style.MozOpacity <= 0) {
            MyBox.style.MozOpacity = 0
            state_trans_dly();
        }
        else {
            setTimeout('fadeit()', timeint);
        } 
    }
}

function state_trans_dly() {
    setTimeout('state_trans_dly2()', timeint);
}

function state_trans_dly2(){
    state_ctl('transition');
}

function move_tl(MyDiv) {
    //set top=0, left=max, height=0, width=0,
    MyBox = document.getElementById(MyDiv);
    MyBox.style.top = 0 + 'px';
    MyBox.style.left = 0 + 'px';
    MyBox.style.height = 0 + 'px';
    MyBox.style.width = 0 + 'px';

}

function move_tr(MyDiv) {
    //set top=0, left=max, height=0, width=0,
    MyBox = document.getElementById(MyDiv);
    MyBox.style.top = 0 + 'px';
    MyBox.style.left = tot_width + 'px';
    MyBox.style.height = 0 + 'px';
    MyBox.style.width = 0 + 'px';
}

function move_bl(MyDiv) {
    MyBox = document.getElementById(MyDiv)
    MyBox.style.top = (tot_height) + 'px';
    MyBox.style.left = 0 + 'px';
    MyBox.style.height = 0 + 'px';
    MyBox.style.width = 0 + 'px';
}

function move_br(MyDiv) {
    MyBox = document.getElementById(MyDiv);
    MyBox.style.top = tot_height + 'px';
    MyBox.style.left = tot_width + 'px';
    MyBox.style.height = 0 + 'px';
    MyBox.style.width = 0 + 'px';
}

function make_big(MyDiv) {
    MyBox = document.getElementById(MyDiv);
    MyBox.style.top = 0 + 'px';
    MyBox.style.left = 0 + 'px';
    MyBox.style.height = tot_height + 'px';
    MyBox.style.width = tot_width + 'px';
}

function make_wide(MyDiv) {
    MyBox = document.getElementById(MyDiv);
    //MyBox.style.top = tot_height + 'px';
    //MyBox.style.left = tot_width + 'px';
    //MyBox.style.height = tot_height + 'px';
    MyBox.style.width = tot_width + 'px';
}

function make_tall(MyDiv) {
    MyBox = document.getElementById(MyDiv)
    //MyBox.style.top = tot_height + 'px';
    //MyBox.style.left = tot_width + 'px';
    MyBox.style.height = tot_height + 'px';
    //MyBox.style.width = tot_width + 'px';
}

function hideit(MyDiv) {
    MyBox = document.getElementById(MyDiv);
    MyBox.style.visibility = 'hidden';
}

function showit(MyDiv) {
    // don't forget opacity and expand it
    //var DivName = getdivname()
    MyBox = document.getElementById(MyDiv)
    MyBox.style.visibility = 'visible'
    if (ie) {
        MyBox.filters.alpha.opacity = 100
    }
    if (ns) {
        MyBox.style.MozOpacity = 1
    }
}

function make_z(MyDiv, zind) {
    var startZ = document.getElementById('SlideBox').style.zIndex;
    MyBox = document.getElementById(MyDiv);
    MyBox.style.zIndex = startZ + zind;
}




