
// ############################## Startup Listing ##############################
// ### Make a seperate file based on the template
function makelisting() { //Comes from onload
    // ###### Need to load_arrays(MyURL, GalID, MyDest) && load the the listing
    // Get the querystring and get the GalID and load the array
    //document.getElementById('slidebox').style.left = slider_left + 'px'

    if (MainGalID == '1') {
        MainGalID = getQuerystring2('GalID');
        if (MainGalID == '') MainGalID = '1';    
    }



    MainCatID = getQuerystring2('CatID');
    if (MainCatID == '') MainCatID = '1';
    
    //anylinkcssmenu.init("anchorclass")

    //var StyleSize = forms.form1.txtStyleSize.value;
    // change the styles for 

    load_url = 'parts/galleries/gallery' + MainGalID + '/ctl.xml';
    //MyURL = 'parts/galleries/gallery' + MyGalID + '/cd_catalog.xml';

    if (load_url == '') return;
    CurLayer = 'GP1';
    // Make GP1 w = 0, h = 0
//    hideit('GP1');

    load_main = true;
    load_arrays(); // calls load listing then preload
}

// TESTING  #####################
function get_gallery() {
    var MyLocation = document.location.href;
    // get the gallery from txtDetect
    MainGalID = document.form1.txtDetect.value;
    MyLocation += '?GalID=' + MyGalID;
    document.location.href = MyLocation;
}

// ##################### Get a Heading for the slideshow #####################
function get_head(GID, Item) {
    // Passed the galleryID and SeqNum
    // Return the text
    var tempA = document.getElementById('slideheads' + GID).innerHTML;
    //use /n to split the string the text between the Item number of /n and the next /n
    var tempB = tempA.split('<BR>');
    var tempC = tempB[Item + 1];
    if (tempC == undefined) {
        var tempB = tempA.split('<br>');
        var tempC = tempB[Item + 1];
    }
    return tempC;
}

function load_banner() {
    // div id banner.

}


// ##################### Load One Listing #####################
function load_list_one() {
    // The main array is loaded
    // Just one listing - If it's a gallery load it. If it's an item, just load the item
    // var ListOne = false;
    //var NoSlideHead = false;
    //var NoSlideBtm = false;
    // MainCatID
    // if div id="ItemID" = 0 it's a gallery
    //var imgtot = urlary.length - 1 //3 // starts at 0

    var i = 0;
    var p = 0;
    if (document.getElementById('ItemID').innerHTML != '0') {

        while (i <= urlary.length - 1 && p == 0) {
            if (catidary[i] == MainCatID) {
                p = i;
                CatListAryItem = i;
                CatListItem = true;
            }
            //strTemp += inner_listing(p);
            i++;
        }
    }

    // set MainItemID to the Div ID Used for displaying the next back buttons The whole bottom
    // Set NoSlideBtm = True
    // Go through the list and find the CatalogID
    
    
    var strTemp = inner_listing(p);
    document.getElementById('Listing').innerHTML = strTemp;
}

// ##################### Load Listing #####################
function load_listing() {
    //var imgpath = rootpath + 'thumb/'
    imgtot = urlary.length - 1 //3 // starts at 0
    imgwidth = 100;
    imgheight = 80;
    imghspace = 0;
    imgvspace = 0;
    imgcols = 0; // starts at 0
    cellwidth = 110;
    var strTemp = ''
    //cellheight = 85;
    p = 0;
    
    //strTemp = '&nbsp;<img src="parts/galleries/buttons/ClickImage.gif" border=0 /><br clear="left">';
    strTemp += make_btn('Click Image', '') + '<br clear="left"/>';
    
    while (p <= imgtot) {
        strTemp += inner_listing(p);
        p++;
    }

    document.getElementById('Listing').innerHTML = strTemp;

    strGPS = '';
    
    if (GalLat == '0' && GalLng == '0') {
        //strTemp = '<img alt="GPS" align="left" src="parts/galleries/buttons/GPS_space.gif" border="0" />'
    }
    else {
        //strTemp = '<a target="_blank" href="http://maps.google.com/?ie=UTF8&ll=' + GalLat + ',' + GalLng + '&spn=0.038696,0.053043&t=h&z=14"><img alt="GPS" align="left" src="parts/stock/buttons/16H/O1_S_GPS.gif" border="0" /></a>';

        strGPS += make_btn('GPS', '<a target="_blank" href="http://maps.google.com/?ie=UTF8&ll=' + GalLat + ',' + GalLng + '&z=14">');

        //strTemp = '<a target="_blank" href="http://maps.google.com/?ie=UTF8&ll=' + GalLat + ',' + GalLng + '&z=14"><img alt="GPS" align="left" src="parts/galleries/buttons/GPS.gif" border="0" /></a>';
//        strTemp = '<a target="_blank" href="http://maps.google.com/?ie=UTF8&ll=' + GalLat + ',' + GalLng + '&z=14"><img alt="GPS" align="left" src="parts/galleries/buttons/GPS.gif" border="0" /></a>';
    
    
    }

    document.getElementById('GPS_btn').innerHTML = strGPS;
    document.getElementById('galry_head').innerHTML = GalTitle;
    document.getElementById('galry_desc').innerHTML = GalDescription;



}

