//------------------
//
// CLASS ScreenShotBrowser

function ScreenShotBrowser(shot_server, media_server, user_gallery)
{
	this.shot_server = shot_server;
	this.media_server = media_server;
	this.user_gallery = user_gallery;
	this.plugin = null;

	this.width = 953;
	this.thumb_max = 5;
	this.fade_time = 400;
	this.ad_seconds = 20;

	this.strings = {};
	this.visible = false;
	this.shotgroups = {};
	this.shots = null;
	this.curshotgroup = null;
	this.curidx = -1;
	this.curshot = null;
	this.thumb_start = 0;
	this.fader = null;
	this.fader_start = null;
	this.page_start = null;
	this.ad_link = null;
	this.ad_time = null;
	this.ad_counter = 0;

	window.onresize = function() {Center(document.getElementById('ssbr'));}
}
var thisclass = ScreenShotBrowser.prototype;

//------------------

thisclass.AttachPlugin = function(plugin)
{
	this.plugin = plugin;
}

//------------------

thisclass.ShiftFocus = function()
{
	document.getElementById('ssbr_close').focus();
	document.getElementById('ssbr_close').blur();
}

//------------------

thisclass.ActivateShotGroup = function(group)
{
	if(group==null)
		group = '';
	if(group==this.curshotgroup)
	    return;
	this.curshotgroup = group;
	if(group=='')
	{
		this.shots = [];
	}
	else
	{
		if(!this.shotgroups[group])
		{
			this.shotgroups[group] = [];
		}
		this.shots = this.shotgroups[group];
	}
}

//------------------
// NOTE: if a guid is given, the shot will be editable

