
$(function(){
    
    // Hide info box 
    $('#portfolio_map .info_box').css({display: 'none'});
    
    // Load Buildings Data
    $.getJSON("/Scripts/commercial_bldg_map.js", function(data){
        var count = 1;
        $.each(data, function(i, item){
            //create the point
            if (item.image != 'null') {
                var link = '<a href="' + item.more_link + '" class="point" id="' + count + '_point" title="' + item.name + '" name="/images/commercial/building_images/' + item.image + '">&nbps;</a>';
            } else {
                var link = '<a href="' + item.more_link + '" class="point" id="' + count + '_point" title="' + item.name + '" name="">&nbps;</a>';
                
            }

            $('#portfolio_map').append( link );
            
            //set the position of the point
            $('#' + count + '_point').css({top: item.top + 'px', left: item.left + 'px'});
            count++;
        });
            
            
        // Set up mouse over
        $('#portfolio_map .point').mouseover(function (eve) {

            
            var ele = $(this);
            
            //show and populate info box
            $('#portfolio_map .info_box').css({display: 'block'});
            $('#portfolio_map .info_box .building_name').text( ele.attr('title') );
            if (ele.attr('name') != '') {
                $('#portfolio_map .info_box .building_image').html( '<img alt="' + ele.attr('title') + '" src="' + ele.attr('name') + '" />' );
            } else {
                $('#portfolio_map .info_box .building_image').html( '<div class="no_image">No Image</div>');
            }
            
            $('#portfolio_map .more_link a').attr('href', ele.attr('href'));
            //reset the z-index of all the points
            $('#portfolio_map .point').css({'z-index': 999});
            $('#portfolio_map .active_point').removeClass('active_point');
            
            //put this point above all others
            ele.css({'z-index': 9999});
            ele.addClass('active_point');
            
        });
        
        // Set up clicks of points
        $('#portfolio_map .point').click(function (eve) {
            //just disable for now
            //eve.preventDefault();
        });
    });
});