
//
// Code related specifically to the overlay drop down
//                                                   
$j('#contentWrapper').bind('paneLoaded', function() {
// Set bg color for initial active layer
$j('.activeLayer').parents('li:first').css('background-color', '#ECECEC');
$j('.layerCheck').hide();                                                 

// Set click event handlers for each layer 
$j('.overlay').each(function(i) {          
        var layerLocation = $j(this).attr('layerLocation');
        var id = this.id;                                  

/*
        if($j(this).hasClass('activeLayer')) {
                var test = $j('#' + this.id + 'Check');
                test.show();                           
                test.css('display', 'inline');         
        }                                              
*/                                                     
        $j(this).click(function(evt, data) {           
//              $j( '#loadingMsg' ).fadeIn( this.FadeInDt );
                // Remove active class if the active layer was clicked
                if($j(this).hasClass('activeLayer') ) {
                        $j(this).removeClass('activeLayer');
                        //activeLayerSave = '';
//                      hq.map.gMap.removeOverlay(hq.map.overlay);
                        $j('#' + this.id + 'Check').hide();
                        $j('.layerCheck').parents('li.level2').css('background-color', '');
                        $j('.hq_idx_overlayMenu').css('background-color', '');

                        // CLear saved spaces, layerid
                        $j('#loadedSpaceIds').val('');
                        $j('#loadedSpaceLayerId').val('');

                        var event = jQuery.Event('layerChange');
                        event.id = this.id;
                        event.layerLocation = layerLocation;
                        event.noLayer = true;

                        $j('#contentWrapper').trigger(event);


                        hq.ajax.loadLink($j('#pluginPath').val()  + '/searchlistings.php?listingOp=clear&noLayer=1');

                // Add the active class if a non active layer was clickced
                } else {
                        $j('.layerCheck').parents('li.level2').css('background-color', '');
                        $j('.layerCheck').hide();
                        $j('.overlay').removeClass('activeLayer');
                        $j(this).addClass('activeLayer');
//                      activeLayerSave = $j(this).attr('layerId');
//                      hq.map.addLayer(this.id, layerLocation);
//                      $j('#hq_idx_overlayMenu').css('background-color', '#ECCCCC');
                        $j('#' + this.id + 'Check').show();
                        $j('#' + this.id + 'Check').parents('li:first').css('background-color', '#ECECEC');
                        var noLayer = $j(this).hasClass('noLayer') ? true : false;


                        // New Layer, update label
                        var event = jQuery.Event('layerChange');
                        event.id = this.id;
                        event.layerLocation = layerLocation;
                        event.noLayer = noLayer;
                        event.noClear = data ? data.noClear : false;

                        $j('#contentWrapper').trigger(event);
                        $j('#doZoom').val('1');
                }

//              hq.ajax.loadLink('/wp-content/plugins/hq_idx/searchlistings.php?layerOp=clearLoaded');

//              $j( '#loadingMsg' ).fadeOut( this.FadeOutDt );
                return false;
        });
 });

// Show the goddamn check image for the active layer, i don't know why this won't work above
var id = $j('.activeLayer').attr('id');
var idStr = '#' + id + 'Check';
$j(idStr).show();


});

