var Helper = function()
{
	return {

		init: function( is_drag )
		{
			var that = this;

			if( !is_drag )
				is_drag = false;

			that.helper = {
				'drag': is_drag
			};
			var w = window.getSize().x.toInt();
			var h = window.getSize().y.toInt();

			var scroll = window.getScrollTop();

			that.max_width = 698;
			that.max_height = 460;

			var middle_width = w/2;
			var middle_height = h/2;

			that.end_left = ( w-this.max_width )/2;
			that.end_top = ( ( h-this.max_height )/2 )+scroll;
		},

		open: function( data,is_drag )
		{
			var that = this;

			that.init( is_drag );
			document.addEvent( 'keypress', function( e ){ if( e.key=='esc' ) that.close() } );

			that.helper_bg = new Element(
				'div',
				{
					styles :
					{
						background: '#FFF',
						width:      '100%',
						height:     '100%',
						opacity:    '0.9',
						position:   'absolute',
						top:        window.getScrollTop(),
						left:       0,
						'z-index':  9998
					},
					id : 'helper_bg',
					events:
					{
						'click': function(){ that.close() }
					}
				}
			);

			that.helper_main = new Element(
				'div',
				{
					styles :
					{
						width:      that.max_width + 'px',
						height:     that.max_height + 'px',
						position:   'absolute',
						left:       this.end_left + 'px',
						top:        this.end_top + 'px',
						display:    'block',
						'z-index':  9999
					},
					id : 'helper_main'
				}
			);
			
			if( navigator.appVersion.indexOf("MSIE 6.0") > 0 ) {
			
			that.helper_main.set( 'html',
				'<table class="helpUp">' +
					'<tr>' +
						'<td><img src="/design/standart/images/q1_.gif" width="57" height="61"></td>' +
						'<td style="background: url(/design/standart/images/q2_.gif);"><div class="nomber">' + data[ 'helper_title' ] + '</div><div class="closeText">закрыть</div></td>' +
						'<td><a class="close" href="javascript:Helper.close()" onFocus="this.blur()"></a></td>' +
					'</tr>' +
					'<tr>' +
						'<td style="background: url(/design/standart/images/q8_.gif);">&nbsp;</td>' +
						'<td width="100%" class="message" style="background-color:#FFF;">' + data[ 'helper_data' ] + '</td>' +
						'<td style=" background: url(/design/standart/images/q4_.gif);">&nbsp;</td>' +
					'</tr>' +
					'<tr>' +
						'<td><img src="/design/standart/images/q7_.gif" width="57" height="70"></td>' +
						'<td style="background: url(/design/standart/images/q6_.gif);">&nbsp;</td>' +
						'<td><img src="/design/standart/images/q5_.gif" width="57" height="70"></td>' +
					'</tr>' +
				'</table>'
			);
			
			} else {

			that.helper_main.set( 'html',
				'<table class="helpUp">' +
					'<tr>' +
						'<td><img src="/design/standart/images/q1.png" width="57" height="61"></td>' +
						'<td style="background: url(/design/standart/images/q2.png);"><div class="nomber">' + data[ 'helper_title' ] + '</div><div class="closeText">закрыть</div></td>' +
						'<td><a class="close" href="javascript:Helper.close()" onFocus="this.blur()"></a></td>' +
					'</tr>' +
					'<tr>' +
						'<td style="background: url(/design/standart/images/q8.png);">&nbsp;</td>' +
						'<td width="100%" class="message" style="background-color:#FFF;">' + data[ 'helper_data' ] + '</td>' +
						'<td style=" background: url(/design/standart/images/q4.png);">&nbsp;</td>' +
					'</tr>' +
					'<tr>' +
						'<td><img src="/design/standart/images/q7.png" width="57" height="70"></td>' +
						'<td style="background: url(/design/standart/images/q6.png);">&nbsp;</td>' +
						'<td><img src="/design/standart/images/q5.png" width="57" height="70"></td>' +
					'</tr>' +
				'</table>'
			);
			
			}

			that.helper_main.inject( document.body );

			if( that.helper[ 'drag' ] )
			{
				that.helper_main.setStyle('cursor','move');
				new Drag.Move( that.helper_main );
			}
			else
				that.helper_bg.inject( document.body );

			window.addEvent(
				'scroll',
				function()
				{
					/*
					if( that.helper_main )
						that.helper_main.setStyle(
							'top',
							( ( window.getSize().y.toInt()-that.helper_main.getSize().y.toInt() )/2 )+window.getScrollTop()
						);
					if( that.helper_bg )
						that.helper_bg.setStyle( 'top',window.getScrollTop() );
					*/
				}
			);

			// Для активации у всплавающей формы niceforms кастомных полей
			inputs2 = [];
			labels2 = [];
			radios2  = [];
			radioLabels2 = [];
			checkboxes2 = [];
			checkboxLabels2 = [];
			texts2 = [];
			textareas2 = [];
			selects2 = [];
			hovers2 = [];
			buttons2 = [];

			getElements2();
			separateElements2();
			buttonHovers2();
			replaceCheckboxes2();
			replaceSelects2();
		},

		close: function()
		{
			var that = this;
			// Необходимо дестроить сгенерированные скриптом niceforms выпадающие списки
			$try(function() {
				$$('.optionsDivVisible').setStyle('display', 'block');
				$$('.optionsDivVisible').destroy();
			});
			$try(function() {
				$$('.optionsDivInvisible').setStyle('display', 'block');
				$$('.optionsDivInvisible').destroy();
			});
			that.helper_bg.dispose();
			that.helper_main.dispose();
		}

	}
}();
