// Remove a photo from Saved Items
function initAutoFilter(selector) {

	//set up advanced filtering dropdown menus
	$(selector).each(function(){
		var itemtype = $(this).attr('itemtype');
		var currentSort = $(this).find(':checked + label').text() + " " + itemtype;
		var $sortForm = $('form', this);
		
		//Set up new structure and CSS for the menu
		$(this).css({
			position:'absolute',
			padding: '0',
			top:'22px',
			left:'70px',
			zIndex:'10',
			width:'150px',
			color:'#000',
			fontWeight:'normal'
		}).prepend(
			$('<div/>').attr({ className:'currentFilter' }).text(currentSort)
		).find('.formTitle').css({
			display:'block',
			position:'absolute',
			top:'2px',
			left:'-108px',
			width:'100px',
			textAlign:'right',
			color:'#FFF',
			fontSize:'12px',
			fontWeight:'bold'
		}).end().find('.filterOptionsBox').css({
			border:'none',
			padding:'0',
			backgroundColor:'#FFF',
			border:'1px solid #999999',
			borderTop:'0',
			padding:'0',
			display:'none'
		}).find('.formSubmit').css({
			display:'none'
		}).end().find('p').css({
			display:'none'
		}).end().find('.filterOption').css({
			float:'none',
			margin:'0',
			padding:'0'
		}).find('label').css({
			display:'block',
			padding:'3px 6px',
			cursor:'pointer'
		}).hover(
			function(){
				$(this).css({
					backgroundColor:'#AC0535',
					color:'#FFF',
					fontWeight:'bold'
				});
			},
			function(){
				$(this).css({
					backgroundColor:'#FFF',
					color:'#000',
					fontWeight:'normal'
				});
			}
		).click(function(e){
			$(this).parent().parent().find(':checked').attr('checked', '');
			$(this).prev(':radio').attr('checked', 'checked').change();
			currentSort = $(this).text() + " " + itemtype;
			$('.currentFilter').text(currentSort);
			e.preventDefault();
			
			$sortForm.submit();
		
		}).end().find(':radio').change(function(){
			//insert handler code for changing the sort option
			
			
		}).css({ display: 'none' });
		
		//set up menu functionality
		//taken and modified from tuturial on jqueryfordesigners.com
		var hideDelayTimer = null;
		var beingShown = false;
		var shown = false;
		var trigger = $('.currentFilter', this);
		var menu = $('.filterOptionsBox', this);
		
		$([trigger.get(0)]).click(function () {
			if (hideDelayTimer) clearTimeout(hideDelayTimer);
			if (beingShown || shown) {
				menu.slideUp(menuSpeed, function () {
					shown = false;
				});
			} else {
				// reset position of info box
				beingShown = true;
				
				menu.slideDown(menuSpeed, function () {
					beingShown = false;
					shown = true;
				});
			}
			return false;
		});
		
		$([trigger.get(0), menu.get(0)]).mouseover(function () {
			if (hideDelayTimer) clearTimeout(hideDelayTimer);
			return false;
		}).mouseout(function () {
			if (hideDelayTimer) clearTimeout(hideDelayTimer);
			hideDelayTimer = setTimeout(function () {
				hideDelayTimer = null;
				menu.slideUp(menuSpeed, function () {
					shown = false;
				});
	
			}, hideDelay);
	
			return false;
		});
		
	});

}
