var Collections = Class.create({
  initialize: function(path) {
    this.path = path;
	this.backend = path + 'backend/edit/';
  },

  add: function(name, cb) {
	var handler = function(req) {
		var res = JSON.parse(req.responseText);
		if (cb != null)
			cb(res.result);			
	};

	var pars = 'cmd=add&name=' + encodeURIComponent(name);	
	var req = new Ajax.Request(this.backend + 'submitCol.php',
		{ method: 'get', parameters: pars, onComplete: handler});
 },

 del: function(cid, cb) {
	var handler = function(req) {
		var res = JSON.parse(req.responseText);
		if (cb != null)
			cb(res.result);			
	};

	var pars = 'cmd=del&cid=' + cid;	
	var req = new Ajax.Request(this.backend + 'submitCol.php',
		{ method: 'get', parameters: pars, onComplete: handler});
 },

 delblog: function(bid, cb) {
	var handler = function(req) {
		var res = JSON.parse(req.responseText);
		if (cb != null)
			cb(res.result);			
	};

	var pars = 'cmd=del&bid=' + bid;	
	var req = new Ajax.Request(this.backend + 'submitBlog.php',
		{ method: 'get', parameters: pars, onComplete: handler});
 }
});

/*
var BlogDrag = Class.create();
BlogDrag.prototype = (new Rico.Draggable()).extend( {
   initialize: function(htmlElement, bid, col) {
      	this.htmlElement  = $(htmlElement);
		this.type = 'blog';
		this.bid = bid;
		this.col = col; 
   }
} );


var ColDrop = Class.create();
ColDrop.prototype = (new Rico.Dropzone()).extend( {
   initialize: function(htmlElement, cid, col, path) {
      	this.htmlElement  = $(htmlElement);
    	this.path = path;
		this.cid = cid;
		this.col = col;
		this.backend = path + 'backend/edit/';
		this.showingHover = false;
   },

	accept: function(objs) {
		var obj = this;
		var handler = function(req) {
			var res = req.responseText.parseJSON();
			if (res.result == true) {
				objs[0].col.fetchBlogs();
				obj.col.fetchBlogs();
			}
			else {
				alert("Failed to move blog");
			}
		};

		var pars = 'cmd=col&bid='+objs[0].bid + '&cid=' + this.cid;	
		var req = new Ajax.Request(this.backend + 'submitBlog.php',
			{ method: 'get', parameters: pars, onComplete: handler});
		this.htmlElement.appendChild(objs[0].getDroppedGUI());
	},
	activate: function() { },
	deactivate: function() { },
	showHover: function() {
		var htmlElement = this.htmlElement;
		if (htmlElement == null || this.showingHover)
			return;
		this.showingHover = true;
		this.saveBackground = htmlElement.style.background;
		htmlElement.style.background = '#c3c7ff';
	},

	hideHover: function() {
		var htmlElement = this.htmlElement;
		if (htmlElement == null || !this.showingHover)
			return;
		
		htmlElement.style.background = this.saveBackground; 
		htmlElement.style.background = '#ffffff'; 
		this.showingHover = false;
	}


} );
*/

