window.addEvent('domready', function(){


	function timeFunction(){ 
		$('collectionHover').fade('out');
		$('collectionHoverBG').fade('out');
	};
	
	function timeFunction2(){ 
		$('collectionHover').destroy();
		$('collectionHoverBG').destroy();
	};
	
	var userVar = new Request({ 
		url: 'user.php',

		onRequest: function(txt){
			$('report').empty().addClass('ajax-loading');
			$('report').set('html', '<p class="success">Saving...</p>');

		},	
		onSuccess: function(txt){			
			$('report').empty().removeClass('ajax-loading');
			$('report').set('html', txt);
			
			$('privacy').highlight('#39c');

		}	
	});	
	
	var searchVar = new Request({ 
		url: 'searching.php',

		onRequest: function(txt){
			$('prints').empty().addClass('ajax-loading');
			$('prints').set('html', '<h1 style="text-align:center;">Searching...<h1>');

		},	
		onSuccess: function(txt){			
			$('prints').empty().removeClass('ajax-loading');
			$('prints').set('html', txt);
			
			$('prints').highlight('#39c');
			
			$$('.printWrapper').each(function(item){
				var thisSlider = new Fx.Slide( item.getElement('.info'));
				thisSlider.hide();
				item.getElement( '.print' ).addEvent( 'click', function(){ thisSlider.toggle(); });
			});
		}	
	});	
	
	
	
	
	if($( 'userSave' )){
		$( 'userSave' ).addEvent('click', function(e) {
		
			
			var have = $('user_privacy_have').value;
			var sell = $('user_privacy_sale_trade').value;
			var want = $('user_privacy_want').value;
			var number = $('user_privacy_number').value;
			var info = $('user_privacy_info').value;
			
			
			userVar.post({'have': have, 'sell': sell, 'want': want, 'number': number, 'info': info});	//do the AJAX call


		});
	}
		
	if($( 'search' )){
		$( 'search-form' ).addEvent('submit', function(e){
			searchVar.post($('search-form'));
			return false;
		});
	}
	
	
	if($$( '.edit' )){
	
		$$( '.edit' ).addEvent('click', function(e){
			var printname = this.get('name');

			var hover = new Element('div', {id: 'collectionHover'});
			var hoverContent = new Element('div', {id: 'collectionHoverContent'});
			var hoverBG = new Element('div', {id: 'collectionHoverBG'});
			var closeButton = new Element('img', {id: 'closeButton'});
			closeButton.set('src', 'includes/images/closebox.png');
			
			
			
			hover.inject($('head'), 'after');
			hover.inject($('head'), 'after');
			hoverBG.inject($('head'), 'after');
			hoverContent.inject(hover, 'top');
			closeButton.inject(hover, 'top');
			
			editAjax.post({'n': printname});
			
			
			$('closeButton').addEvent('click', function(e){
				$('collectionHover').fade('out');
				$('collectionHoverBG').fade('out');
				
				var timeFunction = function(){ 
						$('collectionHoverBG').destroy();
						$('collectionHover').destroy();
				};
				timeFunction.delay(500);
			});
			
			hoverBG.addEvent('click', function(e){
				hoverBG.fade('out');
				hover.fade('out');
				
				$clear(timeFunction);
				$clear(timeFunction2);
				//timeFunction3.delay(500);
			});
			return false;
		});	
	}
		
		
		
		
	var editAjax = new Request({ 
		url: 'edit.php',

		onRequest: function(txt){
			$('collectionHoverContent').set('html', '<p>Loading...</p>');
		},	
		onSuccess: function(txt){
			$('collectionHoverContent').set('html', txt);
			
			var editPrint = new Request({ 
				url: 'editPrint.php',
				onRequest: function(txt){
					$('collectionHoverContent').set('html', '<p>Loading...</p>');

				},	
				
				onSuccess: function(txt){
					$('collectionHoverContent').set('html', txt);						
				}
			});
			
			$('submit').addEvent('click', function(e){
			
				editPrint.post($('user-form'));
				
				return false;
			});
		}	
	});			
			

	$$('.printWrapper').each(function(item){
		var thisSlider = new Fx.Slide( item.getElement('.info'));
		thisSlider.hide();
		item.getElement( '.print' ).addEvent( 'click', function(){ thisSlider.toggle(); });
	});
			
	
});	
