var inventory = Class.create({
	initialize: function(){

	},
	upload: function(){
		var pars = Form.serialize('upload');

		new Ajax.Updater('ajaxresponse', 'uploaded', {method: 'post', parameters: pars});
	},
	deletePicture: function(ID){
		var pic = ID.slice(3);	
		

        Dialogs.confirm(
                'Are you sure you want to delete this image?',
                function(){
                      	new Ajax.Updater(pic, 'delete', {method: 'post', parameters: 'picID=' + pic});
                        Dialogs.close();
                },
                function(){
                        Dialogs.close();
                }
        );


	},
	deleteItem: function(ID)
	{
		var dID = $('span' + ID).innerHTML;
		
		
	  	Dialogs.confirm(
		  'Are you sure you want to delete all records for this item?',
		  function(){
				  new Ajax.Updater('messanger', 'inventory/deleteitem', {method: 'post', parameters: 'ID=' + dID, oncomplete: $('divspan' + ID).hide() });
				 
				  Dialogs.close();
		  },
		  function(){
				  Dialogs.close();
		  }
		);
	},
	tabSwitch: function(ID){
		$('itemDetailsTab').hide();
		$('itemGalleryTab').hide();
		
		$(ID + 'Tab').show();
	}
});

var general = Class.create({
	initialize: function(){
		return true;
	},
	getLoader: function(){
		$('statusContainer').show();
	},
	showLayer: function(id)
	{
		$(id).show();
	},
	updateFlashmessanger: function(message)
	{
		$('flashMessanger').update(message);
	},
	forgottenPassword: function(){
		var email;
		email =  $F('email');
		if(email != '')
		{
			new Ajax.Updater('flashMessanger', 'forgottenpassword/', {method: 'get', parameters: 'email=' + email});
		}else{
			this.updateFlashmessanger("Please provide an email address");
		}			
	},
	showAlert: function(id)
	{

	}
});

var users = Class.create({
	initialize: function(){

	},
	approve: function(id){
		var pars = 'userID=' + id;
		new Ajax.Updater('userRow' + id, 'admin/approveuser/', {method: 'get', parameters: pars});
	},
	area: function(id){
		this.getAllTabs();
		
		$(id + 'Area').show();
	},
	getAllTabs: function(){
		$('tab1Area').hide();
		$('tab2Area').hide();
		$('tab3Area').hide();
		$('tab4Area').hide();
		$('tab5Area').hide();
		$('tab6Area').hide();
	}
});
Ajax.Responders.register({   
	 onCreate: function() {   
	  $('statusContainer').show();   
	 },   
	 onComplete: function() {   
	  $('statusContainer').hide();   
	 } 
	 });

Event.observe(window, 'load', function(event){
									   
var inv = new inventory();
var gen = new general();
var user = new users();

if($('upload')){
	Event.observe('upload', 'submit', function(){ gen.getLoader(); });
}

if($('forgottenPasswordShow')){
	Event.observe('forgottenPasswordShow', 'click', function(){ gen.showLayer('forgottenPassword'); });	
}

if($('retrievePasswordAction')){
	Event.observe('retrievePasswordAction', 'click', function(){ gen.forgottenPassword(); });	
}

$$('.approveUser').each(function(divID){ 
	Event.observe(divID, 'click', function(){ user.approve(this.id); });
						});

$$('.sectionLink').each(function(divID){ 
	Event.observe(divID, 'click', function(){
										  user.area(this.id);
										   });
						});

$$('.sectionLink').each(function(divID){ 
	Event.observe(divID, 'mouseover', function(){
										  $(this.id).toggleClassName('sectionLinkHover');
									 });
						});
$$('.sectionLink').each(function(divID){ 
	Event.observe(divID, 'mouseout', function(){
										  $(this.id).removeClassName('sectionLinkHover');
											});
						});

$$('.showDel').each(function(divID){ 

	Event.observe(divID, 'mouseover', function(){

										  $('div' + this.id).show();
										   });
	Event.observe(divID, 'mouseout', function(){
										  $('div' + this.id).hide();
										   });
						});
$$('.delImg').each(function(divID){ 
	Event.observe(divID, 'click', function(){
										 inv.deletePicture(this.id);
										   });
						});
$$('.inventoryTabItem').each(function(divID){ 
	Event.observe(divID, 'click', function(){
										 inv.tabSwitch(this.id);
										   });
						});


$$('.deleteItem').each(function(divID){ 
	Event.observe(divID, 'click', function(){
										 inv.deleteItem(this.id);
										   });
						});	
	

	
	
	
	
	
});