function inner_listing(p) {
    var strTemp = ''

    strTemp += '<div id="listing' + p + '" class="list_image">';
    strTemp += '<a href="javascript:mouse_click_thumb(' + p + ')"> <img align="center" border="0" width="' + thumb_width + '" height="' + thumb_height + '" src="' + thumbary[p] + '" /></a>';
    //strTemp =+ '<img border="0" src="parts/galleries/gallery30/thumb/P9170183.jpg" hspace="0" vspace="0" width="100" height="75" />';
    strTemp += '</div>';
    strTemp += '<div class="list_head">';
    // id="list_item_head"
    // if there is a catalog catidary[i]
    if (catidary[p] != 0) {
        strTemp += '<div style="float:right;">';
        if (ListOne == false) {
            strTemp += make_btn('Details', '<a href="javascript:details_btn(' + catidary[p] + ')">');
        }
        if (NoCartBtn == false) strTemp += make_btn('Add To Cart', '<a href="Checkout.aspx?CatID=' + catidary[p] + '">');
        
        strTemp += '</div>';

        //            strTemp += '<a target="_blank" href="Checkout.aspx?CatID=' + catidary[p] + '"><img src="parts/galleries/buttons/AddToCart.gif" align="right" border=0 /></a>';
        //            strTemp += '<a href="javascript:details_btn(' + catidary[p] + ')"><img src="parts/galleries/buttons/Details.gif" align="right" border=0 /></a>';

    }
    // if there it is a sub
    if (extrefary[p] != 'None') {
        strTemp += '<div style="float:right;">';
        if (NoOpenBtn == false) strTemp += make_btn('Open', '<a href="javascript:open_btn(' + intrefary[p] + ')">');
       
        
        //strTemp += make_btn('Open', '<a href="javascript:open_btn()">');
        strTemp += '</div>';

        //strTemp += '<a href="javascript:open_btn()"><img src="parts/galleries/buttons/Open.gif" align="right" border=0 /></a>';
    }
   // id = "list_item_head"' <div id = "list_item_head" style="float:left;">' +   + '</fiv>'
    strTemp +=  titleary[p];
    strTemp += '</div>';
    if (document.getElementById("list_item_head")) document.getElementById("list_item_head").innerHTML = titleary[p];
    strTemp += '<div class="list_text">';

    if (priceary[p] != null) {
        strTemp += '<div class="list_price">';
        strTemp += 'Price: $' + priceary[p];
        strTemp += '</div>';
    }

    strTemp += txtary[p];

    strTemp += '</div>';
    strTemp += '<br clear="left" /><div class="list_divider"></div>';

    return strTemp
}

// ##################################################
// ##################### Load Layer #####################
// ##################################################

