//
// 		Wizzard Bulgaria
// 		Plamen Nikolov
// 		14.09.2009
//
//		Web 2.0 Tools
//
	
Event.observe(window, 'load', attachTools);

function attachTools(){

	var areas = $$('div.rich-text, div.rich-text *');
	
	
	$$('#tools a').each(function(el, ind){
		el.observe('click', function(e){
			areas.collect(function(area){
				var fs = parseInt(area.getStyle('font-size'));

				if (el.id == 'tools_reset') {
					fs = 13;
				}
				if (el.id == 'tools_decrease') {
					fs = fs - 1;
				}
				if (el.id == 'tools_increase') {
					fs = fs + 1;
				}
				if (fs > 8 && fs < 20) {
					area.setStyle({
						'fontSize': fs + 'px'
					});
				}
			});
		});
	});
}	


// Send To Friend	
	
var stf = {

	div: null,
	labels: null,

	create: function(title, your_name, your_email, to_email, content, send)
	{	
		stf.labels = {title: title, from_name: your_name, from_email: your_email, to_email: to_email, content: content, send: send}
		
		Wizzard.Mask.show(60);
		
		if (stf.div === null)
		{
			stf.div = new Element('div', {id: 'stf'});
			
			var title = (new Element('div')).update(stf.labels.title);
			title.addClassName('title');
			
			stf.div.insert(title);
			
			var close = (new Element('a', {'href': 'javascript:;'})).update('[x]');
			close.addClassName('close');
			
			close.observe('click', stf.close);
			title.insert({top:close});
			stf.form = new Element('form', {method: 'post', action: ''});

			$A([{name: 'from_name', type: 'input'}, {name: 'from_email', type: 'input'}, {name: 'to_email', type: 'input'}, {name: 'content', type: 'textarea'}]).each(function(obj)
			{
				var label = (new Element('label', {'for': 'id'+obj.name})).update(stf.labels[obj.name]);
				var field = (new Element(obj.type, {id: 'id'+obj.name, name: obj.name}));
				if(obj.name == 'content') {
					field.update(self.location.toString());
				}
				var br = new Element('br');
				stf.form.insert(label).insert((new Element('span', {'class': obj.type})).insert(field)).insert(br);
			});
			
			stf.button = (new Element('button', {type: 'button', 'class': 'send'})).update(stf.labels.send);
			stf.button.observe('click', stf.submit);
			
			stf.form.insert(stf.button);
			stf.div.style.top = parseInt(Wizzard.Mask.getDimensions().height)/2 - 230 + Wizzard.Mask.scroll_offset().top + 'px';
			stf.div.insert(stf.form);
			
			document.body.appendChild(stf.div);
		}
	},

	submit: function(e)
	{
		
		Event.stop(e);
	
		var url = base_url + 'application/xml_http_request?do=send_to_friend';
		
		stf.button.disabled = true;
		new Ajax.Request(url, {
			method: 'post',
			parameters: 'q='+$H($(this.form).serialize(true)).toJSON(),
			onComplete: stf.complete
		});
	},

	complete: function(req)
	{
		var json = req.responseText.evalJSON();
		if(json.js) eval(json.js);
		stf.button.disabled = false;
	},

	close: function()
	{
		stf.div.remove();
		Wizzard.Mask.hide();
		stf.div = null;
	}
};