var elementos;


jQuery(document).ready(function($){
    var args = {
        action : "chronosly_load_mk_dashboard"

    };
    //generamos el html del template
    $.getJSON( ajaxurl, args, function( data ) {

        elementos = eval(data);
        pinta_addons_featured(elementos);
        pinta_addons_listado(elementos);
      
    });

})

function pinta_addons_featured(data){
    var caja = "";
    jQuery.each(data, function(){
        var el = jQuery(this)[0];
        if(el.featured == 1) {
            caja += pinta_addons_caja_featured(el);


        }
    });
    jQuery("#chronosly_dashboard .marketplace div.featured").append(caja);
}

function pinta_addons_listado(data){
    var caja = "";
    jQuery.each(data, function(){
        var el = jQuery(this)[0];

        caja += pinta_addons_caja(el);


    });
    jQuery("#chronosly_dashboard .marketplace div.list").append(caja);
}

function pinta_addons_caja_featured(el){
   
    return "<a  href='"+el.url+"' target='_blank'><div id='"+el.id+"' class='box featured' time='"+el.updated+"' d='"+el.dw+"' rate='"+el.rate+"'>" +
        "<img style='width:100%' src='"+el.img+"' />"+
        "<h4>"+el.name+"</h4>" +
        "<p class='desc'>"+el.desc+"</p>" +
        "</div></a>";

}

function pinta_addons_caja(el){

    if(el.featured) return "";
    return "<a  href='"+el.url+"' target='_blank'><div id='"+el.id+"' class='box' time='"+el.updated+"' d='"+el.dw+"' rate='"+el.rate+"'>" +
        "<img tyle='width:100%' src='"+el.img+"' />"+
        "<h4>"+el.name+"</h4>" +
        "<p class='desc'>"+el.desc+"</p>" +
        "</div></a>";

}


