
//var Toolbox = Class.create();
//Toolbox.prototype = {
var Toolbox = Class.create({
  initialize: function(imgelm, saveelm, bid, path) {
    this.path = path;
	this.backend = path + 'backend/';
	this.bid = bid;
	this.imgelm = $(imgelm);
	this.saveelm = $(saveelm);
	this.angle = 0;
	this.session = cookie_read('gojalla_session');
	Element.hide(this.saveelm);
  },

  rotate_clockwise: function() {
	this.angle += 90;
	if (this.angle >= 360)
		this.angle = 0;
	this.preview();
	Element.show(this.saveelm);
  },

  rotate_anticlockwise: function() {
	this.angle -= 90;
	if (this.angle <= -360)
		this.angle = 0;
	this.preview();
	Element.show(this.saveelm);
  },
  
  preview: function() {
	var tmp = new Image();
	tmp.src = this.backend + 'rotateBlog.php?bid=' +this.bid + '&a=' + this.angle; 
	var obj = this;
	tmp.onload = function() { obj.imgelm.src = this.src; }; 
  },
  save: function() {
	var obj = this;
	var handler = function(req) {
		Element.hide(obj.saveelm);
	};

	var pars = 'cmd=save&bid='+this.bid+'&a=' + this.angle +
	    '&jsc='+this.session;
	var req = new Ajax.Request(this.backend + 'rotateBlog.php',
		{ method: 'get', parameters: pars, onComplete: handler});
  }
});

