
function hideBlock(eThis) {
	eThis.parentNode.className = (eThis.parentNode.className=='block0')?'block1':'block0';
	return false;
}

Event.observe(window, 'load', 	function(){
	$$('.hide-block').each(function(e){
		var eA = $(e.getElementsByTagName('a') || [e])[0];
		if(eA.tagName=='A') eA.addClassName('llink');
		(eA.onclick = function(){
			eA._hide = !eA._hide;
			$A(e.childNodes).each(function(e){if(!eA.descendantOf(e)) (e.style||{}).display = eA._hide?'none':''})
			eA.show();
			return false;
		})();		
	})
	$$('.hblock').each(function(e){
		var eA = $(e).previous('a') || e;
		if(eA.tagName=='A') eA.addClassName('llink');
		eA.onclick = function(){
			e.style.display = (e.style.display=='none')?'':'none';
			return false;
		};
	})
});

function writeEmail(mail, innerHTML, title) {
	mail = mail+'@'+'fly'+'pay.ru';
	document.write('<a title="'+(title||'')+'" href="mail'+'to:'+mail+'">'+(innerHTML||mail)+'</a>');
}

function addOverEvents(element) {
	element = $(element);
	element.onmouseover	= function(){$(this).addClassName('over')}
	element.onmouseout	= function(){$(this).removeClassName('over');}
}

//-----------------------------------------------
function InputPlaceholder (input, value, cssFilled, cssEmpty) {
	var thisCopy = this;
	this.Input = input;
	this.Value = value;
	this.SaveOriginal = (input.value == value);
	this.CssFilled = cssFilled;
	this.CssEmpty = cssEmpty;
	this.setupEvent(this.Input, 'focus', 	function() {return thisCopy.onFocus()});
	this.setupEvent(this.Input, 'blur',  	function() {return thisCopy.onBlur()});
	this.setupEvent(this.Input, 'keydown', 	function() {return thisCopy.onKeyDown()});
	if(input.value == '') this.onBlur();
	return this;
}
InputPlaceholder.prototype.setupEvent = function (elem, eventType, handler) {
	if(elem.attachEvent)		elem.attachEvent('on' + eventType, handler)
	if(elem.addEventListener)	elem.addEventListener(eventType, handler, false)
}
InputPlaceholder.prototype.onFocus = function() {
	if(!this.SaveOriginal &&  this.Input.value == this.Value)
		this.Input.value = ''
	else
		this.Input.className = ''
}
InputPlaceholder.prototype.onKeyDown = function() {
	this.Input.className = ''
}
InputPlaceholder.prototype.onBlur = function() {
	if(this.Input.value == '' || this.Input.value == this.Value) {
		this.Input.value = this.Value
		this.Input.className = this.CssEmpty
	}
	else
		this.Input.className = this.CssFilled
}

//----------- предпросмотр картинок -------------------
var ImageViewer = Class.create();

ImageViewer.prototype = {
	initialize: function(eViewer, options) {
		var pThis = this;
		this.eViewer = eViewer = $(eViewer || 'image-viewer');
		this.eView = eView = eViewer.getElementsByClassName('view')[0];
		this.eA = $A(eViewer.getElementsByTagName('a'));		
		this.imagesSrc = [];
		this.eA.each(function(e, num){
			e = $(e);
			pThis.imagesSrc.push(e.down('img').src);
			e.onclick = function(){ pThis.setImage(num); return false;}
		});
		this.setImage(0);
	},
	
	setImage: function(num) {
		if(this.eActive) this.eActive.removeClassName('active');
		(this.eActive = this.eA[num]).addClassName('active');		
		this.eView.innerHTML = '<img src="'+this.imagesSrc[num]+'"><br>' + this.eActive.title;
	}
}

//-----------------------------------------------------
function onResizeBody(){
	try {
		if(!$('news')) return;
		var width = ($('news').getElementsByClassName('date').last().getWidth()+3)+'px';
		$('content-mainpage').getElementsByClassName('service-info').each(function(e){e.style.width = width});	
	} catch(ex) {}
}

Event.observe(window, 'load', 	onResizeBody);
Event.observe(window, 'resize', onResizeBody);
