var multi = function () {

//global hosturl
    var hosturl = $('#hosturl').val();
    var checkexist = function () {
        //# add new image.
        //$('#add_new_image').on('click',function(){
        $('body').on('click', '.add_new_image', function () {

            var controller = $('#controller').val();
//            alert(controller)
            var remove_itra = '';
            var cls_img = '';

//            if (controller == 'projects') {
            var subj_itra = $(this).attr('data-itra');
            var itr = $('#itr').val();
            var itr = Number(itr) + 1;
            $('#itr').val(itr);
            var marg = '';
//            alert('itr = ' + itr);
            var style = '';
            if (itr > 3) {
                style = 'margin-top: 20px;';
            } else {
                style = 'margin-top: 20px;';
            }
            var output = '';


            output += '    <div class="col-md-3 ' + marg + '" id="img_cont_' + itr + '" style="' + style + '">';
            output += '        <div class="clearfix"></div>';

            //# if controller = teachingstaff draw input for teacher .

            output += '        <div class="fileinput fileinput-new" data-provides="fileinput">';

            output += '            <div class="fileinput-preview thumbnail" data-trigger="fileinput_' + itr + '" style="width: 150px; height: 150px;">';

            output += '            </div>';
            output += '            <button type="button" style="margin-bottom: 118px;" data-itra="' + itr + '" class="btn red remove_image">-</button>';

            output += '            <div>';
            output += '                <span class="btn default btn-file">';
            output += '                    <span class="fileinput-new">استعراض</span>';
            output += '                    <span class="fileinput-exists">صوره</span>';
            output += '                    <input type="file" name="cls_img_' + itr + '"  accept="image/jpg, image/jpeg, image/png" class="img_cls fatmaclass" >';
            output += '                </span>';
            output += '                <a href="#" class="btn red fileinput-exists" data-dismiss="fileinput">';
            output += '                    حذف </a>';
            output += '            </div>';
            output += '            <div class="clearfix margin-top-10 margin-bottom-10">';
            output += '                <span class="label label-danger">ملاحظه!</span> يمكنك فقط رفع صور';
            output += '            </div>';

            output += '        </div>';

            output += '    </div>';

            $('#img_group').append(output);

//            UPLOAD();
        });

        //# remove image .
        $('body').on('click', '.remove_image', function () {
            var img_itra = $(this).attr('data-itra');
            $('#img_cont_' + img_itra + '').remove();
        });




    }




    return {
//main function to initiate the module
        init: function () {

            checkexist();
        }

    };
}();
jQuery(document).ready(function () {
    multi.init();
});