// JavaScript

 	function createOverlay(widthPx,heightPX,url)
	{ 
		 var overlay = new Element('div', {
			id: 'overlayRoot',
			styles: {display: 'block', zIndex: '999999',width: widthPx, height: heightPX, 'margin-left': 'auto','margin-right':'auto','top':'-150px'}
		});
	  
		$(document.body).adopt(overlay);
	}
	
	 
	
	function requestPage(page_name,element)
	{
		var loadPage = new Request.HTML({url: page_name,  
		onSuccess: function(htmlImages) 
		{ 
			$(element).set('html', '');
			$(element).adopt(htmlImages);
		}
		}).get();
	}
	
	
	function requestPageComplete(page_name,element,parseClass)
	{
		var loadPage = new Request.HTML({url: page_name,  
		onComplete: function(htmlImages) 
		{ 
			$(element).set('html', '');
			$(element).adopt(htmlImages);
			
			 SqueezeBox.assign($$(parseClass), {
				parse: 'rel'
			});
			 
			 
		}
		}).get();
	}
	
	function requestPageImages(page_name,element,parseClass,parent_id,parent_table)
	{
		var loadPage = new Request.HTML({url: page_name,  
		onComplete: function(htmlImages) 
		{ 
			$(element).set('html', '');
			$(element).adopt(htmlImages);
			
			 SqueezeBox.assign($$(parseClass), {
				parse: 'rel'
			});
				var mySortables = new Sortables('inject_images', {
				constrain: false,
				clone: true,
				opacity:0.2,
				revert: true,
			
				// we now send the call to our script
				onComplete: function() 
				{ 
					var myRequest = new Request
					({ 
						method: 'get', 
						url: '/file_image_order.php',
						data: "parent="+parent_id+"&tbl_id="+parent_table+"&order="+this.serialize(2, 
						function(element, index)
						{
							return element.getProperty('id').replace('item_','');
						})
					}).send();
					
					myRequest.addEvent('complete', function() { $('order_status').set('text','Order updated.'); } );
				}
			}); 
			 
		}
		}).get();
			
	}
	
	function submitListing()
	{
		var myFx = new Fx.Scroll(window);
	
		 
		$('listing_form').addEvent('submit', function(e) {
		//Prevents the default submit event from loading a new page.
		e.stop(); 
		

		//Empty the log and show the spinning indicator.
		var log = $('log_results').empty().addClass('ajax-loading');
		myFx.toElement('logo');
		//Set the options of the form's Request handler. 
		//("this" refers to the $('myForm') element).
		this.set('send', {
			onComplete: function(response) { 
			log.removeClass('ajax-loading');
			log.set('html', response);
			
			

		}});
		//Send the form.
		this.send();
		});
		
		return true;
	}
	
	
	function submitListingInject(updateElement,updateURL,parseClass)
	{
		var myFx = new Fx.Scroll(window);
	
		 
		$('listing_form').addEvent('submit', function(e) {
		//Prevents the default submit event from loading a new page.
		e.stop(); 
		
		//Empty the log and show the spinning indicator.
		var log = $('log_results').empty().addClass('ajax-loading');
		myFx.toElement('logo');
		//Set the options of the form's Request handler. 
		//("this" refers to the $('myForm') element).
		this.set('send', {
			onComplete: function(response) { 
			log.removeClass('ajax-loading');
			log.set('html', response);
			
			
			requestPageComplete(updateURL,updateElement,parseClass);

		}});
		//Send the form.
		this.send();
		});
		
		return true;
	}
	
	function updateDetails()
	{
		
		var myFx = new Fx.Scroll(window);
		
		$('details_form').addEvent('submit', function(e) {
		//Prevents the default submit event from loading a new page.
		e.stop(); 
		
		//Empty the log and show the spinning indicator.
		var log = $('details_log_results').empty().addClass('ajax-loading');
		myFx.toElement('logo');
		//Set the options of the form's Request handler. 
		//("this" refers to the $('myForm') element).
		this.set('send', {
		onComplete: function(response) { 
			log.removeClass('ajax-loading');
			log.set('html', response);
			
			

		}});
		//Send the form.
		this.send();
		});
		
		return true;
		
	}
	
	function updatedPassword()
	{
		
		
		var psFX = new Fx.Scroll(window);
		
		$('password_form').addEvent('submit', function(e) {
		//Prevents the default submit event from loading a new page.
		e.stop(); 
		
		//Empty the log and show the spinning indicator.
		var log = $('password_log_results').empty().addClass('ajax-loading');
		psFX.toElement('password_log_results');
		//Set the options of the form's Request handler. 
		//("this" refers to the $('myForm') element).
		this.set('send', {
		onComplete: function(response) { 
			log.removeClass('ajax-loading');
			log.set('html', response);
			
			

		}});
		//Send the form.
		this.send();
		});
		
		return true;
	}
	
	function slideElement(element,clickReveal)
	{
		var slideFX = new Fx.Slide(element);
		slideFX.hide()
		
		$(clickReveal).addEvent('click', function() { slideFX.toggle(); } );
	}
	
// default page operations

//load in navigation options
requestPage('/session_nav.php','navigation_session');

 