function load_layer(MyName) {
    //get the selected object to load and losd from the object
    // ####### Make 3 different load functions that are called by the sequencer for the 3 types
    //MyName = getdivname()
    MyDiv = document.getElementById(MyName);
    //var seqID = document.form1.FormSeqNum.value
    //MyBox = document.getElementById(DivName)
    MyObject = get_object(MyName);
    var top_text = ''

    if (NoSlideHead == false) {
        if (UseMainSeq == true) {
            top_text = '<div class="slider_title">' + get_head(MainGalID, MainSeqNum) + '</div>';
        }
        else {
            var MyGalID = intrefary[MainSeqNum];
            top_text = '<div class="slider_title">' + get_head(MyGalID, SubSeqNum) + '</div>';
        }
    }

    var btm_text = ''
    //btm_text += '<p/>';
    //btm_text += '<br clear="left"/>';
    
    //btm_text += '<div><div>'
    btm_text += '<div class="slider_btm" style="float: left;">';

    if(NoList == false) btm_text += make_btn('Hide Me', '<a href="javascript:hideslidebox()">');
    
    //  ###### start of sequence controls
        MyObject = get_object(NextLayer);
    if (ListOneItem == false) { 
        btm_text += make_btn('Back', '<a href="javascript:back_btn()">');
        btm_text += make_btn('Next', '<a href="javascript:next_btn()">');

        btm_text += '<div style="float:left">'
            if (OState.auto_play == true) {
                btm_text += '<a href="javascript:make_auto()"><img id="btn_auto_play_' + MyName + '" src="parts/galleries/buttons/AutoStop.gif" border="0" /></a>';
            }
            else {
                btm_text += '<a href="javascript:make_auto()"><img id="btn_auto_play_' + MyName + '" src="parts/galleries/buttons/AutoPlay.gif" border="0" /></a>';
            }
        btm_text += '</div>'

    // Counter and Open Button
        if (extrefary[MainSeqNum] != 'None') {
            if (NoPageCount == false) { 
                if (SubSeqNum != 0) {
                    btm_text += '<div style="float:left">'
                    btm_text += '&nbsp;' + (SubSeqNum + 1);
                    // The length is the previous sub length
                    //if (UseMainSeq == false) {
                    btm_text += ' of ' + (sub_urlary.length);
                    btm_text += '&nbsp;</div>'
                }
                else {
                    btm_text += '<div style="float:left">'
                        btm_text += '&nbsp;' + (SubSeqNum + 1);
                    btm_text += '&nbsp;</div>'
                }
            }
            //strTemp += make_btn('Details', '<a href="javascript:details_btn(' + MyObject.catalogid + ')">');

            //MyObject.catalogid

            //if (NoOpenBtn == false) strTemp += make_btn('Open', '<a href="javascript:open_btn(' + intrefary[p] + ')">');

            if (NoOpenBtn == false) btm_text += make_btn('Open', '<a href="javascript:open_btn(' + intrefary[MainSeqNum] + ')">');
        }
        // End of sequence controls
    }
        
    if (MyObject.catalogid != 0) {
        
        // Add to Cart and Details
        btm_text += '<div style="float: right;">'; // width=120px background-color: #FFFFFF;

        if (ListOne == false) {
            btm_text += make_btn('Details', '<a href="javascript:details_btn(' + MyObject.catalogid + ')">');
        }
        //btm_text += make_btn('Details', '<a href="javascript:details_btn(' + MyObject.catalogid + ')">');
        //btm_text += make_btn('Details', '<a href="javascript:details_btn(' + MyObject.catalogid + ')">');
        
        if (NoCartBtn == false) btm_text += make_btn('Add To Cart', '<a target="_blank" href="Checkout.aspx?CatID=' + MyObject.catalogid + '">');

        //btm_text += make_btn('Add To Cart', '<a target="_blank" href="Checkout.aspx?CatID=' + MyObject.catalogid + '">');
        btm_text += '</div>';
    }
    
    btm_text += '</div>';

    // if the next type is YouTube make the string
    // <object width="480" height="385"><param name="movie" value="

    NextType = (UseMainSeq == true) ? typeary[MainSeqNum] : sub_typeary[SubSeqNum];
    if(NextType == 'YouTube'){

     }
    
    switch (MyName) {
        case 'GP1':
            if (OGP1.type == 'Image') {
                var textmaker = '<img alt="" src="' + OGP1.url + '" width=' + OGP1.width + ' height=' + OGP1.height + ' />';
                MyDiv.innerHTML = top_text + textmaker + btm_text;
            }
            if (OGP1.type == 'Code') {
                textmaker = '<iframe src="' + OGP1.url + '" width=' + OGP1.width + 'px height=' + OGP1.height + 'px frameborder=0 scrolling=no style="background-color: #FFFFFF"></iframe>';
                MyDiv.innerHTML = top_text + textmaker + btm_text;
            }
            if (OGP1.type == 'YouTube') {
                var strYouTube = '<div>';
                strYouTube += '<object width="' + OGP1.width + '" height="' + OGP1.height + '">';
                strYouTube += '<param name="movie" value="http://www.youtube.com/v/' + OGP1.url + '&amp;hl=en_US&amp;fs=1"></param>';
                strYouTube += '<param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param>';
                strYouTube += '<embed src="http://www.youtube.com/v/' + OGP1.url + '&amp;hl=en_US&amp;fs=1" type="application/x-shockwave-flash"';
                strYouTube += ' allowscriptaccess="always" allowfullscreen="true"';
                strYouTube += ' width="' + OGP1.width + '" height="' + OGP1.height + '"></embed></object>';
                strYouTube += '</div>';
                MyDiv.innerHTML = top_text + strYouTube + btm_text;            
            }
            break;

        // <object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/R-eISboAPOc&amp;hl=en_US&amp;fs=1"></param>
        // <param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param>
        //<embed src="http://www.youtube.com/v/R-eISboAPOc&amp;hl=en_US&amp;fs=1" type="application/x-shockwave-flash" 
        // allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object>

        case 'GP2':
            if (OGP2.type == 'Image') {
                var textmaker = '<img alt="" src="' + OGP2.url + '" width=' + OGP2.width + ' height=' + OGP2.height + ' />'
                MyDiv.innerHTML = top_text + textmaker + btm_text;
            }
            if (OGP2.type == 'Code') {
                var textmaker = '<iframe src="' + OGP2.url + '" width=' + OGP2.width + 'px height=' + OGP2.height + 'px frameborder=0 scrolling=no style="background-color: #FFFFFF"></iframe>';
                MyDiv.innerHTML = top_text + textmaker + btm_text;
            }
            if (OGP2.type == 'YouTube') {
                var strYouTube = '<div>';
                strYouTube += '<object width="' + OGP2.width + '" height="' + OGP2.height + '">';
                strYouTube += '<param name="movie" value="http://www.youtube.com/v/' + OGP2.url + '&amp;hl=en_US&amp;fs=1"></param>';
                strYouTube += '<param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param>';
                strYouTube += '<embed src="http://www.youtube.com/v/' + OGP2.url + '&amp;hl=en_US&amp;fs=1" type="application/x-shockwave-flash"';
                strYouTube += ' allowscriptaccess="always" allowfullscreen="true"';
                strYouTube += ' width="' + OGP2.width + '" height="' + OGP2.height + '"></embed></object>';
                strYouTube += '</div>';
                MyDiv.innerHTML = top_text + strYouTube + btm_text;            

                //MyDiv.innerHTML = strYouTube + btm_text;
                //var strYouTube = '<object width="' + OGP2.width + '" height="' + OGP2.height + '"><param name="movie" value=http://www.youtube.com/v/"' + OGP2.url  // 
                //strYouTube += '&hl=en_US&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param>'
                //strYouTube += '<embed src="http://www.youtube.com/v/' + OGP2.url + '&hl=en_US&fs=1&"' + ' type="application/x-shockwave-flash"'
                //strYouTube += ' allowscriptaccess="always" allowfullscreen="true" '
                //strYouTube += 'width="' + OGP2.width + '" height="' + OGP2.height + '"></embed></object>'


            }
            break;
            


        case 'MediaPlayer':

            if (ie == true) {

                MyPlayer = document.getElementById('MediaPlayer1');
                MyPlayer.URL = OMedia.url;
                MyPlayer.width = OMedia.width;

                MyPlayer.height = OMedia.height + 60; //
                
//                if (OMedia.nomc == 'false') {
//                    MyPlayer.height = OMedia.height + 60; //
//                    MyPlayer.uiMode = "full"
//                }
//                else {
//                    MyPlayer.height = OMedia.height; //
//                    MyPlayer.uiMode = "none"
//                }


                //MyPlayer.AutoSize = true;
                MyPlayer.stretchToFit = true;

                // Load the top and bottom divs media_top media_btm

                if (NoSlideHead == false) document.getElementById('media_top').innerHTML = top_text;
                if (NoSlideBtm == false) document.getElementById('media_btm').innerHTML = btm_text;
            }

            if (ns == true) {
                MyLayer = document.getElementById('MediaPlayer');
                Myhight = OMedia.height + 60
//                if (OMedia.nomc == false) {
//                    Myhight = OMedia.height + 60; //
//                }
//                else {
//                    Myhight = OMedia.height; //
//                }
                var textstr = ''
                MyLayer.innerHTML = textstr
                if (NoSlideHead == false) textstr += top_text
                textstr += '<object width="' + OMedia.width + '" height="' + Myhight + '" '
                textstr += ' id="MediaPlayer1"'
                textstr += ' type="application/x-mplayer2">'
                textstr += ' <param name="fileName" value="' + OMedia.url + '">'
                textstr += ' <param name="autostart" value="0">'
                textstr += ' <param name="ShowStatusBar" value="0">'
                textstr += ' <param name="volume" value="0">'
                //textstr += ' <param name="AutoSize" value="1">'
                textstr += ' <param name="stretchToFit" value="true">'

                textstr += ' </object>'
                if (NoSlideBtm == false) textstr += btm_text
                MyLayer.innerHTML = textstr
            }

            MyPlayer = document.getElementById('MediaPlayer1');
            MyPlayer.stretchToFit = true;

//            if (OMedia.nomc == 'false') {
//                MyPlayer.uiMode = "full"
//            }
//            else {
//                MyPlayer.uiMode = "none"
//            }



            break;


        case 'FlashPlayer':
            //MyPlayer = document.getElementById('FlashPlayer1');
            MyPlayer = swfobject.getObjectById('FlashPlayer1')

            MyPlayer.LoadMovie(0, OFlash.url);
            MyPlayer.width = OFlash.width;
            MyPlayer.height = OFlash.height;

            // Load the top and bottom divs media_top media_btm
            //NoSlideHead = true;
            //NoSlideBtm = true;   
            if (NoSlideHead == false) document.getElementById('flash_top').innerHTML = top_text;
            if (NoSlideBtm ==  false) document.getElementById('flash_btm').innerHTML = btm_text;

            break;
    }
}

