function gd_PhotosGallery(params)
{
	this.name=params.name;
	this.photo_ids=new Array();
	this.main_photo=0;
	this.back_photo=0;
	this.background_def="#fff";
	this.path_ajax="";
	this.background_element="body";
	this.lang=new Array();
	if(params.photo_ids)
		this.photo_ids=params.photo_ids;
	if(params.main_photo)
		this.main_photo=params.main_photo;
	if(params.back_photo)
		this.back_photo=params.back_photo;
	if(params.background_def)
		this.background_def=params.background_def;
	if(params.path_ajax)
		this.path_ajax=params.path_ajax;
	if(params.background_element)
		this.background_element=background_element;
	if(params.lang)
		this.lang=params.lang;
}

gd_PhotosGallery.prototype.remove_photo=function(photo_id)
{
	if(this.back_photo==photo_id)
	{
		this.back_photo=0;
		jQuery(this.background_element).css("background",this.background_def);
	}
		
	var temp_arr=[];
	for(var i=0;i<this.photo_ids.length;i++)
	{
		if(this.photo_ids[i]!=photo_id)
			temp_arr.push(this.photo_ids[i]);
	}
	this.photo_ids=temp_arr;
	if(this.main_photo==photo_id)
	{
		if(this.photo_ids.length>0)
			this.main_photo=this.photo_ids[0];
		else
			this.main_photo=0;
		this.rebuild_main_markers();
		jQuery("#album_photo_thumbs").prepend(jQuery("#photo_frame_"+photo_id).replaceWith(""));
	}
	var photos_count=parseInt(jQuery("#photos_count").text())-1;
	jQuery("#photos_count").text(photos_count);
	this.send_request(this.path_ajax+"&del_photo="+photo_id);
	var handler=this;
	if(photos_count)
		jQuery("#photo_frame_"+photo_id).hide("slow");
	else
		jQuery("#photo_frame_"+photo_id).hide("slow",function(){handler.render_no_photos()});
}



gd_PhotosGallery.prototype.background_change=function(photo_id,url)
{
	if(jQuery("#background_photo_switch_"+photo_id).attr("checked"))
	{
		this.back_photo=photo_id;
		this.send_request(this.path_ajax+"&set_back_photo="+photo_id);
		jQuery(this.background_element).css("background","url(\'"+url+"\') repeat");
	}
	else
	{
		this.back_photo=0;
		this.send_request(this.path_ajax+"&clear_back_photo=1");
		jQuery(this.background_element).css("background",this.background_def);
	}
	this.rebuild_back_markers();
}

gd_PhotosGallery.prototype.background_changeGD3=function(photo_id,url)
{
	if(jQuery("#background_photo_switch_"+photo_id).attr("checked"))
	{
		this.back_photo = photo_id;
		this.send_request(this.path_ajax+"&set_back_photo="+photo_id);
		
		jQuery("html").css({"background":"url(\'"+url+"\') repeat","background-position":"left 7em"});
		jQuery("body").css({"background":"none"});

	}
	else
	{
		this.back_photo=0;
		this.send_request(this.path_ajax+"&clear_back_photo=1");
		jQuery("body").css({"background":"url(http://cachei.gamedesire.com/i/gd3/background_top_gradient.png)","background-position":"left 7em","background-repeat":"repeat-x"});
		jQuery("html").css({"background-image":"none","background-color":this.background_def});
	}
	this.rebuild_back_markers();
}


gd_PhotosGallery.prototype.rebuild_back_markers=function()
{
	for(var i=0;i<this.photo_ids.length;i++)
	{
		if(this.photo_ids[i]!=this.back_photo)
			jQuery("#background_photo_switch_"+this.photo_ids[i]).attr("checked",false);
	}
}

gd_PhotosGallery.prototype.set_main_photo=function(photo_id)
{
	this.main_photo=photo_id;
	this.send_request(this.path_ajax+"&set_main_photo="+photo_id);
	this.rebuild_main_markers();
	jQuery("#album_photo_thumbs").prepend(jQuery("#photo_frame_"+photo_id).replaceWith(""));
}

gd_PhotosGallery.prototype.rebuild_main_markers=function()
{
	var handler=this;
	for(var i=0;i<this.photo_ids.length;i++)
	{
		if(this.photo_ids[i]==this.main_photo)
			jQuery("#main_photo_switch_"+this.photo_ids[i]).html(this.lang.main_photo_album);
		else
		{
			var id=this.photo_ids[i];
			jQuery("#main_photo_switch_"+this.photo_ids[i]).html('<a href="javascript:'+this.name+'.set_main_photo('+id+');">'+this.lang.set_main+'</a>');
		}
	}
}
gd_PhotosGallery.prototype.render_no_photos=function()
{
	jQuery("#album_photo_thumbs").html(this.lang.no_photos);
}
gd_PhotosGallery.prototype.send_request=function(url)
{
	jQuery.get(url+"&random_value="+Math.random());
}