require('LibDropbox.class');
var menu_li;
var translate = {
	producerDefaultText : {
		'ru' : 'Выберите производителя',
		'en' : 'Chose producer',
		'de' : 'Wähle Hersteller'
	},
	catalogDefaultText : {
		'ru' : 'Выберите продукт',
		'en' : 'Chose product',
		'de' : 'Wähle Product'
	},
	search : {
		'ru' : 'Поиск',
		'en' : 'Search',
		'de' : 'Wählen'
	}
}
window.addEvent('domready', function() {

			/**
			 * ВЫБОР ПРОИЗВОДИТЕЛЕЙ-ПРОДУКЦИИ В ВЕРХНЕЙ ЧАСТИ ШАБЛОНА
			 */
			var catalog_request = new Request({
						url : '/catalog/ajax/getproduceritems/',
						method : 'get',
						onSuccess : function(responseText) {
							catalog_dropbox.AJAXUpdate(responseText);
						}
					});
			var producers_request = new Request({
						url : '/catalog/ajax/getproducers/',
						method : 'get',
						onSuccess : function(responseText) {
							producers_dropbox.AJAXUpdate(responseText);
						}
					}).send();
			var producers_dropbox = new elSelect({
						container : 'producers',
						defaultText : translate.producerDefaultText[lang]
					}, function(val) {
						catalog_request.send('producer_id=' + val);
					});
			var catalog_dropbox = new elSelect({
						container : 'catalog',
						defaultText : translate.catalogDefaultText[lang]
					}, function(val) {
						location.href = '/catalog/items/' + val + '/';
					});

			/**
			 * МЕНЮ
			 */
			menu_li = $('top_menu').getElements('li');
			$each(menu_li, function(li) {
						li.addEvents({
									'mouseenter' : function() {
										this.addClass('text_selected');
									},
									'mouseleave' : function() {
										this.removeClass('text_selected');
									},
									'click' : function() {
										location.href = this.getFirst()
												.getProperty('href');
									}
								});
					});

			/**
			 * ТЕКСТОВОЕ ПОЛЕ ПОИСКА
			 */
			var search_field = $('s_field');
			search_field.addEvents({
						'focus' : function(e) {
							if (this.value.trim() == translate.search[lang]) {
								this.value = '';
								this.setStyle('color', '#000');
							}
						},
						'blur' : function(e) {
							if (!this.value.trim().length) {
								this.setStyle('color', '');
								this.value = translate.search[lang];
							}
						}
					});
		});