// #################### Transition cleanup ####################
function transition_cleanup() {
    hideit(CurLayer);
    make_z(CurLayer, 0);

    // BACK TO BACK PROBLEM
    if (CurLayer == 'MediaPlayer' && NextLayer != 'MediaPlayer') stop_m();
    //if (CurLayer == 'MediaPlayer') stopit(CurLayer);
    if (CurLayer == 'FlashPlayer' && NextLayer != 'FlashPlayer') {

        //stop_f(); 
        kill_f();  // it won't transparent on some browsers
    }
    //if (CurLayer == 'FlashPlayer' && NextLayer != 'FlashPlayer') stopit(CurLayer);


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

    if (CurLayer == 'GP2' && OGP2.type == 'YouTube') {
        document.getElementById('GP2').innerHTML = '';
        OGP2.loaded = false;
    }    
    
    // #################### Next Loaded false - preload 
    // If it wasn't loaded - Check it's object that the current layer has been loaded
    MyObject = get_object(NextLayer);
    
    if (MyObject.loaded == false) {
        preloadnext();
    }

    // Start next player
    if (NextLayer == 'MediaPlayer') play_m();
    //if (NextLayer == 'MediaPlayer') playit(NextLayer);
    if (NextLayer == 'FlashPlayer') play_f();
    //if (NextLayer == 'FlashPlayer') playit(NextLayer);

    make_z(NextLayer, TopLayerZ);
    showit(NextLayer);

    // CatalogID
    if (MyObject.catalogid != 0) {
        if(document.form1.txtCatID) document.form1.txtCatID.value = (UseMainSeq == true) ? catidary[MainSeqNum] : sub_catidary[SubSeqNum];
    }
    else document.form1.txtCatID.value = 0;
}


