var ajaxCall;

function getGallery(page,sub_page_id,section_id) {
    if (ajaxCall != undefined)
        ajaxCall.abort();
    
    $("#"+section_id).css('height',$("#"+section_id).height()).empty()
    .html('<div id="spin_gallery"  style="position: relative; top: 50%;">');  
    
    spin('spin_gallery');
    
    if(typeof page === 'object' || typeof page === 'undefined')
        page = 1;


    ajaxCall = $.post('/gallery',
    { 
        'sub_page_id':sub_page_id,
        'page':page
    }, function(data) {
        ajaxCall = null;
        $("#"+section_id).html(data);
    });
  
}

function getFiles(page,sub_page_id) {
    if (ajaxCall != undefined)
        ajaxCall.abort();

    $("#park-file").css('height',$("#park-file").height()).empty()
    .html('<div id="spin_download"  style="position: relative; top: 50%;">');   
    
    spin('spin_download');
    
    if(typeof page === 'object' || typeof page === 'undefined')
        page = 1;


    ajaxCall = $.post('/download',
    { 
        'sub_page_id':sub_page_id,
        'page':page
    }, function(data) {
        ajaxCall = null;
        $('#park-file').html(data);
    });
  
}
function getFloors(floor,building) {
    if (ajaxCall != undefined)
        ajaxCall.abort();
    if(floor == 0 && building == 0)
       $(".tabs-content").addClass('light');
        
    $(".tabs-content").css('height',$(".tabs-content").height()).empty()
    .html('<div id="spin_floorplan"  style="position: relative; top: 50%;">');  
    
    spin('spin_floorplan');
    
    if(typeof floor === 'object' || typeof floor === 'undefined')
        floor = 2;
    
    if(typeof building === 'object' || typeof building === 'undefined')
        building = $("#build").find('a.active').parent('li').attr('name');
    
    
    ajaxCall = $.post('/floors',
    { 
        'floor': floor,
        'building': building
    }, function(data) {
        ajaxCall = null;
        $('.tabs-content').html(data);
    });
  
}


function getFloorPlan(floor,building) {
    if (ajaxCall != undefined)
        ajaxCall.abort();

    $(".floorplan-container").css('height',$(".floorplan-container").height()).empty()
    .html('<div id="spin_floorplan"  style="position: relative; top: 50%;">'); 
    
    spin('spin_floorplan');
    
    if(typeof floor === 'object' || typeof floor === 'undefined')
        floor = 2;
    
    if(typeof building === 'object' || typeof building === 'undefined')
        building = $("#build").find('a.active').parent('li').attr('name');
    
    ajaxCall = $.post('/floorplan',
    { 
        'floor': floor,
        'building': building
    }, function(data) {
        ajaxCall = null;
        $('.floorplan-container').html(data);
    });
  
}

function getApartment(apartment_id) {
    $('#tiptip_holder').fadeOut('fast');
    if (ajaxCall != undefined)
        ajaxCall.abort();

    $(".tabs-content").css('height',$(".tabs-content").height()).empty()
    .html('<div id="spin_floorplan" style="position: relative; top: 50%;">');	   
    
    spin('spin_floorplan');
    
    ajaxCall = $.post('/apartment',
    { 
        'apartment_id': apartment_id
    }, function(data) {
        ajaxCall = null;
        $('.tabs-content').html(data);
    });
  
}

function spin(element){

    var opts = {
        lines: 12, // The number of lines to draw
        length: 7, // The length of each line
        width: 4, // The line thickness
        radius: 10, // The radius of the inner circle
        color: '#463b4a', // #rgb or #rrggbb
        speed: 1, // Rounds per second
        trail: 60, // Afterglow percentage
        shadow: false // Whether to render a shadow
    };
    
    if(element=='spin_floorplan'){
        var opts = {
            lines: 12, // The number of lines to draw
            length: 7, // The length of each line
            width: 4, // The line thickness
            radius: 10, // The radius of the inner circle
            color: '#fff', // #rgb or #rrggbb
            speed: 1, // Rounds per second
            trail: 60, // Afterglow percentage
            shadow: false // Whether to render a shadow
        };        
    }

    var target = document.getElementById(element);
    var spinner = new Spinner(opts).spin(target);
    
    target.appendChild(spinner.el);
    $('#'+element).children().css('width','50px');
}
