(function($){
    $(document).ready(function(){
        var $document  = $(document);
        var $change_lang_btn = $('.change-lang-btn');
        var $update_config_btn = $('.update-config-btn');
        var $update_translate_btn = $('.update-translate-btn');
        var $create_translate_btn = $('.create-translate-btn');
        var $create_lang_btn = $('.create-lang-btn');
        var $create_gal_btn = $('.create-gal-btn');
        var $update_gal_btn = $('.update-gal-btn');
        var $delete_gal_btn = $('.delete-gal-btn');
        var $switcher = $('.switcher');
        var $open_lang_edit = $('.open-lang-edit');
        var $info_table_content = $('.info-table-content');
        var $select_lang = $('#select-lang');
        var $select_gal = $('#select-gal');
        var $select_gal_file = $('#select-gal-file');
        var $group_location = $('.group-location-btn');
        var $a_pathname = $('a[href="'+location.pathname+'"]');
        var $filer_input = $('#filer-input');
        var $keyword_add = $('.keyword-add-btn');
        var $gal_info_form = $('#gal-info-form');
        var $upload_cont = $('#upload-cont');
        var $file_info_cont = $('#file-info-cont');
        var filer_init_status = false;
        var current_gallery_folder;

        $change_lang_btn.change(changeLang);
        $update_config_btn.click(updateConfig);
        $update_translate_btn.click(updateTranslate);
        $create_translate_btn.click(createTranslate);
        $create_lang_btn.click(createLang);
        $update_gal_btn.click(updateGal);
        $create_gal_btn.click(createGal);
        $delete_gal_btn.click(deleteGal);
        $switcher.change(switcherChnage);
        $select_lang.change(infoTableOpen);
        $select_gal.change(infoFormOpen);
        $select_gal_file.change(fileContOpen);
        $open_lang_edit.click(openLangEdit);
		$keyword_add.click(addKeyword);

        $document.on('click', '.update_fileinfo_btn', updateFileInfo)



        function changeLang(e) {
            var $this = $(this);
            var data  = {};
            data.lang =   $this.val();
            $.ajax({
                type: 'post',
                url: 'jezik/changelang',
                data: data,
                success:  function (response) {
                    notify(JSON.parse(response));
                    if( JSON.parse(response).status === 'success'){
                        setTimeout(function () {
                            location.reload();
                        },1500)
                    }

                }
            })

        }

        function updateConfig(e) {
            e.preventDefault();
            var $this = $(this),
                $form  = $this.closest('tr').find('form');

            $this.button('loading');
            if($this.hasClass('disabled')) return false;

            $.ajax({
                type: 'post',
                url: 'bojan/update',
                data: $form.serialize(),
                success:  function (response) {
                    $this.button('reset');
                    notify(JSON.parse(response));
                }
            })

        }

        function updateTranslate(e) {
            e.preventDefault();
            var $this = $(this),
                form = $this.data('form'),
                $form  = $this.closest('tr').find(form);
            $this.button('loading');
            if($this.hasClass('disabled')) return false;
            $.ajax({
                type: 'post',
                url: 'jezik/update',
                data: $form.serialize(),
                success:  function (response) {
                    $this.button('reset');
                    notify(JSON.parse(response));
                }
            })
        }

        function createTranslate(e) {
            e.preventDefault();
            var $this = $(this);
            var $form = $this.closest('form');
            $this.button('loading');
            if($this.hasClass('disabled')) return false;
            $.ajax({
                type: 'post',
                url: 'jezik/create',
                data: $form.serialize(),
                success:  function (response) {
                    $this.button('reset');
                    $form.get(0).reset();
                    notify(JSON.parse(response));
                }
            })
        }
		function createGal(e) {
            e.preventDefault();
            var $this = $(this);
            var $form = $this.closest('form');
            $this.button('loading');
            if($this.hasClass('disabled')) return false;
            $.ajax({
                type: 'post',
                url: 'filemanager/create',
                data: $form.serialize(),
                success:  function (response) {
                    $this.button('reset');
                    $form.get(0).reset();
                    notify(JSON.parse(response));
                }
            })
        }
        function updateGal(e) {
            e.preventDefault();
            var $this = $(this);
            var $form = $this.closest('form');
            $this.button('loading');
            if($this.hasClass('disabled')) return false;
            $.ajax({
                type: 'post',
                url: 'filemanager/update',
                data: $form.serialize(),
                success:  function (response) {
                    $this.button('reset');
                    notify(JSON.parse(response));
                     if( JSON.parse(response).status === 'success'){
                        setTimeout(function () {
                            location.reload();
                        },1500)
                    }
                }
            })
        }

        function deleteGal(e){
            e.preventDefault();
            var $this = $(this);
            $.ajax({
                type: 'post',
                url: 'filemanager/delete',
                data: {gallery_id: $select_gal.val()},
                success:  function (response) {

                    notify(JSON.parse(response));
                    if( JSON.parse(response).status === 'success'){
                        setTimeout(function () {
                            location.reload();
                        },1500)
                    }

                }
            })

        }
        function updateFileInfo(e){
            e.preventDefault();
            var $this = $(this);
            var $form = $this.closest('form');
            var $item = $('li.og-expanded').find('a.grid-item');
            $this.button('loading');
            if($this.hasClass('disabled')) return false;
            $.ajax({
                type: 'post',
                url: 'filemanager/updateinfo',
                data: $form.serialize(),
                success:  function (response) {
                    $this.button('reset');
                    if( JSON.parse(response).status === 'success'){
                        $item.data("title",$form.find('input[name="file_title"]').val());
                        $item.data("alt", $form.find('input[name="file_alt"]').val());
                        $item.data("description", $form.find('textarea[name="file_description"]').val());
                    }
                    notify(JSON.parse(response));
                }
            })

        }

        function infoTableOpen() {
            $info_table_content.slideDown()
        }

        function fileContOpen() {
            Grid.reset();
            var $this = $(this);
            var data = $this.find('option:selected').data('value');

            $.ajax({
                type: 'post',
                url: 'filemanager/filelist',
                data: {gallery_id: $this.val()},
                success:  function (response) {
                    if( JSON.parse(response).status === 'success'){
                        var data  =  JSON.parse(response).data;
                        for(var key in data){
                            var item = data[key];
                            var arr = data[key].file_path.split("/");
                            var name = arr[arr.length-1];
                            var $items = $( '<li><a class="grid-item" href="" \
                                data-id="'+item.file_id+'" \
                                data-title="'+item.title+'" \
                                data-largesrc="'+item.file_path+'" \
                                data-status="'+item.file_status+'" \
                                data-name="'+name+'" \
                                data-alt="'+item.alt+'" \
                                data-description="'+item.description+'">\
                                <img src="'+item.file_path+'" height="200px"/></a>'
                            )
                            .appendTo( $( '#og-grid' ) );

                            Grid.addItems( $items );
                        }
                    }
                    notify(JSON.parse(response));

                }
            })



        }
		function infoFormOpen() {
            var $this = $(this);
            current_gallery_folder = $this.find('option:selected').data('folder');
            $this.closest('.tab-pane').find('input[name="gallery_folder"]').val(current_gallery_folder);
            $this.closest('.tab-pane').find('input[name="gallery_id"]').val($this.val());
            $upload_cont.removeClass('hidden');
            $.ajax({
                type: 'post',
                url: 'filemanager/filelist',
                data: {gallery_id: $this.val()},
                success:  function (response) {
                    $filer_input.trigger("filer.reset");
                    if( JSON.parse(response).status === 'success'){
                        var data  =  JSON.parse(response).data;
                        for(var key in data){
                            var arr = data[key].file_path.split("/");
                            data[key].name = arr[arr.length-1];
                            data[key].file = data[key].file_path;
                            data[key].status = data[key].file_status;
                            data[key].type = "image/jpg";
                            delete data[key].file_status;
                            delete data[key].file_path;
                        }
                        $filer_input.trigger("filer.append", {
                            files: data
                        })
                    }
                    notify(JSON.parse(response));
                }
            })
            var data = $this.find('option:selected').data('value');
            var $input_group_clone = $('.input-group-clone');
            $gal_info_form.get(0).reset();
            $input_group_clone.remove();
            $gal_info_form.find('textarea[name="gallery_description"]').val(data.gallery_description);
            $gal_info_form.find('input[name="gallery_folder"]').val(data.gallery_folder);
            $gal_info_form.find('input[name="gallery_type"]').val(data.gallery_type);
            $gal_info_form.find('input[name="gallery_title"]').val(data.gallery_title);
            $gal_info_form.find('input[name="gallery_type"]').val(data.gallery_type);
            $gal_info_form.find('input[name="gallery_kw[]"]').val(data.gallery_kw);
        }

		function addKeyword(){

			 var $this = $(this);
			 var $form_group = $this.closest('.form-group');
			 var $inp_group = $this.closest('.input-group');
			 var $inp_group_clone = $inp_group.clone();

			 $inp_group_clone
             .addClass('input-group-clone')
			 .find('input')
			 .val('');
			 $inp_group_clone
			 .find('.input-group-addon')
			 .removeClass('keyword-add-btn')
			 .addClass('keyword-del-btn')
			 .bind("click",delKeyword);
			 $inp_group_clone
			 .find('.fa')
			 .removeClass('fa-plus')
			 .addClass('fa-minus')
			 .addClass('text-danger');

			 $form_group.append($inp_group_clone);
		}
		function delKeyword(){
			 var $this = $(this);
			 var $inp_group = $this.closest('.input-group');
			 $inp_group.remove();
		}

        function createLang(e) {
            e.preventDefault();
            var $this = $(this);
            var $form = $this.closest('form');
            $this.button('loading');
            if($this.hasClass('disabled')) return false;
            $.ajax({
                type: 'post',
                url: 'jezik/createlang',
                data: $form.serialize(),
                success:  function (response) {
                    $this.button('reset');
                    $form.find("select option:selected").remove();
                    if($form.find("select option").length ===1){
                        location.reload();
                    }
                    $info_table_content.slideUp();
                    $form.get(0).reset();
                    notify(JSON.parse(response));

                }
            })
        }
        function switcherChnage(e) {
            var $this = $(this);
            var $switcher_inp = $this.closest('form').find('.switcher-inp');
            if($this.prop('checked')){
                $switcher_inp.val(true)
            }else{
                $switcher_inp.val(false)
            }
        }

        function openLangEdit(e) {
            e.preventDefault();
            var $this  =  $(this);
            var block  = $this.data('block');
            var $block  = $(block);
            $block.slideToggle(300);
        }
        // Notify Plugin
        //-----------------------------------------------
        function notify(data) {
            var icon = 'glyphicon-warning-sign';
            var type  = 'danger';
            if( data.status === 'success'){
                icon = 'glyphicon-ok';
                type  = 'success';
            }
            $.notify({
                // options
                message: data.message,
                icon: 'glyphicon '+icon,
            },{
                // settings
                type: type,
                delay: 2000,
                offset: 20
            });
        }


// Google Maps
//-----------------------------------------------

        var markers = [];



        var map,
            myLatlng,
            myZoom,
            marker,
            markerTimeout,
            mapTypeId,
            timeouts = [] ;

        // Deletes all timeouts
        function clearAllTimeouts(){
            for(var i = 0, z = timeouts.length; i < z; i++){
                clearTimeout(timeouts[i]);
            }
            timeouts = [];
        }

        // Sets the map on all markers in the array.
        function setMapOnAll(map) {
            for (var i = 0; i < markers.length; i++) {
                markers[i].setMap(map);
            }
        }

        // Removes the markers from the map, but keeps them in the array.
        function clearMarkers() {
            setMapOnAll(null);
        }

        // Deletes all markers in the array by removing references to them.
        function deleteMarkers() {
            clearAllTimeouts();
            clearMarkers();
            markers = [];
        }


        function initialize() {
            myLatlng = new google.maps.LatLng(avgLat, avgLng);
            if(clan_data){
                myZoom = 16;
                mapTypeId = google.maps.MapTypeId.HYBRID;
                $a_pathname.closest(".collapse").collapse('show');
                $a_pathname.closest("li").addClass('active');
                addMarkerWithTimeout(clan_data, 50);
            }else{
                myZoom = 12;
                mapTypeId = google.maps.MapTypeId.ROADMAP
                if(window.location.hash != ''){
                    var group = window.location.hash.replace('#','');
                    if(prireditelj_groups.hasOwnProperty(group)){
                        var groups_data  = prireditelj_groups[group];
                        for (var j = 0; j < groups_data.length; j++) {
                            addMarkerWithTimeout(groups_data[j], j*50, group);
                        }
                    }else{
                        initAllMarker();
                    }
                }else{
                    initAllMarker();
                }

            }
            function initAllMarker(){
                var i=0;
                for (var key in prireditelj_groups) {
                    var groups_data  = prireditelj_groups[key];
                    for (var j = 0; j < groups_data.length; j++) {
                        addMarkerWithTimeout(groups_data[j], i*50, key);
                        i++;
                    }
                }
            }
            var mapOptions = {
                zoom: myZoom,
                mapTypeId: mapTypeId,
                center: myLatlng,
                scrollwheel: false,
                styles:[
                    {
                        "featureType": "water",
                        "elementType": "geometry",
                        "stylers": [
                            {
                                "visibility": "on"
                            },
                            {
                                "color": "#aee2e0"
                            }
                        ]
                    },
                    {
                        "featureType": "landscape",
                        "elementType": "geometry.fill",
                        "stylers": [
                            {
                                "color": "#abce83"
                            }
                        ]
                    },
                    {
                        "featureType": "poi",
                        "elementType": "geometry.fill",
                        "stylers": [
                            {
                                "color": "#769E72"
                            }
                        ]
                    },
                    {
                        "featureType": "poi",
                        "elementType": "labels.text.fill",
                        "stylers": [
                            {
                                "color": "#7B8758"
                            }
                        ]
                    },
                    {
                        "featureType": "poi",
                        "elementType": "labels.text.stroke",
                        "stylers": [
                            {
                                "color": "#EBF4A4"
                            }
                        ]
                    },
                    {
                        "featureType": "poi.park",
                        "elementType": "geometry",
                        "stylers": [
                            {
                                "visibility": "simplified"
                            },
                            {
                                "color": "#8dab68"
                            }
                        ]
                    },
                    {
                        "featureType": "road",
                        "elementType": "geometry.fill",
                        "stylers": [
                            {
                                "visibility": "simplified"
                            }
                        ]
                    },
                    {
                        "featureType": "road",
                        "elementType": "labels.text.fill",
                        "stylers": [
                            {
                                "color": "#5B5B3F"
                            }
                        ]
                    },
                    {
                        "featureType": "road",
                        "elementType": "labels.text.stroke",
                        "stylers": [
                            {
                                "color": "#ABCE83"
                            }
                        ]
                    },
                    {
                        "featureType": "road",
                        "elementType": "labels.icon",
                        "stylers": [
                            {
                                "visibility": "off"
                            }
                        ]
                    },
                    {
                        "featureType": "road.local",
                        "elementType": "geometry",
                        "stylers": [
                            {
                                "color": "#A4C67D"
                            }
                        ]
                    },
                    {
                        "featureType": "road.arterial",
                        "elementType": "geometry",
                        "stylers": [
                            {
                                "color": "#9BBF72"
                            }
                        ]
                    },
                    {
                        "featureType": "road.highway",
                        "elementType": "geometry",
                        "stylers": [
                            {
                                "color": "#EBF4A4"
                            }
                        ]
                    },
                    {
                        "featureType": "transit",
                        "stylers": [
                            {
                                "visibility": "off"
                            }
                        ]
                    },
                    {
                        "featureType": "administrative",
                        "elementType": "geometry.stroke",
                        "stylers": [
                            {
                                "visibility": "on"
                            },
                            {
                                "color": "#87ae79"
                            }
                        ]
                    },
                    {
                        "featureType": "administrative",
                        "elementType": "geometry.fill",
                        "stylers": [
                            {
                                "color": "#7f2200"
                            },
                            {
                                "visibility": "off"
                            }
                        ]
                    },
                    {
                        "featureType": "administrative",
                        "elementType": "labels.text.stroke",
                        "stylers": [
                            {
                                "color": "#ffffff"
                            },
                            {
                                "visibility": "on"
                            },
                            {
                                "weight": 4.1
                            }
                        ]
                    },
                    {
                        "featureType": "administrative",
                        "elementType": "labels.text.fill",
                        "stylers": [
                            {
                                "color": "#495421"
                            }
                        ]
                    },
                    {
                        "featureType": "administrative.neighborhood",
                        "elementType": "labels",
                        "stylers": [
                            {
                                "visibility": "off"
                            }
                        ]
                    }
                ]
            };
            map = new google.maps.Map(document.getElementById("map"),mapOptions);


            var getContentString = function (info) {
                var info_str  =  '<div id="content">'+
                    '<div id="siteNotice">'+
                    '</div>'+
                    '<h4 id="firstHeading" class="firstHeading">'+info.prireditelj_company+'</h4>'+
                    '<div id="bodyContent">';
                if(info.prireditelj_name) info_str+= '<p>Kontakt: '+info.prireditelj_name+'</p>';
                if(info.prireditelj_address) info_str+= '<p>address: '+info.prireditelj_address+'</p>';
                if(info.prireditelj_fax) info_str+= '<p>fax: <a href="tel:'+info.prireditelj_fax+'">'+info.prireditelj_fax+'</a> </p>';
                if(info.prireditelj_tel) info_str+= '<p>tel: <a href="tel:'+info.prireditelj_tel+'">'+info.prireditelj_tel+'</a> </p>';
                if(info.prireditelj_email) info_str+= '<p>e-pošta: <a href="mailto: '+info.prireditelj_email+'">'+info.prireditelj_email+'</a> </p>';
                info_str += '</div></div>'
                return  info_str;
            }

            var infowindow = new google.maps.InfoWindow();

            function addMarkerWithTimeout(data, timeout, key) {

                markerTimeout = window.setTimeout(function() {
                    var position  = {
                        lat: +data.prireditelj_lat, lng: +data.prireditelj_lon
                    }
                    marker = new google.maps.Marker({
                        position: position,
                        map: map,
                        animation: google.maps.Animation.DROP
                    })
                    marker.addListener('click',
                        (function(marker, data) {
                            return function() {
                                infowindow.setContent(getContentString(data))
                                infowindow.open(map, marker);
                            }
                        })(marker, data));
                    markers.push(marker);
                    $('[data-group="'+key+'"]').addClass('active');
                }, timeout);
                timeouts.push(markerTimeout);
            }

            google.maps.event.addDomListener(window, "resize", function() {
                map.setCenter(myLatlng);
            });
            if(clan_data === undefined){
                $group_location.click(showGroupLocation);
            }



            function showGroupLocation(e) {
                // e.preventDefault();
                var $this  = $(this);
                var group = $this.data('group');
                $group_location.removeClass('active');
                $this.addClass('active');
                // window.location.hash = "#"+group;
                deleteMarkers();
                for (var i = 0; i < prireditelj_groups[group].length; i++) {
                    addMarkerWithTimeout(prireditelj_groups[group][i], i * 100);
                }

            }
        }
        if(document.getElementById("map") !== null){
            google.maps.event.addDomListener(window, "load", initialize);
        }


        /* Init Filer Input*/
        if($filer_input.length>0) filerInit();
        function filerInit(){

            filer_init_status = true;
            var dev = $filer_input.filer({
            limit:999,
            changeInput: '<div class="jFiler-input-dragDrop"><div class="jFiler-input-inner"><div class="jFiler-input-icon"><i class="icon-jfi-cloud-up-o"></i></div><div class="jFiler-input-text"><h3>Potegni in spusti datoteke tukaj za prenos na strežnik</h3> <span style="display:inline-block; margin: 15px 0"> ALI</span></div><a class="jFiler-input-choose-btn blue"><i class="fa fa-files-o" aria-hidden="true"></i> IZBERI DATOTEKE</a></div></div>',
            showThumbs: true,
            theme: "dragdropbox",
            templates: {
                box: '<ul class="jFiler-items-list jFiler-items-grid"></ul>',
                item: '<li class="jFiler-item">\
                    <div class="jFiler-item-container">\
                        <div class="jFiler-item-inner">\
                            <div class="jFiler-item-thumb">\
                                <div class="jFiler-item-status"></div>\
                                <div class="jFiler-item-info">\
                                    <span class="jFiler-item-title"><b title="{{fi-name}}">{{fi-name | limitTo: 25}}</b></span>\
                                    <span class="jFiler-item-others">{{fi-size2}}</span>\
                                </div>\
                                {{fi-image}}\
                            </div>\
                            <div class="jFiler-item-assets jFiler-row">\
                                <ul class="list-inline pull-left">\
                                    <li>{{fi-progressBar}}</li>\
                                </ul>\
                                <ul class = "list-inline pull-right">\
                                    <li>\
                                        <div class="btn-group dropup">\
                                                <span class="hidden glyphicon glyphicon-triangle-top dropdown-toggle" aria-hidden="true" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"></span>\
                                                <div class="dropdown-menu tools-menu">\
                                                    <a class="dropdown-item jFiler-item-showHide-action" >{{fi-status}}</span></a>\
                                                    <a class="dropdown-item jFiler-item-trash-action" ><span class="glyphicon glyphicon-trash pull-right" aria-hidden="true"></span> <b>Izbriši</b></a>\
                                                </div>\
                                            </div>\
                                    </li>\
                                </ul>\
                            </div>\
                        </div>\
                    </div>\
                </li>',
                itemAppend: '<li class="jFiler-item">\
                        <div class="jFiler-item-container">\
                            <div class="jFiler-item-inner">\
                                <div class="jFiler-item-thumb">\
                                    <div class="jFiler-item-status"></div>\
                                    <div class="jFiler-item-info">\
                                        <span class="jFiler-item-title"><b title="{{fi-name}}">{{fi-name | limitTo: 25}}</b></span>\
                                    </div>\
                                    {{fi-image}}\
                                </div>\
                                <div class="jFiler-item-assets jFiler-row">\
                                    <ul class="list-inline pull-left">\
                                        <li><span class="jFiler-item-others">{{fi-icon}}</span></li>\
                                    </ul>\
                                    <ul class="list-inline pull-right">\
                                        <li>\
                                            <div class="btn-group dropup">\
                                                <span class="glyphicon glyphicon-triangle-top dropdown-toggle" aria-hidden="true" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"></span>\
                                                <div class="dropdown-menu tools-menu">\
                                                    <a class="dropdown-item jFiler-item-showHide-action" >{{fi-status}}</span></a>\
                                                    <a class="dropdown-item jFiler-item-trash-action" ><span class="glyphicon glyphicon-trash pull-right" aria-hidden="true"></span> <b>Izbriši</b></a>\
                                                </div>\
                                            </div>\
                                        </li>\
                                    </ul>\
                                </div>\
                            </div>\
                        </div>\
                    </li>',
                progressBar: '<div class="bar"></div>',
                itemAppendToEnd: true,
                removeConfirmation: false,
                _selectors: {
                    list: '.jFiler-items-list',
                    item: '.jFiler-item',
                    progressBar: '.bar',
                    remove: '.jFiler-item-trash-action',
                    showHide: '.jFiler-item-showHide-action'
                }
            },
            dragDrop: {
                dragEnter: null,
                dragLeave: null,
                drop: null,
            },
            uploadFile: {
                url: "/filemanager/upload",
                data: {
                    gallery_id: $select_gal.val(),
                    gallery_folder: $select_gal.find('option:selected').data('folder'),
                },
                type: 'POST',
                enctype: 'multipart/form-data',
                beforeSend: function(i, s, r, o, l, n, t){
                    t.data.set('gallery_id',   $select_gal.val());
                    t.data.set('gallery_folder', $select_gal.find('option:selected').data('folder'));
                },
                success: function(response, el){
                    var parent = el.find(".jFiler-jProgressBar").parent();
                    var res = JSON.parse(response);
                    el.find(".jFiler-jProgressBar").fadeOut("slow", function(){
                        if(res.status === 'success')
                            $("<div class = \"jFiler-item-others text-success\"><i class = \"icon-jfi-check-circle\"></i> Success</div>").hide().appendTo(parent).fadeIn("slow");
                        else
                            $("<div class=\"jFiler-item-others text-warning\"><i class=\"icon-jfi-minus-circle\"></i> Error</div>").hide().appendTo(parent).fadeIn("slow");

                    });
                    notify(JSON.parse(response))
                },
                error: function(el){
                    var parent = el.find(".jFiler-jProgressBar").parent();
                    el.find(".jFiler-jProgressBar").fadeOut("slow", function(){
                        $("<div class=\"jFiler-item-others text-warning\"><i class=\"icon-jfi-minus-circle\"></i> Error</div>").hide().appendTo(parent).fadeIn("slow");
                    });
                },
                statusCode: null,
                onProgress: null,
                onComplete: null
            },
            onRemove: function(el, file){
                var data = {};
                data.gallery_folder = current_gallery_folder;
                data.file_name  = file.name;
                data.file_id  = file.file_id;
                data.file_status = "-1";
                $.ajax({
                    type: 'post',
                    url: 'filemanager/changestatus',
                    data: data,
                    success:  function (response) {
                        notify(JSON.parse(response));
                    }
                })
            },
            onShowHide: function(el, file){
                var $action = el.find('.jFiler-item-showHide-action');
                var data = {};
                data.file_id  = file.file_id;
                data.file_status = file.status == 1 ? "0" : "1";
                $.ajax({
                    type: 'post',
                    url: 'filemanager/changestatus',
                    data: data,
                    success:  function (response) {
                        if( JSON.parse(response).status === 'success'){
                            if(file.status == 1){
                                $action.find('b').text('Show');
                            }else{
                                $action.find('b').text('Hide');
                            }
                            file.status =  data.file_status;
                            $action.find('span').toggleClass('glyphicon-eye-close glyphicon-eye-open');
                        }
                        notify(JSON.parse(response));
                    }
                })
            }
        });

        }


		function getFormData($form){
            var unindexed_array = $form.serializeArray();
			var indexed_array = {};

			$.map(unindexed_array, function(n, i){

                var key = n['name'];
                var val = n['value'];
				if(key.indexOf('[]') != -1){
                    key = n['name'].replace("[]", "");
		          if(!indexed_array.hasOwnProperty(key)) indexed_array[key] = [];
			         indexed_array[key].push(n['value'])
			    }else{
			         indexed_array[key] = val;
			    }

			});

				return indexed_array;
			}

        Grid.init();

    }); // End document ready

})(this.jQuery);