// ############### Pre Load ###############
function preloadnexttimer() {
    //Small time before preload
    PreLoadTimer = setTimeout('preloadnext()', 100);
}
function preloadnext() {
    OSeqNum = NextSeqNum; // point the object to the to the loading layer Sequence Number to load the object 
    NextType = (UseMainSeq == true) ? typeary[MainSeqNum] : sub_typeary[SubSeqNum];
    NextLayer = '';

    switch (NextType) {
        case 'Media':
            NextLayer = 'MediaPlayer';
            //don't load if loaded 
            if (OMedia.loaded == false) {
                OMedia.fillobj()
                load_layer('MediaPlayer');
                NextLayer = 'MediaPlayer';
                OState.preload = true  // 
                //start the play pause sequence for the media player
                OState.detectrunning = true;
                startpause_m();
                //mediapauseinit() 
            }
            break;

        case 'Flash':
            NextLayer = 'FlashPlayer';
            if (OFlash.loaded == false) {
                OFlash.fillobj();
                load_layer('FlashPlayer');
                NextLayer = 'FlashPlayer'
                OState.preload = true;  //
                //stopit(NextLayer);
                //start the play pause sequence for the flash player
                OState.detectrunning = true;
                startpause_f();
                //flashpauseinit();
            }
            break;

        default:
            // load the first not loaded GP
            // If both are loaded clear the one that's not curent

            if (OGP1.loaded == true && OGP2.loaded == true) {
                if (CurLayer == 'GP1') {
                    OGP2.loaded = false
                }
                else {
                    OGP1.loaded = false
                }
               
            }

            if (OGP1.loaded == false) {
                OGP1.fillobj();
                load_layer('GP1');
                NextLayer = 'GP1';
                OState.preload = true  //
                break;
            }
            if (OGP2.loaded == false) {
                OGP2.fillobj();
                load_layer('GP2');
                NextLayer = 'GP2';
                OState.preload = true  //
                break;
            }
    }

    try {
        get_box_size()
        MyNextLayer = document.getElementById(NextLayer)
        MyNextLayer.style.width = next_box_width + 'px';
        MyNextLayer.style.height = next_box_height + 'px';
    }
    catch (e) {
    }
}

// ############ Check Loaded ############
function check_loaded() {
    // Checks the Layer Objects if the layer is loaded from MainSeqNum and SubSeqNum in
    // Sets Next_Layer
    OState.load_check = false;
    if (OGP1.main_seq == MainSeqNum && OGP1.sub_seq == SubSeqNum && OGP1.loaded == true) {
        NextLayer = 'GP1'
        OState.load_check = true;
        return;
    }
    if (OGP2.main_seq == MainSeqNum && OGP2.sub_seq == SubSeqNum && OGP2.loaded == true) {
        NextLayer = 'GP2'
        OState.load_check = true;
        return;
    }
    if (OFlash.main_seq == MainSeqNum && OFlash.sub_seq == SubSeqNum && OFlash.loaded == true) {
        NextLayer = 'FlashPlayer'
        OState.load_check = true;
        return;
    }
    if (OMedia.main_seq == MainSeqNum && OMedia.sub_seq == SubSeqNum && OMedia.loaded == true) {
        NextLayer = 'MediaPlayer'
        OState.load_check = true;
        return;
    } 
}

//// ############ Load Arrays ############

// #### What if there isn't one ####
// #### Default en

