var upload_files_sociel = {
        
        q_files : [],
        first_each_count : 0,
        cur_id : "",
        cur_idan_type : 0,
        img_url : "",
        user_id : 0,
        upload_folder : "uploads",
        in_width : "100%",
        in_height : "100%",
        set_background : "transparent",
        set_color : "white",
        
        cssit : function() {
                
                $("#"+upload_files_sociel.cur_id).css({
                    'background'   : upload_files_sociel.set_background,
                    'border-radius'   : '3px',
                    'width' : upload_files_sociel.in_width,
                    'height' : upload_files_sociel.in_height,
                    'min-height' : '150px',
                    'text-align' : 'center',
                    'position' : 'relative'
                }); 
                $("#"+upload_files_sociel.cur_id).find("input[type=file]").css({
                    'filter'   : 'lpha(opacity=0)',
                    'opacity'  : '0',
                    'width'  : upload_files_sociel.in_width,
                    'height'  : upload_files_sociel.in_height,
                    'position'  : 'absolute',
                    'left'  : '0',
                    'top'  : '0',
                    'z-index'  : '1',
                });
                var the_in_text = "<div style='z-index:0; margin-top:3px; color:white; font-weight:bold; position:absolute; width:100%; text-align:center; top:0; left:0; display: flex; align-items: center; justify-content: center; height: 100%;'>";
                the_in_text += "<div class='the_fileenenett_zoner'>";
                the_in_text += "<div>"+file_upload+"</div>";
                the_in_text += "</div>";
                
                
                
                $("#"+upload_files_sociel.cur_id).append(the_in_text);
                
                
                
        },
        
        init : function(the_id,img_area,uniq_id,type_func) {
        
        var cur_site_id = $('#cur_site_id').val();
        
        //console.log("WHAT FILES???->"+the_id);
        
        upload_files_sociel.cur_site_id = cur_site_id;
        upload_files_sociel.cur_id = the_id;
        upload_files_sociel.img_area = img_area;
        upload_files_sociel.uniq_id = uniq_id;
        upload_files_sociel.type_func = type_func;
        
        //if (type_func == 1) {upload_files.set_text = "בחרו תמונות";}
        
        upload_files_sociel.cssit();
    
    var the_connn = "#"+the_id;
            
    $(the_connn).find("input[type=file]").unbind();        
            
    $(the_connn).find("input[type=file]").bind('change', function(event) {
        
        upload_files_sociel.q_files = [];
    
    upload_files_sociel.first_each_count = event.target.files.length;
    
    var thei = 0;
    
  $.each(event.target.files, function(index, file) {
    var reader = new FileReader();
    
    
    reader.load = function(event) {
        var the_img = event.target.result;
        //console.log("the_img->"+the_img);
        };
    
    reader.onload = function(event) {  
      
      setTimeout(function(){ 
      
      //alert(file.type);
      //alert(event.target.result);
      
      thei++;  
      var object = {};
      object.filename = file.name;
      object.filetype = file.type;
      object.data = event.target.result;
      object.our_id = thei;
      upload_files_sociel.q_files.push(object);
        
        
        
        //if (file.type == "image/svg+xml") {
        
        if (file.type == "video/mp4") {
            
        var the_img = "<input type='hidden' value='2' id='img_or_video'/>";
        the_img += "<div class='the_img_in'>";
        the_img += "<div class='img_or_video_src'>";
        the_img += "<video width='100%;' height='300' controls>";
        the_img += "<source src='"+event.target.result+"' type='video/mp4'>";
        the_img += "</video>";
        the_img += "</div>";
        the_img += "</div>";
            
        } else {
        
        var the_img = "<input type='hidden' value='1' id='img_or_video'/>";
        the_img += "<div class='the_img_in'>";
        the_img += "<div class='img_or_video_src'><img src='"+event.target.result+"' width='100%' /></div>";
        the_img += "</div>";
        
        }
        if (upload_files_sociel.img_area == "shmay_user_panel_img") {
            $('.shmay_user_panel_img img').attr("src", event.target.result);
            $('.the_img_bash_main_logo').val(event.target.result);
            
            $('.the_do_post_pop_up').remove();
            
            the_edit_panels.big_save();
            
        }
        if ( upload_files_sociel.img_area == "the_conterento_panel_in1_background") {
            
            $('.the_conterento_panel_in1_background').css("background", "url('" + event.target.result + "')");
            $('.the_img_bash_main_top').val(event.target.result);
            
            $('.the_do_post_pop_up').remove();
            
            the_edit_panels.big_save();
            
            
            
        } else {
        $('#'+upload_files_sociel.img_area).html(the_img);    
        }
        
          
        $('.the_loading_popo').remove();  
        
        
        
      }, 500);
      
      
      
      
      
      
    };  
    reader.readAsDataURL(file);
    
    
    //console.log("thei->"+thei);
    
    //if (thei == upload_files.first_each_count) {
    //        
    //        setTimeout(function(){ upload_files.upload_to_server(); }, 1000);
    //
    //}
    
    });
    
    //console.log("upload_files.q_files-2222 ->"+JSON.stringify(upload_files_sociel.q_files))
  
    });
            
        },
        
        upload_direct : function(filename,data,thei,uniq_id,type_func,img_area) {
            
            
            console.log("filename->"+filename);
            console.log("thei->"+thei);
            
            var the_url = "/Ajax/upload_files.php";
            
        $.ajax({
          url: the_url,
          type: 'POST',
          data: {filename: filename
                 , data: data
                 , folder : upload_files_sociel.upload_folder
                 , user_id : upload_files_sociel.user_id
                 , action : "ckeditor_uploader"
                 , type_func : type_func
                 , site_id : upload_files_sociel.cur_site_id
                },
                
          beforeSend : function() {
              
              
              
          },      
                
          success: function(response) {
              
              
             var the_json = $.parseJSON(response);
             if (the_json.re == 1) {
                 
             }
             
              
          } ,
          
          error : function() {}
          
          });    
            
        },
        
        
    };