/*
 * Класс переключения страницы для печати
 */
var PrintSwitcher = new Class.create();
PrintSwitcher.prototype = {
	DEBUG: false,
	initialize: function(print_link){
		this.print_link = $(print_link);
		this.isPrint = false;
		this.print_link.onclick = this.toggle.bindAsEventListener(this);
		window.onbeforeprint = window.onafterprint = this.toggleNonPrintableHelper.bindAsEventListener(this);
	},
	toggleNonPrintableHelper: function(){
		var print_links = $A(document.getElementsByClassName('print'));
		print_links.invoke('toggle');
	},
	scroll2Top: function(){
		window.scroll(0, 0);
	},
	setPrintCSS: function(){
		var links = $A(document.getElementsByTagName('link'));
		var _this = this;
		links.each(function(item){
			if (item.title == 'printview') item.disabled = !_this.isPrint;
			else if (item.title == 'screenview') item.disabled = _this.isPrint;
		});
	},
	toggle: function(e){
		this.isPrint = !this.isPrint;
		this.setPrintCSS();
		this.isPrint ? this.print_link.update('Вернуться к обычному виду').title = '' : this.print_link.update('Печатная версия').title = 'Распечатать';
		this.scroll2Top();
	}
};