function load_arrays() {

    if (window.XMLHttpRequest) {
        xhttp = new XMLHttpRequest();
    }
    else // Internet Explorer 5/6
    {
        xhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xhttp.open("GET", load_url, true);  //Async = true
    //xhttp.open("GET", MyURL, false);  //Async = true
    xhttp.send("");

    OState.load_ctl_counter = 0
    
    load_arrays2();

}


function load_arrays2(){
    OState.load_ctl_counter++;
    if (OState.load_ctl_counter == 100) {
        
        //return;

        // it must be a sub but making the new MainGalID requires crakig the string for the sub ctl-en.xml
        // load_url  
        //
        //extrefary[i] = 'None'
        GalCur = false
        xhttp.send(null);
        state_ctl('advance_ctr');
        
        // else // its en - shut it down clear the main array extrefary[i] to 'None'
        // clear galcur ...
    }

    //if (xhttp.readyState != 4 || xhttp.readyState != 200) { // Check status 200 //    if (this.readyState == 4 && this.status == 200) {
    if (xhttp.readyState != 4 || xhttp.status != 200) { // Check status 200 //    if (this.readyState == 4 && this.status == 200) {
        CtlLoadTimer = setTimeout("load_arrays2()", 100); // Try again
        // alert(xmlhttp.responseText)
        return;
    }

    //  ######## Check if it's loaded
    // Check its status every 100 ms with counter to 100
    // OState.load_ctl_counter
    // Onreadystate.change NO check it with timer

    // #######################################################################################################
    // ######################## Get the first node and see if it's there Name Nusdt be there #################
    
    xmlDoc = xhttp.responseXML;

    var x = xmlDoc.getElementsByTagName("Table");
    var tempData = '';
    if (load_main == true) {

        GalName = xmlDoc.getElementsByTagName("Name")[0].childNodes[0].nodeValue;
        GalTitle = xmlDoc.getElementsByTagName("Heading")[0].childNodes[0].nodeValue;
        GalDescription = xmlDoc.getElementsByTagName("Description")[0].childNodes[0].nodeValue;
        GalLat = xmlDoc.getElementsByTagName("Latitude")[0].childNodes[0].nodeValue;
        GalLng = xmlDoc.getElementsByTagName("Longitude")[0].childNodes[0].nodeValue;
        
        for (i = 0; i < x.length; i++) {

            imgidary[i] = x[i].getElementsByTagName("ImageID")[0].childNodes[0].nodeValue;
            urlary[i] = x[i].getElementsByTagName("FileName")[0].childNodes[0].nodeValue;
            thumbary[i] = x[i].getElementsByTagName("ThumbName")[0].childNodes[0].nodeValue;
            typeary[i] = x[i].getElementsByTagName("FileType")[0].childNodes[0].nodeValue;
            nomcary[i] = x[i].getElementsByTagName("NoMC")[0].childNodes[0].nodeValue;
            transary[i] = x[i].getElementsByTagName("Transition")[0].childNodes[0].nodeValue;
            widthary[i] = parseInt(x[i].getElementsByTagName("width")[0].childNodes[0].nodeValue);
            heightary[i] = parseInt(x[i].getElementsByTagName("height")[0].childNodes[0].nodeValue);
            titleary[i] = x[i].getElementsByTagName("ImgTitle")[0].childNodes[0].nodeValue;
            txtary[i] = x[i].getElementsByTagName("ImgText")[0].childNodes[0].nodeValue;
            durary[i] = parseInt(x[i].getElementsByTagName("Duration")[0].childNodes[0].nodeValue);
            linkary[i] = x[i].getElementsByTagName("ImgLink")[0].childNodes[0].nodeValue;
            extrefary[i] = x[i].getElementsByTagName("ExtRef")[0].childNodes[0].nodeValue;
            intrefary[i] = parseInt(x[i].getElementsByTagName("IntRef")[0].childNodes[0].nodeValue);
            //InCatalog
            CatData = x[i].getElementsByTagName("InCatalog")[0].childNodes[0].nodeValue;
            if (CatData == "true") {
                catidary[i] = parseInt(x[i].getElementsByTagName("CatalogID")[0].childNodes[0].nodeValue);
                priceary[i] = x[i].getElementsByTagName("Price")[0].childNodes[0].nodeValue;
            }
            else catidary[i] = 0;
        }
    }
    else {
        // clear the sub
        sub_urlary.length = 0
        
        for (i = 0; i < x.length; i++) {
            sub_imgidary[i] = x[i].getElementsByTagName("ImageID")[0].childNodes[0].nodeValue;
            sub_urlary[i] = x[i].getElementsByTagName("FileName")[0].childNodes[0].nodeValue;
            sub_thumbary[i] = x[i].getElementsByTagName("ThumbName")[0].childNodes[0].nodeValue;
            sub_typeary[i] = x[i].getElementsByTagName("FileType")[0].childNodes[0].nodeValue;
            sub_nomcary[i] = x[i].getElementsByTagName("NoMC")[0].childNodes[0].nodeValue;
            sub_transary[i] = x[i].getElementsByTagName("Transition")[0].childNodes[0].nodeValue;
            sub_widthary[i] = parseInt(x[i].getElementsByTagName("width")[0].childNodes[0].nodeValue);
            sub_heightary[i] = parseInt(x[i].getElementsByTagName("height")[0].childNodes[0].nodeValue);
            sub_titleary[i] = x[i].getElementsByTagName("ImgTitle")[0].childNodes[0].nodeValue;
            sub_txtary[i] = x[i].getElementsByTagName("ImgText")[0].childNodes[0].nodeValue;
            sub_durary[i] = parseInt(x[i].getElementsByTagName("Duration")[0].childNodes[0].nodeValue);
            sub_linkary[i] = x[i].getElementsByTagName("ImgLink")[0].childNodes[0].nodeValue;
            sub_extrefary[i] = x[i].getElementsByTagName("ExtRef")[0].childNodes[0].nodeValue;
            sub_intrefary[i] = x[i].getElementsByTagName("IntRef")[0].childNodes[0].nodeValue;
            //InCatalog
            tempData = x[i].getElementsByTagName("InCatalog")[0].childNodes[0].nodeValue;
            if (tempData == "true") {
                sub_catidary[i] = parseInt(x[i].getElementsByTagName("CatalogID")[0].childNodes[0].nodeValue);
                //sub_priceary[i] = x[i].getElementsByTagName("Price")[0].childNodes[0].nodeValue;
            }
            else sub_catidary[i] = 0;
        }
    }

    // NoList
    // ListOne
    if (load_main && ListOne != true && NoList== false) {
        load_listing();

    }
    else {
        if (ListOne == true && NoList == false) {
            load_list_one();
            make_total(); // It's a catalog or checkout
        }
    }

    // If the load_main The page was just loaded
    // Get the first image up Now.
    //

    state_ctl('advance_ctr');  // Preloads next 


    // 
//    if (NoList) {
//        preloadnext();
//        transition();
//    }
//    else{
//        state_ctl('advance_ctr');  // Preloads next 
//    }
    load_main = false;

}

// ##################### Load Media Player #####################
function load_media_player() {
    if (ie) {
        document.write('<object  width="320" height="305"');
        document.write(' id="MediaPlayer1"');
        document.write(' type="application/x-oleobject"');
        document.write(' classid="CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6"');
        document.write(' codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715"');
        document.write(' standby="Loading Microsoft Windows Media Player components...">');
        document.write(' <param name="url" value="parts/stock/mediaplayer/small.wmv">');
        document.write(' <param name="autostart" value="true">');
        document.write(' <param name="ShowStatusBar" value="false">');  //
        document.write(' <param name="AutoSize" value="true">');
        document.write(' <param name="loop" value="false">');
        document.write(' </object>');
    }
    if (ns) {
        document.write('<object width="320" height="305" ');
        document.write(' id="MediaPlayer1"');
        document.write(' type="application/x-mplayer2">');
        document.write(' <param name="fileName" value="parts/stock/mediaplayer/small.wmv">');
        document.write(' <param name="autostart" value="1">');
        document.write(' <param name="ShowStatusBar" value="0">');
        document.write(' <param name="volume" value="0">');
        document.write(' <param name="AutoSize" value="true">');
        document.write(' </object>');
    }
}

// ##################### Load Flash Player #####################
function load_flash_player() {
    //http://kb2.adobe.com/cps/127/tn_12701.html
    if (ie) {
        document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"');
        document.write(' id="FlashPlayer1"');
        document.write(' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"');
        document.write(' width="320" height="240">');
        document.write(' <param name="movie" value="Test/medium/StarA.swf" />');
        document.write(' <param name="quality" value="high" />');
        //document.write(' <param name="bgcolor" value='#FFFFFF' />');
        document.write(' <param name="loop" value="false" />');
        document.write(' <param name="play" value="false" />');
        document.write(' <param name="vmode" value="transparent" />');
        document.write(' </object>');
        document.write(' ');
    }

    if (ns) {
        document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"');
        //document.write(' id="FlashPlayer1"');
        document.write(' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"');
        //document.write(' width="320" height="240">');
        document.write(' <param name="Test/medium/StarA.swf" />');
        //document.write(' <param name="quality" value="high" />');
        //document.write(' <param name="bgcolor" value='#FFFFFF' />');
        //document.write(' <param name="loop" value="true" />');
        document.write(' <param name="play" value="false" />');
        document.write(' <param name="vmode" value="transparent" />');
        document.write(' <embed');
        document.write(' id="FlashPlayer1"');
        document.write(' width="320" height="240"');
        document.write(' name="FlashPlayer1"');
        document.write(' src="Test/medium/StarA.swf"');
        document.write(' quality="high"');
        //document.write(' bgcolor="#FFFFFF"')
        document.write(' loop="false"');
        document.write(' play="false"');
        //document.write(' vmode="transparent"');
        document.write(' >')
        document.write('</embed> ');
        document.write(' </object>');
    }

}


//    if (window.DOMParser) {
//        parser = new DOMParser();
//        xmlDoc = parser.parseFromString(text, "text/xml");
//    }
//    else // Internet Explorer
//    {
//        xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
//        xmlDoc.async = "false";
//        xmlDoc.loadXML(text);
//    }




//    GalName = xmlDoc.getElementsByTagName("galary")[0].childNodes[0].nodeValue;
//    GalTitle = xmlDoc.getElementsByTagName("Title")[0].childNodes[0].nodeValue;
//    GalDescription = xmlDoc.getElementsByTagName("Description")[0].childNodes[0].nodeValue;
//    GalLat = xmlDoc.getElementsByTagName("Lat")[0].childNodes[0].nodeValue;
//    GalLng = xmlDoc.getElementsByTagName("Lng")[0].childNodes[0].nodeValue;
//    
    
    
    
    
    //document.getElementById("from").innerHTML = xmlDoc.getElementsByTagName("from")[0].childNodes[0].nodeValue;
    
    
    //document.getElementById("message").innerHTML = xmlDoc.getElementsByTagName("body")[0].childNodes[0].nodeValue;





//function load_arrays(MyURL, GalID, MyDest) {
//    load_ary_dest = MyDest;
//    loadOuter(MyURL);
//}
//    var srcFrame;
//function loadOuter(doc) {
//    srcFrame = document.getElementById("data_frame");
//    srcFrame.src = doc;
//    load_ary_framesrc = doc;
//    // workaround for missing onLoad event in IFRAME for NN6
//    //if (!srcFrame.onload) {
//    CtlLoadTimer = setTimeout("transferHTML()", 1000);
//    //}
//}

//function transferHTML() {
//    srcContent = '';
//    if (srcFrame.contentDocument) {
//        srcContent = srcFrame.contentDocument.getElementsByTagName("BODY")[0].innerHTML;
//    }
//    else if (srcFrame.contentWindow) {
//    srcContent = srcFrame.contentWindow.document.body.innerHTML;

//        if (srcContent == '') {
//            OState.load_ctl_counter += 1
//            if (OState.load_ctl_counter == 5) return;
//            loadOuter(load_ary_framesrc);
//        }
//    }
//    
//// Need to check if it's liaded
//// Make a loader counter in OState

//    var i = 0; // The start of the *^@
//    var j = 0; // The next *^@
//    var k = 0; // Substring cutter
//    var l = 0; // Substring cutter
//    var m = 0; // sub array counter
//    var n = 0; // sub array counter

//    var strTemp = '';
//    var strArrayName = '';

//    var tempary = new Array;
//    var temparyA = new Array;
//    
//    //slice it up into the arrays strings
//    //string.indexOf(searchstring, start)
//    // get the *^@
//    while (i != -1) {
//        i = srcContent.indexOf('*^@', i);
//        if (i == -1) break;
//        j = srcContent.indexOf('*^@', i + 3);
//        if (j == -1) {
//            j = srcContent.length;
//        }
//        strtemp = srcContent.substring(i, j); // needs to be j-3
//        // get the array name
//        k = strtemp.indexOf('*^', 3);
//        strArrayName = strtemp.substring(3, k-1);
//        strtemp = strtemp.substring(k);

//        tempary = strtemp.split('*^');
//        // remove empties and space at end
//        // remove the space at the end
//        // FF breaks because of a /n at the end of the arrays
//        n = 0;
//        for (m = 0; m <=(tempary.length - 1); m++) {
//            if (tempary[m] != '') {
//                temparyA[n] = tempary[m].substring(0, tempary[m].length - 1);
//                n++;
//            }
//        }
//        
//        // Switch Case ?? Have the array name?
//        //urlary typeary transary widthary heightary thumbary titleary txtary durary linkary extrefary intrefary catidary
//        switch (strArrayName) {
//            case 'urlary':
//                if (load_ary_dest == 'Main') {
//                    transfer_array(temparyA, urlary, false)
//                }
//                else {
//                    transfer_array(temparyA, sub_urlary, false)
//                }
//                break;
//            case 'typeary':
//                if (load_ary_dest == 'Main') {
//                    transfer_array(temparyA, typeary, false)
//                }
//                else {
//                    transfer_array(temparyA, sub_typeary, false)
//                }
//                break;
//            case 'transary':
//                if (load_ary_dest == 'Main') {
//                    transfer_array(temparyA, transary, false)
//                }
//                else {
//                    transfer_array(temparyA, sub_transary, false)
//                }
//                break;
//            case 'widthary':
//                if (load_ary_dest == 'Main') {
//                    transfer_array(temparyA, widthary, true)
//                }
//                else {
//                    transfer_array(temparyA, sub_widthary, true)
//                }
//                break;
//            case 'heightary':
//                if (load_ary_dest == 'Main') {
//                    transfer_array(temparyA, heightary, true)
//                }
//                else {
//                    transfer_array(temparyA, sub_heightary, true)
//                }
//                break;
//            case 'thumbary':
//                if (load_ary_dest == 'Main') {
//                    transfer_array(temparyA, thumbary, false)
//                }
//                else {
//                    transfer_array(temparyA, sub_thumbary, false)
//                }
//                break;        
//            case 'titleary':
//                if (load_ary_dest == 'Main') {
//                    transfer_array(temparyA, titleary, false)
//                }
//                else {
//                    transfer_array(temparyA, sub_titleary, false)
//                }
//                break;
//            case 'txtary':
//                if (load_ary_dest == 'Main') {
//                    transfer_array(temparyA, txtary, false)
//                }
//                else {
//                    transfer_array(temparyA, sub_txtary, false)
//                }
//                break;
//            case 'durary':
//                if (load_ary_dest == 'Main') {
//                    transfer_array(temparyA, durary, true)
//                }
//                else {
//                    transfer_array(temparyA, sub_durary, true)
//                }
//                break;
//            case 'linkary':
//                if (load_ary_dest == 'Main') {
//                    transfer_array(temparyA, linkary, false)
//                }
//                else {
//                    transfer_array(temparyA, sub_linkary, false)
//                }
//                break;
//            case 'extrefary':
//                if (load_ary_dest == 'Main') {
//                    transfer_array(temparyA, extrefary, false)
//                }
//                else {
//                    transfer_array(temparyA, sub_extrefary, false)
//                }
//                break;
//            case 'intrefary':
//                if (load_ary_dest == 'Main') {
//                    transfer_array(temparyA, intrefary, true)
//                }
//                else {
//                    transfer_array(temparyA, sub_intrefary, true)
//                }
//                break;
//            case 'catidary':
//                if (load_ary_dest == 'Main') {
//                    transfer_array(temparyA, catidary, true)
//                }
//                else {
//                    transfer_array(temparyA, sub_catidary, true)
//                }
//                break;                               
//        }
//        i = j;
//    }

//    if (load_ary_dest == 'Main') load_listing();
//    state_ctl('advance_ctr');
//}

//function transfer_array(srcary,destary,num) {
//    // clear the dest array first
//    temp = destary.splice(0, destary.length-1)
//    
////    for (i = 0; i <= destary.length - 1; i++) {
////        destary[i] = '';
////    }
//    for (i = 0; i <= srcary.length - 1; i++) {
//        // Chech for /n at the end

//        temp = srcary[i].substring(srcary[i].length - 1, srcary[i].length);
//        if (temp == '\n') {
//            srcary[i] = srcary[i].substring(0, srcary[i].length - 1);
//        }
//        if (num == false) {
//            destary[i] = srcary[i];
//        }
//        else {
//            destary[i] = parseInt(srcary[i]);
//        }
//    }
//}


