
function Vertelka() {
	this.params = {};
	this.callbacks = [];
}

Vertelka.prototype.success = function (data){
	var i;
	for(i=0; i<this.callbacks.length; ++i) {
		this.callbacks[i](data);
	}
}

Vertelka.prototype.ready = function(callback){
		this.callbacks.push(callback)
}

Vertelka.prototype.split_rows = function(text) {
		var rows = text.split("row_closerow_open");
		var row = [];
		rows[0] = rows[0].replace("row_open", ""); 
		var last = rows.length - 1;
		rows[last] = rows[last].replace("row_close", "");
		for (var i=0; i<=rows.length;i++){
			if (rows[i]) {
				row.push(rows[i])
			}
		}
		return row; 
}

Vertelka.prototype.load = function() {
		var url = '/vertelka-proxy'; 

		var params = this.params;

		if(!params){
			params = {};
		}

		if( !params.pad_id ){
			params.pad_id = 20605;
		}
		if( !params.layout ){
			params.layout = 'pic_vitr';
		}
		if( !params.section ){
			params.section = 'revamp';
		}		
		if( !params.trashwords ){
			params.trashwords = 0;
		}
		params.hl = 0;
		//user_ip
		//user_id
		//user_agent
		//x_forwarded_for
		//referer
		//return; //comented
		
		var tmp = this;
                $.ajax({
			url: url, 
			timeout: 5000,
			cache: false,
            data: params,
			dataType : "html",
            success: function (data) { tmp.success(data) }
                });

}

