//vars
var markerArray = new Array();
var infoWindowArray = new Array();

var master_type = null;
var master_lease = null;

//document ready
$(document).ready(function(){

    
    
});

function closeInfoWindows(){
    
    $(infoWindowArray).each(function(i,e){
    
        e.close();
     
    });
    
}

function getLatLng(){
    
    lat = markerArray[0].getPosition().lat();
    lng = markerArray[0].getPosition().lng();

    $("#property_latitude").val(lat);
    $("#property_longitude").val(lng);
    
}

//functions

function filterPropertiesByType(type){
    
    master_type = type;

    //foreach marker
    $(markerArray).each(function(i,e){
        
        if(type != null){
            show = (e[type]) ? true : false;     
        } else {
            show = true;
        }
        
        //if this isnt being filtered out by the lease filter
        if(e["lease"] == master_lease || master_lease == null){
            //show if in this type, hide otherwise
            e.setVisible(show); 
        }    

    });

    //clear selected style
    $("#type_filters > li > a").attr("class","");
    //apply selected style
    $("a:contains("+type+")").attr("class","map-selected");
    
    //if this is the view all button
    if(!type){
        //clear the lease filter
        filterPropertiesByLease(null);
    }
    
}

function filterPropertiesByLease(lease){
    
    master_lease = lease;

    //foreach marker
    $(markerArray).each(function(i,e){
        
        if(lease != null){
            show = (e["lease"] == lease) ? true : false;      
        } else {
            show = true;
        }
        
        if(e[master_type] || master_type == null){
            //show if in this type, hide otherwise
            e.setVisible(show);      
        } 

    });
    
    //clear selected style
    $("#lease_filters > li > a").attr("class","");
    
    if(master_lease != null){
    
        if(lease){
            id = "lease";
        } else {
            id = "buy";
        }
        
        //apply selected style
        $("a:contains("+id+")").attr("class","map-selected");
        
    }
    
}
