/******************************************************************************
@owner: SVSi
@author: Arthur Johnson
@function: Action Class
@Action
*******************************************************************************/

//*************  ACTION CLASS  ***************//
	function Action(opts) {
		
		if (undef(opts)) opts = {};
		
		this.type = opts.hasOwnProperty('type') ? opts.type : false;
		
		//this.item = opts.hasOwnProperty('item') ? opts.item : false;
		//this.oldvalue = opts.hasOwnProperty('oldvalue') ? opts.oldvalue : false;
		//this.newvalue = opts.hasOwnProperty('newvalue') ? opts.newvalue : false;
		
		this.items = opts.hasOwnProperty('items') ? opts.items : false;
		this.oldvalues = opts.hasOwnProperty('oldvalues') ? opts.oldvalues : false;
		this.newvalues = opts.hasOwnProperty('newvalues') ? opts.newvalues : false;
		
		this.init();
	}
	Action.prototype = {
		init: function(opts){
			//pb.actionlist.push(this);
		},
		commit: function(opts){
			//if (this.item){
			
			//}
			if (this.items){
				switch (this.type) {
					case 'clone': case 'drop':
						for (var i=0; i<this.items.length; i++){
							this.items[i].restore();
						}
						break;
					case 'delete':
						for (var i=0; i<this.items.length; i++){
							this.items[i].destroy();
						}
						break;
					case 'move':
						for (var i=0; i<this.items.length; i++){
							//console.log(this.items[i]);
							this.items[i].element.style.left = this.newvalues[i].left;
							this.items[i].element.style.top = this.newvalues[i].top;
						}
						break;
					case 'size':
						for (var i=0; i<this.items.length; i++){
							//console.log(this.items[i]);
							this.items[i].element.style.width = this.newvalues[i].width;
							this.items[i].element.style.height = this.newvalues[i].height;
							if (this.items[i].textnode){
								var theight = ($(this.items[i].element).outerHeight()/2)
									- ($(this.items[i].textnode).outerHeight()/2);
								$(this.items[i].textnode).css('top', theight + 'px');
							}
						}
						break;
					case 'style':
						for (var i=0; i<this.items.length; i++){
							//console.log(this.items[i]);
							this.items[i].element.style.cssText = this.newvalues[i].style;
							this.items[i].element.style.backgroundSize = "100% 100%";
							if (this.items[i].textnode){
								var theight = ($(this.items[i].element).outerHeight()/2)
									- ($(this.items[i].textnode).outerHeight()/2);
								$(this.items[i].textnode).css('top', theight + 'px');
							}
						}
						break;
					case 'textoffset':
						for (var i=0; i<this.items.length; i++){
							//console.log(this.items[i]);
							//this.items[i].element.style.cssText = this.newvalues[i].style;
						}
						break;
					default:
						break;
				}
			}
		},
		reverse: function(opts){
			if (this.items){
				switch (this.type) {
					case 'clone': case 'drop':
						for (var i=0; i<this.items.length; i++){
							this.items[i].destroy();
						}
						break;
					case 'delete':
						for (var i=0; i<this.items.length; i++){
							this.items[i].restore();
						}
						break;
					case 'move':
						for (var i=0; i<this.items.length; i++){
							//console.log(this.items[i]);
							this.items[i].element.style.left = this.oldvalues[i].left;
							this.items[i].element.style.top = this.oldvalues[i].top;
						}
						break;
					case 'size':
						for (var i=0; i<this.items.length; i++){
							//console.log(this.items[i]);
							this.items[i].element.style.width = this.oldvalues[i].width;
							this.items[i].element.style.height = this.oldvalues[i].height;
							if (this.items[i].textnode){
								var theight = ($(this.items[i].element).outerHeight()/2)
									- ($(this.items[i].textnode).outerHeight()/2);
								$(this.items[i].textnode).css('top', theight + 'px');
							}
						}
						break;
					case 'style':
						for (var i=0; i<this.items.length; i++){
							//console.log(this.items[i]);
							this.items[i].element.style.cssText = this.oldvalues[i].style;
							this.items[i].element.style.backgroundSize = "100% 100%";
							if (this.items[i].textnode){
								var theight = ($(this.items[i].element).outerHeight()/2)
									- ($(this.items[i].textnode).outerHeight()/2);
								$(this.items[i].textnode).css('top', theight + 'px');
							}
						}
						break;
					case 'textoffset':
						for (var i=0; i<this.items.length; i++){
							//console.log(this.items[i]);
							//this.items[i].element.style.cssText = this.oldvalues[i].style;
						}
						break;
					default:
						break;
				}
			}
		}
	}
//**************  END ACTION  ****************//