var PhotoCats = Class.create();
PhotoCats.prototype = {
	initialize: function() {
		this.test_string = '';
		this.event_id = eid;
		this.cats = [];
		this.max_thumbs = 52;
		this.photo_dir = '';
		this.ajax_status = [];
		this.curr_cat_index = 0;
		this.curr_photo_index = -1;
		this.selected_photos = [];
		this.loaded_photos = [];
		this.loaded_cats = [];
		this.cat_options_open = false;
		this.photoObserver = [];
	},

	ajaxCall:function(func_name,params,handler) {
		this.ajaxBusy(func_name);
		var file = site_ajax_dir+'photoCats.php';
		var opts = {method:'post',parameters:params,onSuccess:handler,onFailure:function(){alert('something is wrong');}}
		new Ajax.Request(file,opts);
	},
	ajaxBusy:function(func_name) {
		var i = this.ajax_status.indexOf(func_name);
		if (i < 0) { this.ajax_status.push(func_name); }
	},
	ajaxIdle:function(func_name) {
		var i = this.ajax_status.indexOf(func_name);
		if (i > -1) { this.ajax_status.splice(i,1); }
	},
	ajaxRunning:function(func_name) {
		return (this.ajax_status.indexOf(func_name) < 0) ? false : true;
	},
	
	
	init: function() {
		this.getCats();
		this.displayCats();
		
		// set event listeners for menu buttons and thumbs
		Event.observe($('p_cat_actions'),"mouseup",this.catControlsUpEvent.bindAsEventListener(this));
		Event.observe($('p_cat_actions'),"mouseover",this.catControlsOverEvent.bindAsEventListener(this));
		Event.observe($('p_cat_actions'),"mouseout",this.catControlsOutEvent.bindAsEventListener(this));
		
		Event.observe($('p_actions'),"mouseup",this.thumbControlsUpEvent.bindAsEventListener(this));
		Event.observe($('p_actions'),"mouseover",this.thumbControlsOverEvent.bindAsEventListener(this));
		Event.observe($('p_actions'),"mouseout",this.thumbControlsOutEvent.bindAsEventListener(this));
		
		Event.observe($('p_cat_thumbs'),"mouseup",this.thumbsUpEvent.bindAsEventListener(this));
		Event.observe($('p_cat_thumbs'),"mouseover",this.thumbsOverEvent.bindAsEventListener(this));
		Event.observe($('p_cat_thumbs'),"mouseout",this.thumbsOutEvent.bindAsEventListener(this));
		
		Event.observe($('p_cats'),"mouseup",this.catsUpEvent.bindAsEventListener(this));
		Event.observe($('p_cats'),"mouseover",this.catsOverEvent.bindAsEventListener(this));
		Event.observe($('p_cats'),"mouseout",this.catsOutEvent.bindAsEventListener(this));
		
		this.showDefaultCat();
	},
	
	
	showDefaultCat:function() {
		var self = this;
		new PeriodicalExecuter(function(pe) {
			if (!self.ajaxRunning('getCats')) {
				// open first cat
				self.curr_cat_index = 0;
				$('p_cats_menu').firstDescendant().addClassName('focus');
				// display selected cats photos
				self.loadPhotos();
				pe.stop();
			}
		}, .1);
	},
	
	catsUpEvent:function(e) {
		var target_el = Event.element(e);	
		switch (target_el.tagName) {
		case 'LI' :
			var cat_el = target_el;
			var cat_index = 0;
			while (cat_el.previous() != 'undefined' && cat_el.previous() != null) {
				cat_el = cat_el.previous();
				cat_index++;
			}
			if (this.curr_cat_index != cat_index) {
				this.clearAll();
				// close previous cat
				$('p_cats_menu').immediateDescendants()[this.curr_cat_index].removeClassName('focus');
				// open selected cat
				target_el.addClassName('focus');
				// set new cat index
				this.curr_cat_index = cat_index;
				// display new cats photos
				this.loadPhotos();
			}
			break;
		}
	},
	catsOverEvent:function(e) {
		var self = this;
		var target_el = Event.element(e);		
		switch (target_el.tagName) {
		case 'LI' :
			target_el.addClassName('hover');
			break;
		}
	},
	catsOutEvent:function(e) {
		var target_el = Event.element(e);
		var related_el = e.relatedTarget || e.toElement;
		while (related_el != target_el && related_el.nodeName != 'BODY') {
			related_el = related_el.parentNode;
		}
		if (related_el == target_el) return;
		switch (target_el.tagName) {
		case 'LI' :
			target_el.removeClassName('hover');
			break;
		}
	},
	
	getCats:function () {
		var self = this;
		var params = 'event_id=' + this.event_id + '&cmd=getCats';
		var handler = function(resp) {
				//alert(resp.responseText);
				self.cats = resp.responseText.evalJSON();
				self.ajaxIdle('getCats');
				
			}
		this.ajaxCall('getCats',params,handler);
	},
	displayCats:function() {
		this.isLoading('p_cats');
		var self = this;
		var cat_items = '';
		new PeriodicalExecuter(function(pe) {
			if (!self.ajaxRunning('getCats')) {
				self.cats.each(function(cat,cat_index) {
					cat_items += '<li>' + cat.name + '</li>';
				});
				$('p_cats').update('<ul id="p_cats_menu">' + cat_items + '</ul>');
				pe.stop();
			}
		}, .1);
	},
	resetCats:function() {
		if (window.confirm("Are you sure you want to reset everything back to the default setting?")) {
			//ajax remove cat
			var self = this;
			var params = 'event_id=' + this.event_id + '&cmd=resetCats';
			var handler = function(resp) {
					self.ajaxIdle('resetCats');
					self.clearAll();
					self.getCats();
					self.displayCats();
					self.showDefaultCat();
					//alert(resp.responseText);
				}
			this.ajaxCall('resetCats',params,handler);
		}
	},
	
	togggleAddCat:function() {
		if ($('p_cat_actions_menu').getStyle('display') != 'none') {
			$('p_cat_actions_menu').hide();
			$('form_addCat').show();
		} else {
			this.hideAddCat();
		}
	},
	hideAddCat:function() {
		$('new_catName').value = '';
		$('p_cat_actions_menu').show();
		$('form_addCat').hide();
	},
	addCat:function() {
		var new_catName = $('new_catName').value;
		if (new_catName != '' && new_catName != ' ') {
			this.togggleAddCat();
			
			//ajax add cat
			var self = this;
			var params = 'event_id=' + this.event_id + '&cmd=addCat&cat_name=' + new_catName;
			var handler = function(resp) {
					self.ajaxIdle('addCat');
					//alert(resp.responseText);
					var new_cat_info = resp.responseText.evalJSON();
					self.cats.push(new_cat_info);
					new Insertion.Bottom('p_cats_menu','<li>' + new_cat_info.name + '</li>');
				}
			this.ajaxCall('addCat',params,handler);
		} else {
			alert('Please enter a category name.');
		}
	},
	deleteCat:function() {		
		if (this.cats[this.curr_cat_index].id > 0) {
			if (window.confirm("Are you sure you want to delete this category?")) {
				var ajax_cat_id = this.cats[this.curr_cat_index].id;
				// move photos back to default category
				var self = this;
				if (this.cats[this.curr_cat_index].photos.length > 0) {
					this.cats[this.curr_cat_index].photos.each(function(photo) {
					  	self.cats[0].photos.push(photo);
					});
				}
				
				//remove the cat from the cat menu
				$('p_cats_menu').down(this.curr_cat_index).remove();
				
				//reset selected photos
				this.clearAll();
					
				// remove the cat from the array and compact
				this.cats.splice(this.curr_cat_index,1);
				
				//ajax remove cat
				var params = 'event_id=' + this.event_id + '&cmd=deleteCat&cat_id=' + ajax_cat_id;
				var handler = function(resp) {
						self.ajaxIdle('deleteCat');
						//alert(resp.responseText);
					}
				this.ajaxCall('deleteCat',params,handler);
				
				// reset photo thumbnails to default category
				this.showDefaultCat();
			}
		} else {
			alert('Cannot delete the current category.');
		}
	},
	toggleRenameCat:function() {
		if ($('p_cat_actions_menu').getStyle('display') != 'none') {
			$('rename_catName').value = this.cats[this.curr_cat_index].name;
			$('p_cat_actions_menu').hide();
			$('form_renameCat').show();
		} else {
			this.hideRenameCat();
		}
	},
	hideRenameCat:function(){
		$('p_cat_actions_menu').show();
		$('form_renameCat').hide();
	},
	renameCat:function() {
		var rename_catName = $('rename_catName').value;
		if (rename_catName != '' && rename_catName != ' ') {
			this.cats[this.curr_cat_index].name = rename_catName;
			//change the category link name in the menu
			$('p_cats_menu').down('li',this.curr_cat_index).update(rename_catName);
			
			$('rename_catName').value = '';
			this.toggleRenameCat();

			// ajax rename cat
			var self = this;
			var params = 'event_id=' + this.event_id + '&cat_id=' + this.cats[this.curr_cat_index].id + '&cmd=renameCat&cat_name=' + rename_catName;
			var handler = function(resp) {
					self.ajaxIdle('renameCat');
					//alert(resp.responseText);
				}
			this.ajaxCall('renameCat',params,handler);
		} else {
			alert('Please enter a category name.');
		}
	},
	
	catControlsUpEvent:function(e) {
		var self = this;
		var target_el = Event.element(e);
		
		switch (target_el.tagName) {
		case 'LI' :
			target_el.removeClassName('hover');
			var f_name = target_el.readAttribute('f_name');
			var f_params = target_el.readAttribute('f_params');
			if (f_params == null) { f_params = ''; }
			
			eval('this.' + f_name + '(' + f_params + ')');
			break;
		}
	},
	catControlsOverEvent:function(e) {
		var self = this;
		var target_el = Event.element(e);		
		switch (target_el.tagName) {
		case 'LI' :
			target_el.addClassName('hover');
			break;
		}
	},
	catControlsOutEvent:function(e) {
		var target_el = Event.element(e);
		var related_el = e.relatedTarget || e.toElement;
		while (related_el != target_el && related_el.nodeName != 'BODY') {
			related_el = related_el.parentNode;
		}
		if (related_el == target_el) return;
		switch (target_el.tagName) {
		case 'LI' :
			target_el.removeClassName('hover');
			break;
		}
	},
	
	thumbsUpEvent:function(e) {
		var self = this;
		var target_el = Event.element(e);		
		switch (target_el.tagName) {
		case 'SPAN' :
			var photo_el = target_el.up('li');
			var photo_index = 0;
			while (photo_el.previous() != 'undefined' && photo_el.previous() != null) {
				photo_el = photo_el.previous();
				photo_index++;
			}

			//TOGGLE RANGE
			if (this.curr_photo_index > -1 && this.curr_photo_index !== photo_index && e.shiftKey) {
				var photos = this.cats[this.curr_cat_index].photos;
				var reverse_selected = false;
				var start_index = this.curr_photo_index;
				var end_index = photo_index;
				if (end_index < start_index) {
					end_index = this.curr_photo_index;
					start_index = photo_index;
					reverse_selected = true;
				}
				var end_loop = end_index + 1;
				for (var i=start_index;i < end_loop;i++) {
					var focus = (i == photo_index) ? true : false;
					this.selectPhoto(i,focus);
				}
			//TOGGLE INDIVIDUAL
			} else {
				if (this.selected_photos.indexOf(photo_index) > -1) {
					this.unselectPhoto(photo_index);
				} else {
					this.selectPhoto(photo_index,true);
				}
			}

			break;
		}
	},
	thumbsOverEvent:function(e) {
		var self = this;
		var target_el = Event.element(e);		
		switch (target_el.tagName) {
		case 'SPAN' :
			var photo_el = target_el.up('li');
			photo_el.addClassName('hover');
			break;
		}
	},
	thumbsOutEvent:function(e) {
		var target_el = Event.element(e);
		var related_el = e.relatedTarget || e.toElement;
		while (related_el != target_el && related_el.nodeName != 'BODY') {
			related_el = related_el.parentNode;
		}
		if (related_el == target_el) return;
		switch (target_el.tagName) {
		case 'SPAN' :
			target_el.up('li').removeClassName('hover');
			break;
		}
	},
	
	thumbControlsUpEvent:function(e) {
		var self = this;
		var target_el = Event.element(e);
		
		switch (target_el.tagName) {
		case 'LI' :
			target_el.removeClassName('hover');
			var f_name = target_el.readAttribute('f_name');
			var f_params = target_el.readAttribute('f_params');
			if (f_params == null) { f_params = ''; }
			eval('this.' + f_name + '(' + f_params + ')');
			break;
		case 'OPTION' :
			var select_el = target_el.up('select');
			if (select_el.id = 'select_catOpts') {
				var select_index = select_el.selectedIndex;
				if (select_index > 0) {
					this.movePhotos();
				}
			}
			break;
		case 'SELECT' :
			if (target_el.id = 'select_catOpts') {
				var select_index = target_el.selectedIndex;
				if (select_index > 0) {
					this.movePhotos();
				}
			}
			break;
		}
	},
	thumbControlsOverEvent:function(e) {
		var self = this;
		var target_el = Event.element(e);		
		switch (target_el.tagName) {
		case 'LI' :
			target_el.addClassName('hover');
			break;
		}
	},
	thumbControlsOutEvent:function(e) {
		var target_el = Event.element(e);
		var related_el = e.relatedTarget || e.toElement;
		while (related_el != target_el && related_el.nodeName != 'BODY') {
			related_el = related_el.parentNode;
		}
		if (related_el == target_el) return;
		switch (target_el.tagName) {
		case 'LI' :
			target_el.removeClassName('hover');
			break;
		}
	},
	
	
	loadPhotos:function() {
		this.isLoading('p_cat_thumbs');
		var total_photos = this.cats[this.curr_cat_index].photos.length;
		
		if (total_photos > 0) {
			if (this.loaded_cats.indexOf(this.cats[this.curr_cat_index].id) < 0) {
				this.loaded_photos.clear();
				
				var self = this;	
				var i = 0;
				var loop = 0;
				var loaded = 0;
				
				for (i=0;i<total_photos;i++) {
					this.loaded_photos[i] = new Image();
					this.loaded_photos[i].src = this.photo_dir + this.cats[this.curr_cat_index].photos[i].filename;
				}
				
				new PeriodicalExecuter(function(pe) {
					if (self.loaded_photos[loaded].complete) {
						loaded++;
						var num_left = self.loaded_photos.length - loaded;
						if (num_left < 1) {
							self.loaded_cats.push(self.cats[self.curr_cat_index].id);
							self.displayPhotos();
							pe.stop();
						} else {
							$('loaded_photos').update(num_left);
						}
						if (loop > 2000) {pe.stop();} // failsafe
					}
					loop++;
					if (loop > 2000) {pe.stop();} // failsafe
				}, .1);
			} else {
				this.displayPhotos();
			}
		} else {
			$('p_cat_thumbs').update('<div class="ajax_msg">No photos exist in this category.</div>');
		}
	},
	displayPhotos:function() {
		var thumbs_list = '<ul id="p_photos_list">';
		var self = this;
		this.cats[this.curr_cat_index].photos.each(function(photo,photo_index) {
			var photo_dom_id = 'photo_' + photo.photo_id;
			var li_class = (photo.on_web != 'y') ? ' class="off_web"' : '';
			thumbs_list += '<li id="' + photo_dom_id + '"' + li_class + ' style="background:url(\'' + self.photo_dir + photo.filename + '\') no-repeat center center;"><span></span></li>';
		});
		thumbs_list += '</ul>';

		// display photo thumbs
		$('p_cat_thumbs').update(thumbs_list);
		
		// make photo thumbs sortable
		//Position.includeScrollOffsets = true;
		//Sortable.create("p_photos_list",{tag:'li',overlap:'horizontal',constraint:false,scroll:'p_cat_thumbs',scrollSensitivity:50,onUpdate:function() { self.updatePhotosPriority(); }});
	},
	
	getPhotoIndex:function(photo_id) {
		var photo_index = -1;
		this.cats[this.curr_cat_index].photos.each(function(photo,index) {
  				if (photo.photo_id === photo_id) {
  					photo_index = index;
  					$break;
  				}
		});
		return photo_index;
	},
	focusPhoto:function(photo_index) {
		if (this.curr_photo_index > -1) {
			$('photo_' + this.cats[this.curr_cat_index].photos[this.curr_photo_index].photo_id).removeClassName('focus');
		}
		$('photo_' + this.cats[this.curr_cat_index].photos[photo_index].photo_id).addClassName('focus');
		this.curr_photo_index = photo_index;
		this.displayPhotoInfo();
	},
	unselectPhoto:function(photo_index) {
		var photo_el = $('photo_' + this.cats[this.curr_cat_index].photos[photo_index].photo_id);
		photo_el.removeClassName('select');
		photo_el.removeClassName('focus');
		
		this.selected_photos[this.selected_photos.indexOf(photo_index)] = null;
		this.selected_photos = this.selected_photos.compact();

		if (this.selected_photos.length > 0) {
			this.focusPhoto(this.selected_photos.last());
		} else {
			this.clearPhotoInfo();
			// hide move-to options if open
			this.hideCatOpts();
		}
	},
	unselectPhotos:function() {
		var self = this;
		this.selected_photos.each(function(photo_index) {
			self.unselectPhoto(photo_index);
		});
	},
	selectPhoto:function(photo_index,focus) {
		var photo_el = $('photo_' + this.cats[this.curr_cat_index].photos[photo_index].photo_id);
		photo_el.addClassName('select');
		if (this.selected_photos.indexOf(photo_index) < 0) { this.selected_photos.push(photo_index); }
		if (focus) { this.focusPhoto(photo_index); } else { photo_el.removeClassName('focus'); }
	},
	selectPhotos:function() {
		var photos = this.cats[this.curr_cat_index].photos;
		var num_photos = photos.length;
		var self = this;
		if (num_photos > 0) {
			photos.each(function(photo,photo_index) {					
				var focus = (photo_index == num_photos - 1) ? true : false;
				self.selectPhoto(photo_index,focus);
			});
		} else {
			alert('No photos are currently in this category.');
		}
	},
	changePhotoStatus:function(status) {
		if (this.selected_photos.length > 0) {
			var ajax_photos = [];
			var self = this;
			this.selected_photos.each(function(photo_index) {
				switch (status) {
				case 'onWeb' :
					self.cats[self.curr_cat_index].photos[photo_index].on_web = 'y';
					$('photo_' + self.cats[self.curr_cat_index].photos[photo_index].photo_id).removeClassName('off_web');
					break;
				case 'offWeb' :
					self.cats[self.curr_cat_index].photos[photo_index].on_web = 'n';
					$('photo_' + self.cats[self.curr_cat_index].photos[photo_index].photo_id).addClassName('off_web');
					break;
				}
				ajax_photos.push(self.cats[self.curr_cat_index].photos[photo_index].photo_id);
			});
			this.unselectPhotos();
			
			//ajax changePhotoStatus
			var params = 'event_id=' + this.event_id + '&cmd=changePhotoStatus&status=' + status + '&photos=' + ajax_photos.toJSON();
			var handler = function(resp) {
					self.ajaxIdle('changePhotoStatus');
					//alert(resp.responseText);
				}
			this.ajaxCall('changePhotoStatus',params,handler);
		} else {
			alert('No photos are currently selected. ' + status);
		}
	},
	
	updatePhotosPriority:function() {
		this.clearAll();
		var tmp,tmp2,photo_index;
		var new_priority_ids = [];
		var new_photos = [];
		var priority_str = Sortable.serialize("p_photos_list"); // p_photos_list[]=22&p_photos_list[]=16& etc ...
		tmp = priority_str.split('&');
		var tmp_len = tmp.length;
		for (var i = 0;i < tmp_len;i++) {
			tmp2 = tmp[i].split('=');
			new_priority_ids[i] = tmp2[1];
			
			//update priority to 
			photo_index = this.getPhotoIndex(tmp2[1]);
			new_photos.push(this.cats[this.curr_cat_index].photos[photo_index]);
		}
		this.cats[this.curr_cat_index].photos = new_photos;
		
		// ajax update priority  - format: (cat_priority + loop)
		var self = this;
		var params = 'event_id=' + this.event_id + '&cmd=updatePhotosPriority&photos=' + new_priority_ids.toJSON();
		var handler = function(resp) {
				self.ajaxIdle('updatePhotosPriority');
				//alert(resp.responseText);
			}
		this.ajaxCall('updatePhotosPriority',params,handler);
	},
	
	displayPhotoInfo:function() {
		var photo_info = '';
		if (this.curr_photo_index > -1) {
			var photo = this.cats[this.curr_cat_index].photos[this.curr_photo_index];
			photo_info += '<dl>';
			photo_info += '<dt>Filename:</dt><dd>' + photo.filename + ' (' + photo.photo_id + ')</dd>';
			var status = (photo.on_web == 'y') ? 'Public viewable' : 'Public hidden';
			photo_info += '<dt>Status:</dt><dd>' + status + '</dd>';
			photo_info += '</dl>';
		}
		$('p_info').update(photo_info);
	},
	clearPhotoInfo:function() {
		$('p_info').update('');
		this.curr_photo_index = -1;
	},
	
	removePhotos:function(e) {
		if (this.selected_photos.length > 0) {
			if (this.curr_cat_index > 0) {
				var ajax_photos = [];
				var photos = this.cats[this.curr_cat_index].photos;
				var self = this;
				
				this.selected_photos.each(function(photo_index) {
					ajax_photos.push(photos[photo_index].photo_id);
					self.cats[0].photos.push(photos[photo_index]);
					$('photo_' + photos[photo_index].photo_id).remove();
					self.cats[self.curr_cat_index].photos[photo_index] = null;
				});
				this.cats[this.curr_cat_index].photos = this.cats[this.curr_cat_index].photos.compact();
				this.selected_photos.clear();
				this.curr_photo_index = -1;
				if (this.cats[this.curr_cat_index].photos.length < 1) {
					$('p_cat_thumbs').update('<div class="ajax_msg">No photos exist in this category.</div>');
				}
				
				//ajax remove photos
				var self = this;
				var params = 'event_id=' + this.event_id + '&cmd=removePhotos&photos=' + ajax_photos.toJSON();
				var handler = function(resp) {
						self.ajaxIdle('removePhotos');
					}
				this.ajaxCall('removePhotos',params,handler);
			} else {
				alert('Photos cannot be removed from the current category.');
			}
		} else {
			alert('No photos are currently selected. remove');
		}
	},
	
	toggleCatOpts:function() {
		if (this.selected_photos.length > 0) {
			if (this.cats.length > 1) {
				if (!this.cat_options_open) {
					var self = this;
					var cat_opts = '<select id="select_catOpts"><option value="">move to ...</option>';
					this.cats.each(function(cat,cat_index) { 
						if (cat_index !== self.curr_cat_index) {
							cat_opts += '<option value="' + cat_index + '">' + cat.name + '</option>';
						}
					});
					cat_opts += '</select>';
					$('photoCats').update(cat_opts);
					$('p_actions_menu').hide();
					$('form_photoCats').show();
					this.cat_options_open = true;
				} else {
					this.hideCatOpts();
				}
			} else {
				alert('There are no other categories available to move photos to.');
			}
		} else {
			alert('No photos are currently selected.');
		}
	},
	hideCatOpts:function() {
		if (this.cat_options_open) {
			$('p_actions_menu').show();
			$('form_photoCats').hide();
			this.cat_options_open = false;
		}
	},
	movePhotos:function() {
		var num_selected_photos = this.selected_photos.length;
		if (num_selected_photos > 0) {
			var ajax_photos = [];
			var to_cat_index = $('select_catOpts').value;
			
			var self = this;
			this.selected_photos.each(function(photo_index) {
				ajax_photos.push(self.cats[self.curr_cat_index].photos[photo_index].photo_id);
				self.cats[to_cat_index].photos.push(self.cats[self.curr_cat_index].photos[photo_index]);
				$('photo_' + self.cats[self.curr_cat_index].photos[photo_index].photo_id).remove();
				self.cats[self.curr_cat_index].photos[photo_index] = null;
			});
			
			this.cats[this.curr_cat_index].photos = this.cats[this.curr_cat_index].photos.compact();
			
			this.hideCatOpts();
			this.cat_options_open = false;
			this.selected_photos.clear();
			this.curr_photo_index = -1;
			this.clearPhotoInfo();
			if (this.cats[this.curr_cat_index].photos.length < 1) {
				$('p_cat_thumbs').update('<div class="ajax_msg">No photos exist in this category.</div>');
			}

			//ajax move photos
			var params = 'event_id=' + this.event_id + '&cat_id=' + this.cats[to_cat_index].id + '&cmd=movePhotos&photos=' + ajax_photos.toJSON();
			var handler = function(resp) {
					self.ajaxIdle('movePhotos');
					//alert(resp.responseText);
				}
			this.ajaxCall('movePhotos',params,handler);
		} else {
			alert('No photos are currently selected. move');
		}
	},
	
	clearAll:function() {
		this.hideCatOpts();
		this.clearPhotoInfo();
		this.unselectPhotos();
		this.selected_photos.clear();
		
		this.hideAddCat();
		this.hideRenameCat();
	},
	isLoading:function(id) {
		var msg;
		switch(id) {
		case 'p_cat_thumbs' :
			msg = 'Loading <span id="loaded_photos"></span> photos, please be patient ...';
			break;
		default :
			msg = 'Loading ...';
			break;
		}
		$(id).update('<div class="ajax_msg" id="loading_' + id + '">' + msg + '</div>');
	}
}