var SITE = SITE || {};

SITE.fileInputs = function() {
    var $this = $(this),
    $val = $this.val(),
    valArray = $val.split('\\'),
    newVal = valArray[valArray.length-1],
    $button = $this.siblings('.button'),
    $fakeFile = $this.siblings('.file-holder'),
    $limite = $this.siblings('.txt-file-limit');
    $selezionato = $this.siblings('.txt-button');
    
    if(newVal !== '') {
     
        
        var extension = newVal.substr( (newVal.lastIndexOf('.') +1) );
        switch(extension) {
            case 'doc':
            case 'docx':
            case 'pdf':
            case 'zip':
                $button.text($selezionato.html());
                
                if($fakeFile.length === 0) {
                    $button.after('<span class="file-holder">' + newVal + '</span>');
                } else {
                    $fakeFile.text(newVal);
                }
                break;                         // the alert ended with pdf instead of gif.
        
            default:
                $button.text($limite.html());
                if($fakeFile.length === 0)
                    $button.after('<span class="file-holder"></span>');
                else
                    $fakeFile.text("");
                break;
        }
        
        
    }
};

$(document).ready(function() {
    $('.file-wrapper input[type=file]').bind('change focus click', SITE.fileInputs);
});



