StuffObject = new Class.create();
StuffObject.prototype = {
	initialize: function(){
		this.option = Object.extend({
			ajaxLocation: '',
			ajaxOption: {
				fromAjax: ''
			},
			
			windowOption: {
				channelmode: 0,
				directories: 0,
				fullscreen: 0,
				height: 600,
				left: 0,
				location: 0,
				menubar: 0,
				resizable: 0,
				scrollbars: 1,
				status: 0,
				titlebar: 1,
				toolbar: 0,
				top: 0,
				width: 500
			},
			textOption: {
				moreText: {
					0: 'подробнее',
					1: 'more'
				},
				hideText: {
					0: 'скрыть',
					1: 'hide'
				},
				pleaseWait: {
					0 : 'Пожалуйста, подождите',
					1 : 'wait, please'
				}
			}
		}, arguments[0] || {});
		
		this.stringAjaxOption = '?';
		for (var option in this.option.ajaxOption) this.stringAjaxOption += option + '=' + this.option.ajaxOption[option] + '&';
	},
	
	setOption: function(setTo){
		if (setTo) this.option[setTo] = Object.extend(this.option[setTo], arguments[1] || {});
		else this.option = Object.extend(this.option, arguments[1] || {});
		this.stringAjaxOption = '?';
		for (var option in this.option.ajaxOption) this.stringAjaxOption += option + '=' + this.option.ajaxOption[option] + '&';
	},
	
	showPanel: function(itemId, templateId){
		this._createPanel();
		bodyElement = this.divPanel.up('body');
		bodyElement.addClassName('panel');
		if (!this.divPanel) return;
		thisPanel = this;
		this.divPanel.down('.full_description').innerHTML = 'Пожалуйста, подождите...';
		new Ajax.Request(this.option.ajaxLocation, {
			method: 'post',
			parameters: this.stringAjaxOption + 'item_id=' + itemId + '&template_id=' + templateId,
			onSuccess: function(transport){
				thisPanel.divPanel.down('.full_description').innerHTML = transport.responseText;
			}
		});
	},
	
	_createPanel: function(){
		if (this.divPanel) this.divPanel.remove();
		this.divPanel = document.createElement('DIV');
		this.divPanel.id = '__more_panel';
		if (Prototype.Browser.IE) document.body.insertBefore(this.divPanel, document.body.firstChild);
		else document.body.insertBefore(this.divPanel, document.body.down());
		
		this.divPanel = $(this.divPanel.id);
		this.divPanel.addClassName('more_panel');
		this.divPanel.innerHTML = '<div class="full_description">&nbsp;</div><div class="close_button"><a href="javascript: //">Закрыть</a></div>';
		Event.observe(this.divPanel.down('.close_button').down('a'), 'click', this.closePanel.bindAsEventListener(this));
		
		this.divPanel.setStyle({
			top: parseInt(this.divPanel.getStyle('top')) + (window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0) + 'px'
		});
	},
	
	closePanel: function(){
		bodyElement = this.divPanel.up('body');
		bodyElement.removeClassName('panel');
		if (this.divPanel) this.divPanel.remove();
		this.divPanel = null;
	},
	
	addToBasket: function(itemId, templateId){
		this._createPanel();
		if (!this.divPanel) return;
		this.divPanel.addClassName('order_panel');
		thisPanel = this;
		this.divPanel.down('.full_description').innerHTML = 'Пожалуйста, подождите...';
		new Ajax.Request(this.option.ajaxLocation, {
			method: 'post',
			parameters: this.stringAjaxOption + 'item_id=' + itemId + '&template_id=' + templateId,
			onSuccess: function(transport){
				thisPanel.divPanel.down('.full_description').innerHTML = transport.responseText;
			}
		});
	},
	
	openWindow: function(url){
		stringWindowOption = '';
		for (var option in this.option.windowOption) stringWindowOption += option + '=' + this.option.windowOption[option] + ',';
		window.open(url, '_blank', stringWindowOption + ', resizable');
	},
	
	removeFromBasket: function(itemId, templateId){
		new Ajax.Request(this.option.ajaxLocation, {
			method: 'post',
			parameters: this.stringAjaxOption + 'item_id=' + itemId + '&template_id=' + templateId
		});
		$('order_' + itemId).remove();
	},
	
	checkAndSubmit: function(idForm, params){
		if ($(idForm)){
			for (var prop in params){
				if ($(prop)){
					if (!$(prop).value){ alert(params[prop]); return; }
				}
			}
			$(idForm).submit();
		}
	},
	
	showhideMore: function(elementFrom, lang_id){
		if (!lang_id) lang_id = 0;
		if ($(elementFrom).up().down('.hidden')){
			$(elementFrom).up().down('.hidden').addClassName('more_text');
			$(elementFrom).up().down('.hidden').removeClassName('hidden');
			$(elementFrom).innerHTML = this.option.textOption.hideText[lang_id];
		}
		else {
			$(elementFrom).up().down('.more_text').addClassName('hidden');
			$(elementFrom).up().down('.more_text').removeClassName('more_text');
			$(elementFrom).innerHTML = this.option.textOption.moreText[lang_id];
		}
	},
	
	addedAjaxList: function(elementTo, templateId){
		if ($(elementTo)){
			Event.observe($(elementTo), 'change', this._eventListChange.bindAsEventListener(this, templateId));
		}
	},
	
	_eventListChange: function(event, templateId){
		elementFrom = Event.element(event);
		if (-1 != elementFrom.selectedIndex){
			while(elementFrom.up('li').next('li')) elementFrom.up('li').next('li').remove();
			if (elementFrom.options[elementFrom.selectedIndex].value){
				elementLi = document.createElement('LI');
				elementFrom.up('ul').appendChild(elementLi);
				elementLi = elementFrom.up('ul').down('li', elementFrom.up('ul').getElementsBySelector('li').size() - 1);
				elementLi.innerHTML = this.option.textOption.pleaseWait;
				thisOption = this.option;
				new Ajax.Request(this.option.ajaxLocation, {
					method: 'post',
					parameters: this.stringAjaxOption + '&' + elementFrom.serialize() + '&template_id=' + templateId,
					onSuccess: function(transport){
						if (transport.responseText){
							elementLi.innerHTML = transport.responseText;
							transport.responseText.extractScripts().map(function(script){
								eval (script);
							});
						}
						else {
							elementLi.remove();
						}
					}
				});
			}
		}
	},
	
	checkAndSubmit: function(idForm, params){
		if ($(idForm)){
			for (var prop in params){
				if ($(prop)){
					if (!$(prop).value){ alert(params[prop]); return; }
				}
			}
			$(idForm).submit();
		}
	}
}