function StartCreatAlbum() {
    var name = $("#name").val();
    var descr = $("#descr").val();
    if (name != 0) {
        $("#name").css('background', '#fff');
        $('#box_loading').show();
        ge('box_but').disabled = true;
        $.post('/index.php?go=albums&act=create', {
            name: name,
            descr: descr,
            privacy: $('#privacy').val()
        }, function (data) {
            $('#box_loading').hide();
            if (data == 'no_name') {
                $('.err_red').show().text(lang_empty);
                ge('box_but').disabled = false
            } else if (data == 'no') {
                $('.err_red').show().text(lang_nooo_er);
                ge('box_but').disabled = false
            } else if (data == 'max') {
                Box.Close('albums');
                Box.Info('load_album', lang_dd2f_no, lang_max_albums, 280)
            } else {
                Box.Close('albums');
                Page.Go(data)
            }
        })
    } else {
        $("#name").css('background', '#ffefef');
        setTimeout("$('#name').css('background', '#fff').focus()", 800);
        $('#box_loading').hide()
    }
}
$(document).ready(function(){
	var aid = $('#aid').val();
	Xajax = new AjaxUpload('upload', {
		action: '/index.php?go=albums&act=upload&aid='+aid,
		name: 'uploadfile',
		onSubmit: function (file, ext) {
			if (!(ext && /^(jpg|png|jpeg|gif|jpe)$/.test(ext))) {
				Box.Info('load_photo_er', lang_dd2f_no, lang_bad_format, 400);
				return false;
			}
			Page.Loading('start');
		},
		onComplete: function (file, response){
			if(response == 'max_img'){
				Box.Info('load_photo_er2', lang_dd2f_no, lang_max_imgs, 400);
				Page.Loading('stop');
				return false
			}
			
			if(response == 'big_size'){
				Box.Info('load_photo_er2', lang_dd2f_no, lang_max_size, 300);
				Page.Loading('stop');
				return false
			}
				
			if(response == 'hacking'){
				return false
			} else {
				response = response.split('|||');
				$('<span id="photo_'+response[0]+'"></span>').appendTo('#photos').html('<div class="hralbum" style="margin:0px;background:#efefef;"></div><div id="cover_'+response[0]+'" style="padding-bottom:10px; padding-top:10px;padding-left:2px;"><a href="/photo'+response[2]+'_'+response[0]+'_sec=loaded" onClick="Photo.Show(this.href); return false"><span class="float_l" id="count_img"><img src="'+response[1]+'" alt="" /></span></a><div style="float:left; width:350px; margin-left:10px; "><div class="albums_name" style="color:#888;padding-bottom:5px;"><b>'+lang_albums_add_photo+'</b></div><textarea id="descr_'+response[0]+'" style="width:340px; height:46px;"></textarea><div class="clear" style="height:10px;"></div><button onClick="PhotoSaveDescr(\''+response[0]+'\'); return false;">'+lang_albums_save_descr+'</button><button class="blue_button" style="margin-left:10px;" onClick="AlbumDeletePhoto(\''+response[0]+'\'); return false;">'+lang_albums_del_photo+'</button><div class="clear"></div></div><div class="clear"></div></div>');
				
				var count_img = $('#count_img img').size();
				if(count_img == 1)
					$('#l_text').show();
					
				$('#button_clear').css('height', '10px');
				$('#button_clear2').css('height', '10px');
				
				$('html').animate({scrollTop: 99999}, 999);
				Page.Loading('stop');
			}
		}
	});
});
function AlbumDeletePhoto(i){
	Page.Loading('start');
	$.get('/index.php?go=albums&act=del_photo', {id: i}, function(){
		$('#photo_'+i).remove();
		var count_img = $('#count_img img').size();
		if(count_img < 1)
			$('#l_text').hide();

		Page.Loading('stop');
	});
}
function SetNewCover(i){
	Page.Loading('start');
	$.get('/index.php?go=albums&act=set_cover', {id: i}, function(){
		$('.covers').css('background', '#fff');
		$('#cover_'+i).css('background', '#f6f9fb').css('border-top', '1px solid #fff');
		$('.cover_links').show();
		$('#cover_link_'+i).hide();
		Page.Loading('stop');
	});
}
function PhotoSaveDescr(i){
	var descr = $('#descr_'+i).val();
	Page.Loading('start');
	$.post('/index.php?go=albums&act=save_descr', {id: i, descr: descr}, function(d){
		Page.Loading('stop');
	});
}