/*
 * Класс блоговских штук
 */

var Blogger = new Class.create();
Blogger.prototype = {
	initialize: function(options){
		this.options = {
			add_code_name: 'blogger-code',
			add_textarea_name: 'blogger-code-text',
			add_hint_name: 'blogger-code-hint',
			add_texparea_wrapper_name: 'blogger-code-text-wrapper',
			add_code_text: 'Вставить в блог',
			add_code_tpl: '<dl style="box-sizing:border-box;-moz-box-sizing:border-box;width:300px;background:#FFF;border:solid 1px #CCC;font:11px Tahoma,sans-serif;color:#000;overflow:hidden"><dt style="padding:4px 8px 0px 6px;overflow:hidden;1height:15px;height:27px"><a href="http://www.vz.ru#{url}"><img border="0" src="http://www.vz.ru/images/vz_tiny.gif" width="77" height="19" alt="" style="float:left;border:none;vertical-align:middle" /></a><small style="float:right;font-size:10px">#{date}</small></dt><dd style="margin:0"><br style="display:none;"><a href="http://www.vz.ru#{url}"><img border="0" src="#{pic_url}" alt="#{title}" style="display:#{pic_display}!important;border:none;vertical-align:bottom;position:static;" /></a><h3 style="padding:4px 6px 5px;margin:0;background:#CCC;font:bold 11px Tahoma;line-height:12px!important;text-align:left;text-transform:none;"><br style="display:none;"><a href="http://www.vz.ru#{url}" style="text-decoration:none;color:#000;font-style:normal;font-weight:bold!important;border:none;background:none;">#{title}</a></h3><p style="padding:6px;margin:0;line-height:13px!important;text-indent:0;text-align:left;"><a href="http://www.vz.ru#{url}" style="text-decoration:none;color:#000;font:11px Tahoma;border:none;">#{lead}</a> <a href="http://www.vz.ru#{url}" style="text-decoration:none;color:#000;font-size:11px;border:none;"><strong style="text-decoration:underline">Подробнее…</strong></a></p><p style="padding:3px 6px 6px 6px;margin:0;font:11px Tahoma,sans-serif;text-indent:0;text-align:left;"><a href="http://www.vz.ru/" style="text-decoration:none;color:#000;border:none;"><span style="text-decoration:underline">все новости</span></a></p></dd></dl>'
		};
		Object.extend(this.options, options || {});
		this.add_code = $(this.options.add_code_name);
		this.initAddCode();
		this.article_data = {};
	},
	initAddCode: function(data){
		this.add_code.update(this.options.add_code_text);
		this.add_code.onclick = this.toggleCode.bindAsEventListener(this);
	},
	initArticle: function(data){
		this.article_data = data || {};
	},
	toggleCode: function(){
		if (!$(this.options.add_texparea_wrapper_name)) return false;
		if (!$(this.options.add_textarea_name)){
			$(this.options.add_texparea_wrapper_name).update('<div class="clear"></div><div id="' + this.options.add_hint_name + '">Скопируйте код и вставьте в свой блог:</div><textarea readonly id="' + this.options.add_textarea_name + '">' + (new Template(this.options.add_code_tpl)).evaluate(this.article_data) + '</textarea>');
			$(this.options.add_textarea_name).onclick = function(e){
				this.select();
			}
		}else $(this.options.add_texparea_wrapper_name).toggle();
	}
}