/**
 * Данная библиотека функций включается только для редактирования галерей пользователя
 */

var gShowPhoto = Array;
var gUpCompl = 0;
function mup_onError(type, index, error) {
    alert(error);
}

function mup_onStart() {
    $("#indicator_upload").show();
}
	//mup_onCompleteAbsolute mup_onComplete
function mup_onCompleteAbsolute(type, totalBytesLoaded) {

    var gallery_id = $("#gallery_id").val();
    var gallery_hfu = $("#gallery_hfu").val();
    var gallery_user_hfu = $("#gallery_user_hfu").val();
    var gallery_name = $("#gallery_name").val();
    var countPhoto = $("#countPhoto").val();
    var url = $("#hAjaxURL").val();
    if (url && gallery_id) {
        ZF.call(url, {'gallery_id' : gallery_id, 'gallery_name':gallery_name},
            function (data) {
                if (data.success) {
                    var arr = data.data;
                    var _html = '';
                    /*for (key in arr) {        
_html = '<div class="friend_photo"><div class="intbutt">';
_html +='<a href="/comm/gallery/up/p/'+arr[key]+'"><img src="/img/left.gif" title="Сдвинуть влево" alt="влево" style="border: 0px none ;"/></a>';
_html +='<a href="/comm/gallery/down/p/'+arr[key]+'"><img src="/img/right.gif" title="Сдвинуть вправо" alt="вправо" style="border: 0px none ;"/></a>';
_html +='<a onclick="if(confirm(\'Вы действительно хотите удалить эту фотку?\')) {return true;} else {return false;}" href="/comm/gallery/delphoto/p/'+arr[key]+'"><img src="/img/deletedpic.gif" title="Удалить фотку" alt="удалить" style="border: 0px none ;"/></a>';
_html +='</div>';
_html +='<a id="'+arr[key]+'" href="/comm/gallery/detail/user/'+gallery_user_hfu+'/gallery/'+gallery_hfu+'/ph/'+arr[key]+'#go-photo" target="_parent" name="'+arr[key]+'" style="color: rgb(195, 28, 0);"><img src="/ui/'+gallery_user_hfu+'/gallery/'+gallery_hfu+'/'+arr[key]+'_1.jpg" /></a>';
_html +='<input id="namephoto-'+arr[key]+'" class="inp_nobr" type="text" style="text-align: center; width: 120px; color: rgb(128, 128, 128); font-size: 11px;" value="'+gallery_name+'" name="namephoto['+arr[key]+']"/></div>';
countPhoto = parseInt(countPhoto);
if (countPhoto >= 5) { 
    $("#countPhoto").val(1); 
    _html +='<div class="clear"></div>';
} else {
    $("#countPhoto").val((countPhoto+1));
}
                        $("#fb001").append(_html);
                    }
                    if (gUpCompl) {
                        //$("#indicator_upload").hide();
                        //alert('Фотографии загружены и обработаны. Чтобы перейти к просмотру фотоальбома нажмите "Сохранить изменения"');
                        gUpCompl = 0;
                        //document.location.replace('/comm/gallery/edit/id/'+gallery_id);
                        $("#frPageSave").submit(); 
                    }*/
                    alert('Ваши фотографии успешно загружены! После обработки сервером они будут доступны Вам! Ждите сообщения об окончании процесса обработки!');
                    $("#indicator_upload").hide();
                } else {
                }
            },
            function (data) {
            }
        ); 
    }   
   
}	

/*function mup_onCompleteAbsolute() {
    gUpCompl = 1;
}*/
function mup_onLoadVars (str) {

}

function setHidePhotoInterface (photo_id) {
    //gShowPhoto[photo_id] = true;
    if (gShowPhoto[photo_id]) {
        setTimeout("setHideInterface('"+photo_id+"')", 500);
        gShowPhoto[photo_id] = false;
    }    
}
function setViewPhotoInterface(photo_id) {
    gShowPhoto[photo_id] = true;
}
function setHideInterface(photo_id) {
    if (!gShowPhoto[photo_id]) {
        $("#divPhotoInterface_"+photo_id).hide();
    }
}
function setShowPhotoInterface (photo_id) {
    if (!gShowPhoto[photo_id]) {
        gShowPhoto[photo_id] = true;
        $("#divPhotoInterface_"+photo_id).show();
    }
}

function setDownPhoto(photo_id) {
    if (photo_id){
        var count = $("#cMovePositions_"+photo_id).val();
        var gallery_id = $("#hGalleryID").val();
        if (count) {
            ZF.call('/ajax/gallery/ajaxdownphoto', {'photo_id' : photo_id, 'gallery_id' : gallery_id, 'count' : count, 'type' : 8, 'order' : 1},
                function (data) {
                    if (data.success) {
                        
                        //$("#liPhoto_"+photo_id).remove();
                    } else {
                        alert(data.error);
                    }
                },
                function (data) {
                    alert('Не удалось выполнить запрос');
                }
            );
        }
    }
}

function setUpPhoto(photo_id) {
    if (photo_id){
        var count = $("#cMovePositions_"+photo_id).val();
        var gallery_id = $("#hGalleryID").val();
        if (count) {
            ZF.call('/ajax/gallery/ajaxdownphoto', {'photo_id' : photo_id, 'gallery_id' : gallery_id, 'count' : count, 'type' : 8, 'order' : 0},
                function (data) {
                    if (data.success) {
                        
                        //$("#liPhoto_"+photo_id).remove();
                    } else {
                        alert(data.error);
                    }
                },
                function (data) {
                    alert('Не удалось выполнить запрос');
                }
            );
        }
    }
}

function setDelPhoto (photo_id) {
    var fr_id = $("#hGalleryID").val();
   if (photo_id) {
        ZF.call('/ajax/gallery/ajaxdelphoto', {'photo_id' : photo_id, 'fr_id' : fr_id},
            function (data) {
                if (data.success) {
                    $("#liPhoto_"+photo_id).remove();
               } else {
                    alert(data.error);
                }
            },
            function (data) {
                alert('Не удалось выполнить запрос');
            }
        ); 
   }    
}

function addGallery(id) {
    ZF.call('/ajax/gallery/ajaxfradd', {'types_id' : id},
            function (data) {
                if (data.success) {
                    $("#ol2").html(data.data);
                    $('#getInv01,#ol2').show();
                    $("#inpName").focus();
                    return false;
                } else {
                }
            },
            function (data) {
            }
        ); 
    return false;
}

function gallAdded () {
    var gall_types_id = $('#gall_types_id').val();
    var inpName = $('#inpName').val();
    var bool = false;
    var ajaxurl;
    var ajaxdata;
    var ajaxrepl;
    switch (gall_types_id) {
        
        case '8': //добавить фотогалерею пользовательскую
        if (inpName) {
            ajaxurl = '/ajax/pub/ajaxaddui';
            ajaxdata = {'pubname' : inpName};
            ajaxrepl = '/comm/gallery/edit/id/';
        }        
        break;
    }
    if (ajaxdata) {
            ZF.call(ajaxurl, ajaxdata,
                function (data) {
                    if (data.success) {
                        document.location.replace(ajaxrepl+data.data);
                        $.modal.close();
                        bool = true;
                    }
                },
                function (data) {
                }
            );
    }
    return bool;
}