thisclass.AddShot = function(group, file, guid, desc, username, game_name, game_link, game_icon, date)
{
	// create shot group
    this.ActivateShotGroup(group);
	var obj_thumb = document.createElement("img");
	obj_thumb.imgfile = file;
	var this_ssbr = this;
	obj_thumb.onclick = function() {this_ssbr.Show(this.imgfile);}

	// fix newts {}
	guid = guid.replace(/&#123;/, '{');
	guid = guid.replace(/&#125;/, '}');
	desc = desc.replace(/&#123;/, '{');
	desc = desc.replace(/&#125;/, '}');

	var shot = {'file':file, 'guid':guid, 'desc':desc, 'username':username, 'game_name':game_name, 'game_link':game_link, 'game_icon':game_icon, 'date':date, 'obj_thumb':obj_thumb};
// 	if(this.curshotgroup=='')
// 	    this.shots = [];    // "lone" group may only have 1 shot
	this.shots.push(shot);
}

//------------------

thisclass.DeleteShot = function(shot)
{
	// delete from all groups
    for(var group in this.shotgroups)
    {
		// get the "real" shot
		var index = this.FindShot(shot.file, group);
		if(index<0)
		    continue;
		this.shotgroups[group].splice(index, 1);
    }
	// update thumbs
	var obj_thumbs = document.getElementById('ssbr_thumbs');
	obj_thumbs.dirty = true;
	if(this.visible)
	{
	    if(this.curshotgroup=='' || this.shots.length==0)
		{
			this.Hide();
		}
		else
		{
			index = this.curidx;
		 	if(index>=this.shots.length)
		 	    index = this.shots.length-1;
	 	    this.curidx = -1;   // refresh
			this.Show(index);
		}
	}
}

//------------------

thisclass.UpdateShot = function(updated_shot)
{
	// update this shot in all groups
    for(var group in this.shotgroups)
    {
		// get the "real" shot
		var index = this.FindShot(updated_shot.file, group);
		if(index<0)
		    continue;
		var shot = this.shotgroups[group][index];
		if(shot!==updated_shot)
		{
		    for(var key in updated_shot)
			{
			    shot[key] = updated_shot[key];
		    }
		}
    }
	if(this.curshot && updated_shot.file==this.curshot.file)
	    this.RefreshShotInfo(this.curshot);
}

//------------------
// group: blank=current

thisclass.FindShot = function(file, group)
{
	var shots;
	if(group && !this.shotgroups[group])
	    return -1;
	else if(group)
		shots = this.shotgroups[group];
	else
	    shots = this.shots;
	// find shot
	for(var i=0 ; i<shots.length ; i++)
	{
	    if(shots[i]['file']==file)
	        break;
	}
	if(shots.length==0 || i>=shots.length)
	    return -1;
	return i;
}

//------------------

// looks for shot info in trigger's ancestors
thisclass.ShowThis = function(trigger)
{
	var shot_info = trigger;
	while(shot_info && shot_info.getAttribute('xffile')==null)
	{
		shot_info = shot_info.parentNode;
	}
	
	if(!shot_info)
	    return;
	// search the right group
	var showidx = this.FindShot(shot_info.getAttribute('xffile'), shot_info.getAttribute('xfgroup'));
	if(showidx!=-1)
	{
		this.ActivateShotGroup(shot_info.getAttribute('xfgroup'));
		this.Show(showidx);
	}
	else
	{
		var working_shot =
		{
			'file':shot_info.getAttribute('xffile'),
			'guid':shot_info.getAttribute('xfguid'),
			'desc':shot_info.getAttribute('xfdesc'),
			'username':shot_info.getAttribute('xfuser'),
			'game_name':shot_info.getAttribute('xfgame_name'),
			'game_link':shot_info.getAttribute('xfgame_link'),
			'game_icon':shot_info.getAttribute('xfgame_icon'),
			'date':shot_info.getAttribute('xfdate')
		};
		this.ActivateShotGroup();
		this.Show(working_shot);
	}
}

//------------------
// locator can be index, file string, or shot

thisclass.Show = function(locator, scroll)
{
    var showidx = -1;
    var shot = false;
	if(typeof(locator)=='object')
	    shot = locator;
	else if(typeof(locator)=='string')
	    showidx = this.FindShot(locator);
	else
	    showidx = locator;
	if(showidx>=0 && showidx<this.shots.length)
		shot = this.shots[showidx];

	// darken & hide
	if(!this.visible)
	{
		HideAds();
		obsc_Show(0.65, (this.page_start? 0 : 150), BindMethod(this, this.Hide));
		obsc_fade_time = 150;
	}

	// set up this shot's links, desc, info
	var obj_img = document.getElementById('ssbr_img');
	var obj_gofull = document.getElementById('ssbr_gofull');
	if(!shot)
	{
		obj_gofull.href = '';
		obj_img.innerHTML = '';
	}
	else
	{
		var path = this.shot_server+"/screenshot/natural/"+shot.file;
		obj_gofull.href = path.replace( /\.jpg$/, ".png" );
		obj_gofull.target = "_blank";
		var path = this.shot_server+"/screenshot/large/"+shot.file;
		obj_img.innerHTML = "<img src='"+path+"'>";
	}
    this.RefreshShotInfo(shot);

	// thumbstrip
	this.ScrollThumbs(0, showidx, scroll);
	var obj_ssbr = document.getElementById('ssbr');
	var obj_main = document.getElementById('ssbr_main');
	if(this.curshotgroup=='')
	{
		obj_ssbr.style.width = (this.width-111)+'px';
 	    obj_main.style.left = '0px';
	}
	else
	{
		obj_ssbr.style.width = this.width+'px';
 	    obj_main.style.left = '';
	}
	if(!this.visible)
	{
		var obj_ssbr = document.getElementById('ssbr');
		CenterAndShow(obj_ssbr);
		this.visible = true;
		this.ObscureSelf(false);
	}

	// ad - after display, due to ad blockers
	setTimeout(BindMethod(this, this.AdUpdate), 1);

	this.curidx = showidx;
	this.curshot = shot;
	this.page_start = false;
	if(this.plugin && this.plugin.AfterShow) this.plugin.AfterShow();
}

//------------------

thisclass.RefreshShotInfo = function(shot)
{
	if(shot)
	{
 	    var desc = shot.desc;
 	    var info = this.strings['taken by']+" <a href='/profile/"+shot.username+"/'><b>"+shot.username+"</b></a> "+this.strings['on date']+" "+shot.date;
	}
	else
	{
	    var desc = this.strings['no image'];
	    var info = '';
	}

	var obj_desc = document.getElementById('ssbr_img_desc');
	// do not use innerHTML! it will unescape
	while(obj_desc.hasChildNodes())
	{
			obj_desc.removeChild(obj_desc.firstChild);
	}
	//obj_desc.appendChild(document.createTextNode(desc));
	var desc_span = document.createElement( 'span' );
	desc_span.appendChild(document.createTextNode(desc));
	obj_desc.appendChild( desc_span );
	
	obj_desc.style.display = (desc? 'block' : 'none');
 	var obj_info = document.getElementById('ssbr_img_info');
 	obj_info.innerHTML = info;
	var obj_extra = document.getElementById('ssbr_top_extra');
	if(shot.game_name)
		obj_extra.innerHTML = "<img src='"+this.media_server+"/xfire/xf/images/icons/"+shot.game_icon+".gif' /><a href='"+shot.game_link+"'>"+shot.game_name+"</a>";
	else
	    obj_extra.innerHTML = '';
	var obj_editbar = document.getElementById('ssbr_toolbar_editing');
	// can edit?
	if(!shot.guid)
	{
	    if(obj_editbar)
			obj_editbar.style.display = 'none';
	}
	// gallery link
	var obj_gallerylink = document.getElementById('ssbr_gogallery');
	if(this.user_gallery!=shot.username)
	{
		obj_gallerylink.style.display = '';
		obj_gallerylink.href = '/profile/'+shot.username+'/screenshots/';
	}
	else
	{
		obj_gallerylink.style.display = 'none';
	}
}


//------------------

thisclass.ScrollThumbs = function(move, showidx, scroll)
{
	if(typeof(showidx)=='undefined')
		showidx = -1;
	// thumbs
	var obj_thumb_strip = document.getElementById('ssbr_thumb_strip');
	if(this.curshotgroup=='' || this.shots.length==0 || (this.shots.length==1 && showidx!=-1))
	{
	    obj_thumb_strip.style.display = 'none';
		return;
	}
    obj_thumb_strip.style.display = '';
	var redraw = !this.visible;
	var old_thumb_start = this.thumb_start,
		thumb_start_max = Math.max(0, this.shots.length-this.thumb_max);
    if(showidx!=-1)
    {
        // calc thumb pos
		if(this.curidx-this.thumb_start!=Math.floor(this.thumb_max/2))
		    scroll = false;
		if(this.thumb_start==-1)
		    this.thumb_start = Math.max(0, showidx-Math.floor(this.thumb_max/2));
		else if(scroll && Math.abs(showidx-this.curidx)==1)
			this.thumb_start += (showidx-this.curidx);
		var min = Math.max(0, showidx-(this.thumb_max-1)),
			max = Math.min(thumb_start_max, showidx);
		if(this.thumb_start>max)
		    this.thumb_start = max;
		if(this.thumb_start<min)
		    this.thumb_start = min;
	}
	if(move)
	{
	    this.thumb_start += move;
	    this.thumb_start = Math.max(this.thumb_start, 0);
	    this.thumb_start = Math.min(this.thumb_start, thumb_start_max);
	}
	if(old_thumb_start!=this.thumb_start)
		redraw = true;
	var obj_thumbs = document.getElementById('ssbr_thumbs');
	if(obj_thumbs.dirty)
		redraw = true;
	// arrows
	var obj = document.getElementById('ssbr_thumb_prev');
	if(this.thumb_start<=0)
		obj.className = "ssbr_thumb_prev_off";
	else
		obj.className = "ssbr_thumb_prev";
	var obj = document.getElementById('ssbr_thumb_next');
	if(this.thumb_start>=thumb_start_max)
		obj.className = "ssbr_thumb_next_off";
	else
		obj.className = "ssbr_thumb_next";
	if(redraw)
	{
		while(obj_thumbs.hasChildNodes())
		{
			obj_thumbs.removeChild(obj_thumbs.firstChild);
		}
	}
	var activeidx = (showidx==-1? this.curidx : showidx);
	for(var i=0 ; i<this.thumb_max ; i++)
	{
		if(this.thumb_start+i>=this.shots.length) break;
		var obj_thumb;
		if(redraw)
		{
			var shot = this.shots[this.thumb_start+i];
			obj_thumb = shot.obj_thumb;
			obj_thumbs.appendChild(obj_thumb);
		}
		else
		{
		    obj_thumb = obj_thumbs.childNodes[i];
		}
		if(!obj_thumb.src)
			obj_thumb.src = this.shot_server+"/screenshot/thumb/"+obj_thumb.imgfile;
		obj_thumb.className = "ssbr_thumb" + (this.thumb_start+i==activeidx? " ssbr_thumb_active" : "");
	}
}

//------------------

thisclass.Hide = function()
{
	if(this.plugin && this.plugin.Hide && !this.plugin.Hide())
	{
		return;
	}
	var obj = document.getElementById('ssbr');
	obj.style.display = 'none';
	this.visible = false;
	obsc_Hide();
	ShowAds();
}

//------------------

thisclass.ObscureSelf = function(hide)
{
	var obj = document.getElementById('ssbr');
	obj.style.zIndex = (hide? 100 : 2000);
}

//------------------

thisclass.AdUpdate = function()
{
	if(this.plugin && this.plugin.AdUpdate && !this.plugin.AdUpdate())
		return;
	var date = new Date();
	// bug 8081: I don't know why Adam added this at all, makes no sense
	//if(this.ad_time && date.getTime()-this.ad_time<this.ad_seconds*1000)
	//    return;

	var iframe = document.getElementById('ssbr_adframe');
	var link = this.ad_link.replace(/\[random\]/g, Math.floor(Math.random()*1000000000));
	link = link.substring(0,(link.length-1)) + ((this.ad_counter++ % 3));
	iframe.src = link;
	this.ad_time = date.getTime();
// 	var doc = iframe.contentWindow.document;
// 	doc.open();
// 	doc.write(html);
// 	doc.close();
}

//------------------

thisclass.ImageClick = function()
{
	if(this.plugin && this.plugin.ImageClick && !this.plugin.ImageClick())
		return;
	if(this.curshotgroup=='')
	    this.Hide();
	else
		this.Next(true);
}

//------------------

thisclass.Next = function(wrap)
{
    var showidx = this.curidx+1;
 	if(showidx>=this.shots.length)
 	{
 	    if(!wrap)
 	        return;
 	    showidx = 0;
 	}
	this.Show(showidx, true);
	this.ShiftFocus();
}

//------------------

thisclass.Prev = function(wrap)
{
    var showidx = this.curidx-1;
 	if(showidx<0)
 	{
 	    if(!wrap)
 	        return;
		showidx = this.shots.length-1;
 	}
	this.Show(showidx, true);
	this.ShiftFocus();
}

//------------------

thisclass.Share = function()
{
	if(!this.curshot)
		return;
	ssmg.SharerShow(this.curshot);
	this.ShiftFocus();
}

//------------------

thisclass.Edit = function()
{
	if(!this.curshot)
		return;
	ssmg.EditorShow(this.curshot);
	this.ShiftFocus();
}

//------------------

thisclass.Delete = function()
{
	if(!this.curshot)
		return;
	ssmg.DeleterShow(this.curshot);
	this.ShiftFocus();
}

//------------------
//
//
// CLASS ScreenShotManager
//
//
//------------------

function ScreenShotManager(ssbr, web_server, shot_server, media_server)
{
	this.ssbr = ssbr;
	this.web_server = web_server;
	this.shot_server = shot_server;
	this.media_server = media_server;

	this.strings = {};
	this.bg_obscured = false;
	this.working_shot = null;
	this.working_shotbox = null;
	this.mini_desc_shotbox = null;

	this.sharer_open = false;
	this.editor_open = false;
	this.deleter_open = false;
	this.closing = false;
	this.save_obsc_callback = -1;
}
var thisclass = ScreenShotManager.prototype;

//------------------

thisclass.ObscureBG = function(hide)
{
	if(hide==this.bg_obscured)
	    return;
	if(this.ssbr && this.ssbr.visible)
	{
	    if(hide)
	    {
			this.save_obsc_callback = obsc_close_callback;
			obsc_close_callback = BindMethod(this, this.Close);
		}
		else if(this.save_obsc_callback!=-1)
		{
			obsc_close_callback = this.save_obsc_callback;
		}
		this.ssbr.ObscureSelf(hide);
	}
	else
	{
	    if(hide)
	    {
			HideAds();
			obsc_Show(0.65, 150, BindMethod(this, this.Close));
		}
	    else
	    {
			obsc_Hide();
			ShowAds();
		}
	}
	this.bg_obscured = hide;
}

//------------------

thisclass.SetWorkingShot = function(file_or_shot)
{
	if(!file_or_shot)
	{
	    this.working_shot = null;
		this.working_shotbox = null;
	    return null;
    }
	if(this.working_shot!=null)
	    return null;
	if(typeof(file_or_shot)=='string')
	{
		this.working_shotbox = this.FindShotBox(document, file_or_shot);
		this.working_shot =
		{
			'file':file_or_shot,
			'guid':this.working_shotbox.getAttribute('xfguid'),
			'desc':this.working_shotbox.getAttribute('xfdesc'),
			'username':this.working_shotbox.getAttribute('xfuser'),
			'game_name':this.working_shotbox.getAttribute('xfgame_name'),
			'game_link':this.working_shotbox.getAttribute('xfgame_link'),
			'game_icon':this.working_shotbox.getAttribute('xfgame_icon'),
			'date':this.working_shotbox.getAttribute('xfdate')
		};
	}
	else
	{
	    this.working_shot = file_or_shot;
		this.working_shotbox = this.FindShotBox(document, this.working_shot.file);
	}
	return this.working_shot;
}

//------------------

thisclass.FindShotBox = function(parent, file)
{
	var shotboxes = GetElements(parent, 'DIV', 'screenshot');
	for(var i=0 ; i<shotboxes.length ; i++)
	{
	    var shotbox = shotboxes[i];
	    if(file==shotbox.getAttribute('xffile'))
	    {
			if(!shotbox.getAttribute('xfdeleted'))
			    return shotbox;
		}
	}
	return null;
}

//------------------
// looks for shot info in trigger's ancestors

thisclass.ShowMiniDesc = function(trigger)
{
	var minidesc = document.getElementById('ssmg_mini_desc');
	if(!trigger)
	{
	    minidesc.style.display = 'none';
	    this.mini_desc_shotbox = null;
	    return;
	}
	// find shotbox
	var shotbox = trigger;
	while(shotbox && shotbox.getAttribute('xffile')==null)
	{
		shotbox = shotbox.parentNode;
	}
	if(!shotbox)
	    return;

	if(this.mini_desc_shotbox && (shotbox!==this.mini_desc_shotbox))
	    minidesc.style.display = 'none';
	this.mini_desc_shotbox = shotbox;
    var desc = shotbox.getAttribute('xfdesc');
    if(!desc)
    {
		this.ShowMiniDesc();
	    return;
    }
//		var obj = GetFirstChild(minidesc, '', 'desc');  // why doesnt this work?
	var obj = document.getElementById('ssmg_mini_desc_desc');
	// do not use innerHTML! it will unescape
	while(obj.hasChildNodes())
	{
		obj.removeChild(obj.firstChild);
	}
	obj.appendChild(document.createTextNode(desc));
	var obj_img = GetFirstChild(shotbox, 'IMG', 'img');
	var parent = obj_img.parentNode;
	if(parent.tagName!='DIV')
	    parent = parent.parentNode;
	parent.appendChild(minidesc);
	var self = this;
//	minidesc.onclick = function() {self.ssbr.Show(self.mini_desc_shotbox.getAttribute('xffile'));}
	minidesc.onclick = function() {eval(obj_img.getAttribute('onclick'));}
    minidesc.style.display = 'block';
}

//------------------

thisclass.MiniDescClick = function()
{
	if(!this.mini_desc_shotbox)
	    return;

	var link = this.mini_desc_shotbox.getAttribute('xflink');
	if(link)
	    document.location = link;
	else
		this.ssbr.ShowThis(this.mini_desc_shotbox);
}

//------------------

thisclass.Save = function(stage)
{
	var done = false;
	if(this.editor_open)
	    done = this.EditorWrite(stage);
	else if(this.deleter_open)
	{
	    done = this.DeleterWrite(stage);
	    // Force refresh the page, since the screenshot hide method isn't enough
	    setTimeout("window.location.reload();", 600);
	}
	return done;
}

//------------------

thisclass.Close = function()
{
	if(this.sharer_open)
	    this.SharerClose();
	if(this.editor_open)
	    this.EditorClose();
	if(this.deleter_open)
	    this.DeleterClose();
    this.ObscureBG(false);
	this.SetWorkingShot();
    this.closing = false;
}

//------------------

thisclass.SaveAndClose = function()
{
	this.closing = true;
	var done = this.Save();
	if(done)
		this.Close();
}

//------------------

thisclass.AjaxComplete = function(req)
{
	if(req.responseText=='ok')
	{
		var done = this.Save(1);
		if(done && this.closing)
			this.Close();
	}
	else
	{
		alert(this.strings['update error']);
	}
}

//------------------

thisclass.SharerShow = function(file_or_shot)
{
	this.Close();
	var shot = this.SetWorkingShot(file_or_shot);
	if(!shot)
	    return;

	var obj_img = document.getElementById('ssmg_sharer_img');
	obj_img.src = this.shot_server+"/screenshot/small/"+shot.file;
	this.SharerUpdate();
	var obj_sharer = document.getElementById('ssmg_sharer');
	this.ObscureBG(true);
	CenterAndShow(obj_sharer);
	this.sharer_open = true;
}

//------------------

thisclass.SharerUpdate = function()
{
	if(!this.working_shot)
	    return;
	var shot = this.working_shot;

	var user_url = this.web_server+"/profile/"+shot.username+"/screenshots/?ss_file="+shot.file;
	var obj = document.getElementById('ssmg_sharer_friends');
	obj.value = user_url;

	var select = document.getElementById('ssmg_sharer_size');
	var size = select.options[select.selectedIndex].value;
	var img_url = this.shot_server+"/screenshot/"+size+"/"+shot.file;

	var obj = document.getElementById('ssmg_sharer_bbcode');
	obj.value = "[URL="+user_url+"][IMG]"+img_url+"[/IMG][/URL]";
	var obj = document.getElementById('ssmg_sharer_html');
	obj.value = "<a href='"+user_url+"'><img src='"+img_url+"'></a>";
}

//------------------

thisclass.SharerClose = function()
{
	var obj_sharer = document.getElementById('ssmg_sharer');
	obj_sharer.style.display = 'none';
	this.sharer_open = false;
}

//------------------

thisclass.EditorShow = function(file_or_shot)
{
	this.Close();
	var shot = this.SetWorkingShot(file_or_shot);
	if(!shot)
	    return;

	var obj_img = document.getElementById('ssmg_editor_img');
	obj_img.src = this.shot_server+"/screenshot/small/"+shot.file;
	var obj = document.getElementById('ssmg_editor_text');
	obj.value = shot.desc;
	var obj_editor = document.getElementById('ssmg_editor');
	this.ObscureBG(true);
	CenterAndShow(obj_editor);
	this.editor_open = true;
}

//------------------

thisclass.EditorWrite = function(stage)
{
	if(stage==null)
	    stage = 0;
	if(!this.working_shot)
	    return true;
	var shot = this.working_shot;
	var obj = document.getElementById('ssmg_editor_text');
	var desc = obj.value;
	switch(stage)
	{
    // update db
	case 0:
		AjaxRequest.post({
			'url':"/ajax_screenshots/?mode=set_description",
			'parameters':{
				'username':shot.username,
				'guid':shot.guid,
				'description':desc
			},
			'onComplete':BindMethod(this, this.AjaxComplete)
		});
		break;

	// update js
	case 1:
		shot.desc = desc;
		if(this.ssbr)
			this.ssbr.UpdateShot(shot);

		if(this.working_shotbox)
		{
			this.working_shotbox.setAttribute('xfdesc', desc);
			var obj_img = GetFirstChild(this.working_shotbox, 'IMG', 'img');
			if(obj_img)
				obj_img.title = desc;
		}
		return true;
	}
	return false;
}

//------------------

thisclass.EditorClose = function()
{
	var obj_editor = document.getElementById('ssmg_editor');
	obj_editor.style.display = 'none';
	this.editor_open = false;
}

//------------------

thisclass.DeleterShow = function(file_or_shot)
{
	this.Close();
	var shot = this.SetWorkingShot(file_or_shot);
	if(!shot)
	    return;

	var obj_img = document.getElementById('ssmg_deleter_img');
	obj_img.src = this.shot_server+"/screenshot/small/"+shot.file;
	var obj_deleter = document.getElementById('ssmg_deleter');
	this.ObscureBG(true);
	CenterAndShow(obj_deleter);
	this.deleter_open = true;
}

//------------------

thisclass.DeleterWrite = function(stage)
{
	if(stage==null)
	    stage = 0;
	if(!this.working_shot)
	    return true;
	var shot = this.working_shot;
	switch(stage)
	{
    // update db
	case 0:
		AjaxRequest.post({
			'url':"/ajax_screenshots/?mode=delete",
			'parameters':{
				'username':shot.username,
				'guid':shot.guid
			},
			'onComplete':BindMethod(this, this.AjaxComplete)
		});
		break;

	// update js
	case 1:
		if(this.working_shotbox)
		{
		    this.working_shotbox.style.display = 'none';
// 			this.working_shotbox.setAttribute('xfdeleted', 1);
// 			var obj_img = GetFirstChild(this.working_shotbox, 'IMG', 'img');
// 			if(obj_img)
// 			{
// 				var obj_imgdel = document.createElement("img");
// 				obj_imgdel.className = 'screenshots_gallery_img_del';
// 				obj_imgdel.src = this.media_server+'/v4/common/ss_delete.png';
// 				obj_imgdel.style.left = obj_img.offsetLeft+"px";
// 				obj_imgdel.style.top = obj_img.offsetTop+"px";
// 				obj_img.parentNode.appendChild(obj_imgdel);
// 			}
		}

		// last, in case it closes (obsc limitation)
		if(this.ssbr)
			this.ssbr.DeleteShot(shot);

		return true;
	}
	return false;
}

//------------------

thisclass.DeleterClose = function()
{
	var obj_deleter = document.getElementById('ssmg_deleter');
	obj_deleter.style.display = 'none';
	this.deleter_open = false;
}

//------------------
