﻿// Functions supporting the listing search pages.

function resizeSections(direction){        
    var listings = document.getElementById('Listings');
    var splitter = document.getElementById('Splitter');
    var listingsSplitter = document.getElementById('SplitterLeft');
    var mapSplitter = document.getElementById('SplitterRight');
    var map = document.getElementById('gmap');
    
    switch(direction){
        case 'left':
            switch(listings.style.width){
                case '975px':
                    showSmallMap(listings, map, listingsSplitter, mapSplitter, splitter);
                    break
                case '618px':
                    showLargeMap(listings, map, listingsSplitter, mapSplitter, splitter)
                    break
                case '354px':
                    showFullMap(listings, map, listingsSplitter, mapSplitter, splitter);
                    break
                default:
                    alert(listings.style.width)
            }
            break
        case 'right':
            switch(map.style.width){
                case '975px':
                    showLargeMap(listings, map, listingsSplitter, mapSplitter, splitter);
                    break
                case '618px':
                    showSmallMap(listings, map, listingsSplitter, mapSplitter, splitter);
                    break
                case '354px':
                    hideMap(listings, map, listingsSplitter, mapSplitter, splitter);
                    break
                default:
                    alert(listings.style.width)
            }
            break                
   }
   loadMap_gmap();
            
}

function hideMap(listings, map, listingsSplitter, mapSplitter, splitter){       
    //alert('inside hideMap');
    map.style.display = 'none'
    listings.style.width = '965px';
    mapSplitter.style.display = 'none';        
}

function showFullMap(listings, map, listingsSplitter, mapSplitter, splitter){
    //alert('inside showFullMap');
    listings.style.display = 'none';
    map.style.width = '975px';
    splitter.style.width = '977px';
    listingsSplitter.style.display = 'none';    
}

function showSmallMap(listings, map, listingsSplitter, mapSplitter, splitter){
    //alert('inside showSmallMap');
    map.style.width = '354px';
    splitter.style.width = '356px';
    listings.style.width = '618px';
    map.style.display = '';
    listingsSplitter.style.display = '';
    mapSplitter.style.display = 'none';
}

function showLargeMap(listings, map, listingsSplitter, mapSplitter, splitter){
    listings.style.width = '354px';
    map.style.width = '618px';
    splitter.style.width = '622px';
    listings.style.display = '';        
    listingsSplitter.style.display = '';
    mapSplitter.style.display = '';        
}
    

function collapseAllOtherListingDetails(divToExclude){
    var listings = document.getElementById('Listings');
    var divInListings = listings.getElementsByTagName('DIV');
    
    for( var x = 0; x < divInListings.length; x++ ) {
        if ((divInListings[x].id.search(/ListingDetails/) > -1) && (divInListings[x].id != divToExclude.id)){ 
            divInListings[x].style.display = 'none';
            divInListings[x].parentNode.className = 'listing';
        }
    }
}

function toggleDetails(rowID, index, mapIndex, moveMap, scrollList){
    //gather all div within active listing
    var thisListing = document.getElementById(rowID);
    var divsInListing = thisListing.parentNode.getElementsByTagName('Div');
    for( var x = 0; x <divsInListing.length; x++ ) {
        //find details listing div tag
        if (divsInListing[x].id.search(/ListingDetails/) > -1){
            //toggle display attribute
            if (divsInListing[x].style.display == 'block'){
                divsInListing[x].style.display = 'none';
            }
            else{
                divsInListing[x].style.display = 'block';
                thisListing.parentNode.className = 'listingSelected';
                collapseAllOtherListingDetails(divsInListing[x]);
                
                if (moveMap == true) {
                    // Center small map and add InfoWindow Toggle effect.
                    mOver(mapIndex - 1, 'gmap');
                    eval('map_smallMap' + index).checkResize();
                    setCenterAndZoom(eval('bounds_smallMap' + index), eval('map_smallMap' + index), 15);
                }
                
                if (scrollList == true) {
                    // Scroll results list to item
                    var list = document.getElementById('Listings');
                    list.scrollTop = ((index - 1) * 86);
                }
            }
        }        
    }
    //map_mapSmall2.checkResize();
} 

function testMe(){
    alert('testing');
}
