(function() {
	EYE.register(function(){
		var prodTabsEl, prodTabEl, prodRatings, prodReviews, accntForm, checkoutEl;
		$('#browseManufacturer, select.productsSort').bind('change', function(){
			if (this.value != 0) {
				window.location.href = this.value;
			}
		});
		if ((prodTabsEl = document.getElementById('productDetailsTabs'))) {
			$(prodTabsEl).bind('click', function(ev){
				if ($(ev.target).is('a')) {
					var tabIndex = $('a', prodTabsEl).index(ev.target); 
					$(prodTabsEl)
						.find('li')
							.removeClass('current')
							.eq(tabIndex)
								.addClass('current')
								.end()
							.end()
						.parent()
							.find('>div')
								.removeClass('current')
								.eq(tabIndex)
									.addClass('current');
					ev.target.blur();
					return false;
				}
			});
			if (window.location.hash && (prodTabEl = $(window.location.hash)).size()>0) {
				if (prodTabEl.is('li') && EYE.isChildOf(prodTabsEl, prodTabEl.get(0), prodTabsEl)) {
					var tabIndex = $('li', prodTabsEl).index(prodTabEl.get(0)); 
					$(prodTabsEl)
						.find('li')
							.removeClass('current')
							.eq(tabIndex)
								.addClass('current')
								.end()
							.end()
						.parent()
							.find('>div')
								.removeClass('current')
								.eq(tabIndex)
									.addClass('current');
				}
			}
		}
		$('#filterCategory').bind('change', function(){
			window.location.href = this.value;
		});
		if ((prodRatings = document.getElementById('reviewsRatings'))) {
			$('select', prodRatings)
				.hide()
				.each(function(){
					var el = $('<div class="starRating" />')
								.appendTo(this.parentNode)
								.bind('click', function(ev){
									var targetEl = $(ev.target);
									if (targetEl.is('a')) {
										$(this)
											.find('div')
												.css('width', ev.target.offsetWidth + 'px')
												.end()
											.parent()
												.find('select')
													.val(targetEl.attr('rel'))
													.end()
												.end()
											.find('a')
												.removeClass('active');
										targetEl.addClass('active').blur();
										return false;
									}
								}),
						cnt = 0;;
					$(this).find('option').each(function(){
						el.prepend('<a href="#" rel="' + $(this).attr('value') + '" class="starRating' + cnt +'">' + cnt +'</a>');
						cnt++;
					});
					$('<div />').css('width', (parseInt(this.value, 10)||0)*20 + 'px').prependTo(el);
				});
		}
		if ((prodReviews = document.getElementById('productReviewsPage'))) {
			$('p.productReviewUsefull a', prodReviews).bind('click', function(){
				window.location.href = $(this).attr('dovote');
				return false;
			});
		}
		if ((accntForm = document.getElementById('accountForm'))) {
			var swicthAccount = function(ev){
				var el = $(this);
				el
					.parent()
					.parent()
						.find('input, select')
							.not(el)
							.attr('disabled', el.attr('checked'));
			};
			swicthAccount.apply($('input[name=use_contact_info]', accntForm)
				.bind('click', swicthAccount).get(0));
		}
		$('#addBookmark').bind('click', function () {
			this.blur();
			if (window.sidebar) { 
				window.sidebar.addPanel($('title').text(), window.location.href,""); 
			} else if( document.all ) {
				window.external.AddFavorite( window.location.href, $('title').text());
			} else if( window.opera && window.print ) {
				return true;
			}
			return false;
		});
		if ((checkoutEl = document.getElementById('shippingAddress'))) {
			$('select:first', checkoutEl)
				.bind('change', function(){
					$('fieldset.addressGroup').hide().eq(this.selectedIndex).show();
				})
				.each(function(){
					$('fieldset.addressGroup').hide().eq(this.selectedIndex).show();
				})
		}
		var topBanners = $('#topBanners a');
		if (topBanners.size() > 0) {
			topBanners.eq(parseInt(Math.random()*topBanners.size())||0).css('display','block');
		}
	}, 'init');
	
	EYE.localOverlay = function (){
		var inited = false;
		return {
			init: function (){
				if (inited == false) {
					inited = true;
					$('#localOverlay').css('opacity', 0.6);
				}
			},
			show: function (el) {
				var offset = $(el).offset();
				$('#localOverlay').css({
					top: offset.top,
					left: offset.left,
					width: el.offsetWidth,
					height: el.offsetHeight,
					display: 'block'
				});
			},
			hide: function (el) {
				$('#localOverlay').hide();
			}
		};
	}();
	EYE.register(EYE.localOverlay.init, 'init');
	
	EYE.clientOptions = function(){
		var show = function(){
				$('#clientOptions').css('left', $('#accountStatus a').get(0).offsetLeft).show();
			},
			hide = function(){
				$('#clientOptions').hide();
			};
		return {
			init: function() {
				$('#accountStatus a, #clientOptions')
					.bind('mouseenter', show)
					.bind('mouseleave', hide);
			}
		};
	}();
	EYE.register(EYE.clientOptions.init, 'init');
	
	EYE.categoriesSearch = function(){
		var el, srcEl, timer, cache = {}, active = false, lastSearch = '',
			category = 0, lastFound,
			show = function(){
				if (active) {
					$('#searchSuggestion').hide();
				}
				el.parent().show();
			},
			hide = function(){
				if (active) {
					$('#searchSuggestion').show();
				}
				el.parent().hide();
			},
			click = function(ev){
				var tgtEl = $(ev.target);
				if (tgtEl.is('a')) {
					el.find('a').removeClass('on');
					tgtEl.addClass('on');
					$('#searchCategory').text(tgtEl.text());
					var val = tgtEl.parent().data('searchVal');
					$(srcEl).val(val);
					if (category != val) {
						category = val;
						cache = {};
						search();
					}
					ev.target.blur();
					el.parent().hide();
				}
				return false;
			},
			hideSuggestion = function (ev) {
				if (active) {
					var theList = document.getElementById('searchSuggestion'),
						theField = document.getElementById('searchQuery');
					if (EYE.isChildOf(theList, ev.target, theList) || EYE.isChildOf(theField, ev.target, theField) || EYE.isChildOf(el.get(0), ev.target, el.get(0))) {
						//return false;
					} else {
						active = false;
						$(theList).hide();
						lastSuggestion = false;
						$(document).unbind('mousedown', hideSuggestion);
					}
				}
			},
			showSuggestion = function(data){
				var products = $('product', data);
				$('#searchInfo').empty();
				if (products.size() > 0) {
					var html = [];
					products.each(function(){
						html.push(tmpl('suggestionItem', {
							name: $('name', this).text(),
							brand: $('brand', this).text(),
							image: $('image', this).text(),
							url: $('url', this).text(),
							price: $('price', this).text(),
							categories: $('categories', this).text()
						}));
					});
					if (active === false) {
						active = true;
						$(document).bind('mousedown', hideSuggestion);
					}
					lastSuggestion = $('searched', data).text();
					$('#searchInfo').html(tmpl('suggestionInfo', {
						found: $('found', data).text(),
						total: $('total', data).text(),
						searched: lastSuggestion
					}));
					$('#searchSuggestion>ul').html(html.join('')).parent().show();
				} else if (active) {
					hideSuggestion();
					$(document).unbind('mousedown', hideSuggestion);
				}
			},
			search = function (){
				var val = $('#searchQuery').val();
				if (val.length > 1) {
					lastSearch = val;
					$('#searchSuggestion>ul').empty();
					if (cache[val]) {
						showSuggestion(cache[val]);
					} else {
						$('#searchQuery').addClass('loading');
						$.ajax({
							type: 'POST',
							data: $.param({
								plugin: 'searchProducts',
								category: $('#searchType').val(),
								val: val
							}),
							complete: function(){
								$('#searchQuery').removeClass('loading');
							},
							success: function(xmlResponse)
							{
								cache[val] = xmlResponse;
								showSuggestion(cache[val]);
							},
							url : '/ajaxserver.php'
						});
					}
				}
			},
			keyDown = function (ev) {
				var val = $('#searchQuery').val();
				clearTimeout(timer);
				if (val != lastSearch) {
					timer = setTimeout(search, 300);
				}
			},
			submitSuggestion = function() {
				if (lastSuggestion) {
					$('#searchQuery').val(lastSuggestion);
					$('#searchFrom').submit();
				}
				this.blur();
				return false;
			};
		return {
			init: function() {
				if ((srcEl = document.getElementById('searchType'))) {
					el = $('#searchCategories')
							.bind('mouseenter', show).bind('mouseleave', hide)
							.find('ul').bind('click', click);
					$('option', srcEl).each(function(){
						$('<li><a href="#">'+$(this).text()+'</a></li>')
							.data('searchVal', $(this).attr('value'))
							.appendTo(el);
					});
					var opt = $('option:selected', srcEl);
					el.find('a').eq($('option', srcEl).index(opt)).addClass('on');
					category = opt.attr('value');
					$('#searchCategory').bind('mouseenter', show).bind('mouseleave', hide)
						.text($('option:selected', srcEl).text());
					$('#searchQuery')
						.attr('autocomplete', 'off')
						.bind($.browser.opera ? 'keypress' : 'keydown', keyDown)
						.bind('focus', search);
					$('#searchInfo').bind('click', submitSuggestion);
				}
			}
		};
	}();
	EYE.register(EYE.categoriesSearch.init, 'init');
	
	EYE.mainMenu = function(){
		var currentItem,
			enter = function(){
				var left = Math.min($(this).offset().left - $('#wrapper').offset().left, 490);
				var submenu = $(this)
					.find('>a').addClass('active').end()
					.find('>div')
						.css('left', left)
						.show();
				submenu.find('iframe').css({
					width: submenu.get(0).offsetWidth-1,
					height: submenu.get(0).offsetHeight-1
				})
			},
			leave = function(){
				$(this)
					.find('>a').removeClass('active').end()
					.find('>div').hide();
			};
		return {
			init: function(){
				$('#mainMenu li.mainItem')
					.bind('mouseenter', enter)
					.bind('mouseleave', leave)
					.find('iframe').css('opacity', 0);
			}
		};
	}();
	EYE.register(EYE.mainMenu.init, 'init');
	
	EYE.sideBoxes = function(){
		var toggle = function(){
			var parBox = $(this).parent().parent().toggleClass('collapsed');
			$.cookie(parBox.get(0).id, parBox.hasClass('collapsed') ? 0 : 1,{ expires: 7, path: '/'});
			
			this.blur();
			return false;
		};
		return {
			init: function(){
				$('#leftColumn div.leftSideBox h3 a, #recentActivity h4 a').bind('click', toggle)
					.each(function(){
						var parBox = $(this).parent().parent();
						if ($.cookie(parBox.get(0).id) == 0) {
							parBox.addClass('collapsed');
						} else {
							parBox.removeClass('collapsed');
						}
					});
			}
		};
	}();
	EYE.register(EYE.sideBoxes.init, 'init');
	
	EYE.productOptions = function(){
		var show = function(){
				$(this).data('submenu').show();
			},
			hide = function(){
				$(this).data('submenu').hide();
			},
			cancelEv = function(){
				return false;
			}
		return {
			init: function(){
				$('#centerColumn>div.productsOptions')
					.find('>p.orderProductsBy a').bind('mouseenter', show).bind('mouseleave', hide).bind('click', cancelEv)
						.each(function(){
							$(this).data('submenu', $(this).parent().parent().find('>ul'));
						}).end()
					.find('>ul').bind('mouseenter', show).bind('mouseleave', hide).each(function(){
						$(this).data('submenu', $(this));
					}).end();
			}
		};
	}();
	EYE.register(EYE.productOptions.init, 'init');
	
	
	EYE.productComment = function (){
		var inited = false, el, review, container,
			hide = function (ev) {
				$('#commentComment').val('');
				$('#productCommentForm ul').remove();
				$('#overlay, #productCommentForm').hide();
				if (ev) {
					this.blur();
				}
				return false;
			},
			overlay = function() {
				$('#overlay').hide().css({
					width: $(document).width(),
					height: $(document).height(),
					display: 'block'
				});
			},
			show = function(ev){
				container = $(this).parent().parent();
				review = container.attr('rel');
				container = container.find('div.productReviewComments');
				var offset = $(this).offset();
				$('#productCommentForm').css({
					display: 'block',
					top: offset.top,
					left: offset.left
				});
				overlay();
				this.blur();
				return false;
			},
			send = function (ev){
				EYE.localOverlay.show(document.getElementById('productCommentForm'));
				$.ajax({
					type: 'POST',
					data: $.param({
						plugin: 'postComment',
						name: $('#commentName').val(),
						comment: $('#commentComment').val(),
						email: $('#commentEmail').val(),
						product: EYE.product,
						review: review
					}),
					complete: EYE.localOverlay.hide,
					success: function(xmlResponse)
					{
						var responseErros = $('errorResponse', xmlResponse);
						if (responseErros.size() > 0) {
							var html = ['<ul>'];
							responseErros.each(function(){
								html.push('<li>');
								html.push($(this).text());
								html.push('</li>');
							});
							html.push('</ul>');
							$('#productCommentForm ul').remove();
							$('#productCommentForm h3').after(html.join(''));
							overlay();
						} else {
							hide();
							var dat = {
								name: $('name', xmlResponse).text(),
								email: $('email', xmlResponse).text(),
								date: $('date', xmlResponse).text(),
								text: $('text', xmlResponse).text()
							};
							container.find('>div.productReviewCommentsWrapper').append(tmpl("reviewItem", dat));
							$.cookie('comment_name', dat.name, {
								expires: 7,
								path: '/'
							});
							$.cookie('comment_email', dat.email, {
								expires: 7,
								path: '/'
							});
							var cnt = container.find('h4 span');
							cnt.text(parseInt(cnt.text(), 10) + 1);
						}
					},
					url : '/ajaxserver.php'
				});
				this.blur();
				return false;
			},
			toggle = function() {
				$(this).parent().parent().find('div.productReviewCommentsWrapper').toggle();
				this.blur();
				return false;
			};
		return {
			init: function(){
				if (inited == false && (el = document.getElementById('productReviewsPage'))) {
					inited = true;
					$('a.addComment').bind('click', show);
					$('#overlayIframe').css('opacity', 0);
					$('#productCommentForm a:last').bind('click', hide);
					$('#productCommentForm a:first').bind('click', send);
					$('div.productReviewComments h4 a', el).bind('click', toggle);
				}
			}
		}
	}();
	EYE.register(EYE.productComment.init, 'init');
	
	EYE.homepagePromo = function(){
		var el, current = 0, lnks, lnks2,
			timer,
			goTo = function(ev) {
				clearTimeout(timer);
				lnks.eq(current).stop().animate({opacity: 0}, 500, function(){
					$(this).hide();
				});
				lnks2.eq(current).removeClass('active');
				if (ev){
					var targetEl = $(ev.target);
					if (targetEl.is('a')) {
						if (ev.target.id == 'homepagePromoPrev') {
							current --;
						} else if (ev.target.id == 'homepagePromoNext') {
							current ++;
						} else {
							current = $('#homepagePromoNavigation span a').index(ev.target);
						}
						targetEl.blur();
					} else {
						current ++;
					}
				} else {
					current ++;
				}
				if (current < 0) {
					current = lnks.size()-1;
				} else if(current >= lnks.size()) {
					current = 0;
				}
				lnks.eq(current).show().stop().animate({opacity: 1}, 500);
				lnks2.eq(current).addClass('active');
				timer = setTimeout(goTo, 5000);
				return false;
			};
		return {
			init: function(){
				if ((el = document.getElementById('homepagePromo'))) {
					var imgs = $('#homepagePromoImages a');
					if (imgs.size() > 1) {
						var html = [];
						$('#homepagePromoImages a').each(function(){
							html.push('<a href="#">&nbsp;</a>');
						}).css('opacity', 0).filter(':first').css('opacity',1).show();
						$('#homepagePromoNavigation span').html(html.join('')).find('a:first').addClass('active');
						$('#homepagePromoNavigation').bind('click', goTo);
						timer = setTimeout(goTo, 5000);
						lnks = $('#homepagePromoImages a');
						lnks2 = $('#homepagePromoNavigation span a');
					} else {
						$('#homepagePromoNavigation').empty().css('height', 10);
					}
				}
			}
		};
	}();
	EYE.register(EYE.homepagePromo.init, 'init');
	
	EYE.priceRange = function () {
		var el, cont, width = 148, priceDiff, knob1, knob2,
			origX, mouseX, knob, minPrice, maxPrice;
			mouseDown = function(ev){
				if ($(ev.target).is('span')) {
					knob = ev.target;
					$(document).bind('mousemove', mouseMove).bind('mouseup', mouseUp);
					origX = knob.offsetLeft;
					mouseX = ev.pageX;
					return false;
				}
			},
			mouseMove = function(ev){
				knob.style.left = Math.min(Math.max(0, origX + ev.pageX - mouseX), width) + 'px';
				showPrice();
				return false;
			},
			mouseUp = function(ev){
				$(document).unbind('mousemove', mouseMove).unbind('mouseup', mouseUp);
				return false;
			},
			showPrice = function(){
				var minP = EYE.priceRangeMin + parseInt(priceDiff * knob1.offsetLeft / width, 10);
				var maxP = EYE.priceRangeMin + parseInt(priceDiff * knob2.offsetLeft / width, 10);
				EYE.priceRangeRef[1] = Math.min(minP, maxP);
				EYE.priceRangeRef[3] = Math.max(minP, maxP);
				minPrice.text(EYE.priceRangeRef[1]);
				maxPrice.text(EYE.priceRangeRef[3]);
				$('#priceRangeCurrent a').attr('href', EYE.priceRangeRef.join(''));
			};
		return {
			init: function(){
				if ((el = document.getElementById('priceRange'))) {
					cont = $('#priceRangeSlider').bind('mousedown', mouseDown);
					//width = cont.width() - cont.find('span:last').width();
					cont
						.find('span:last')
							.css('left', width);
					minPrice = $('#priceRangeCurrent span:first');
					maxPrice = $('#priceRangeCurrent span:last');
					knob1 = document.getElementById('priceRangeSlider1');
					knob2 = document.getElementById('priceRangeSlider2');
					priceDiff = EYE.priceRangeMax - EYE.priceRangeMin;
					showPrice();
				}
			}
		}
	}();
	EYE.register(EYE.priceRange.init, 'init');
	
	EYE.productImages = function(){
		var click = function (ev) {
			var targetEl = $(ev.target), dir = 0;
			if (targetEl.is('img')) {
				targetEl = targetEl.parent();
			}
			if (targetEl.is('.productPrev')) {
				dir = -1;
			} else if (targetEl.is('.productNext')) {
				dir = 1;
			}
			if (dir != 0) {
				var imgs = $('a:first img', this);
				var vis = $('a:first img:visible', this);
				var indx = imgs.index(vis) + dir;
				if (indx < 0) {
					indx = imgs.size() - 1;
				} else if (indx >= imgs.size()) {
					indx = 0;
				}
				vis.hide();
				imgs.eq(indx).show();
				targetEl.blur();
				return false;
			}
		},
		comboClick = function(ev) {
			var targetEl = $(ev.target), dir = 0;
			if (targetEl.is('img')) {
				targetEl = targetEl.parent();
			}
			if (targetEl.is('a')) {
				$(this)
					.parent().parent()
						.find('>p a:first')
							.find('img:visible').hide()
							.end()
						.find('img').eq($('a', this).index(targetEl.get(0))).show();
				targetEl.blur();
				return false;
			}
		};
		return {
			init: function () {
				$('p.productImages').each(function(){
					if ($('>a:first img', this).size() <= 1) {
						$('a.productPrev, a.productNext', this).hide();
					}
				}).bind('click', click);
				$('#productsList span.productListCombos').bind('click', comboClick);
			}
		};
	}();
	EYE.register(EYE.productImages.init, 'init');
	
	EYE.productCombos = function () {
		var el,
			selectedOptions = {},
			thumbPath = '/images/eshop/products/orig/',
			imagePath = '/images/eshop/products/max/',
			anySelected = 0,
			currentCombo = '',
			currentImage,
			click = function(ev) {
				var targetEl = $(ev.target);
				if (targetEl.is('img') || targetEl.is('span')) {
					targetEl = targetEl.parent();
				}
				if (targetEl.is('a')) {
					var dat = targetEl.blur().data('opt');
					var near = targetEl.parent().parent().find('a');
					if (!targetEl.is('.disabled') && near.size()>1) {
						if (dat.disabled != true) {
							var sel = !dat.selected;
						}
						targetEl.parent().parent().find('a').removeClass('selected').each(function(){
							$(this).data('opt').selected = false;
						});
						if ((dat.selected = sel)) {
							targetEl.addClass('selected');
							EYE.product.combos[dat.attr_id].selected = dat.id;
						}
						else {
							EYE.product.combos[dat.attr_id].selected = false;
						}
						highlight();
					} else {
						clear();
						EYE.product.combos[dat.attr_id].selected = dat.id;
						dat.selected = true;
						targetEl.addClass('selected');
						highlight();
					}
					return false;
				}
			},
			highlight = function(){
				$('a', el).addClass('disabled');
				var img = EYE.product.image;
				selectedOptions = {};
				anySelected = 0;
				currentCombo = '';
				$.each(EYE.product.combos, function(nr, val){
					if (val.selected) {
						selectedOptions[val.id] = val.selected;
						if (val.options[val.selected].image) {
							img = val.options[val.selected].image.name;
						}
						anySelected ++;
					}
				});
				$.each(EYE.product.combo, function(nr, combo){
					var cnt = 0;
					if (anySelected > 0) {
						$.each(selectedOptions, function(attr, opt){
							if (combo.attributes[attr] && combo.attributes[attr] == opt) {
								cnt++;
							}
						});
						combo.available = (cnt == anySelected && combo.quantity > 0);
					} else {
						combo.available = combo.quantity > 0;
					}
					$.each(combo.attributes, function(attr, opt){
						if (combo.available) {
							$('#A'+attr+'O'+opt).removeClass('disabled');
						}
					});
					if (cnt == combo.size) {
						currentCombo = nr;
					}
				});
				$('#productImages a:first')
					.attr('href', imagePath + img)
					.find('img')
						.attr('src',thumbPath + img);
				currentImage = img;
				if ($('#productCombo option[value='+currentCombo+']').size() != 1) {
					$('#productCombo').val(0);
					$('#productPrice').text(EYE.product.price);
				} else {
					$('#productCombo').val(currentCombo);
					$('#productPrice').text(EYE.product.combo[currentCombo].price);
				}
			},
			setCombo = function(ev){
				if (ev) {
					$('a', el).removeClass('selected').each(function(){
					 $(this).data('opt').selected = false;
					 });
					 $.each(EYE.product.combos, function(nr, combo){
					 combo.selected = false;
					 });
				}
				clear();
				var sel = $('#productCombo')
				var val = sel.val();
				if (val == 0) {
					if (sel.get(0).length == 2) {
						val = sel.find('option:last').attr('value');
						sel.val(val);
					}
				}
				if (EYE.product.combo[val]) {
					$.each(EYE.product.combo[val].attributes, function (attr, opt){
						EYE.product.combos[attr].selected = opt;
						$('#A'+attr+'O'+opt).addClass('selected').data('opt').selected = true;
					});
				}
				highlight();
			},
			submit = function(){
				if (!currentCombo || $('#productCombo option[value='+currentCombo+']').size() != 1) {
					$('#productCombo').parent()
						.find('em').remove().end()
						.append('<em>'+EYE.product.error+'</em>');
					return false;
				}
				return true;
			},
			clear = function (){
				var lnks = $('a', el).removeClass('selected');
				var cnt = 0;
				$.each(EYE.product.combos, function(nr, attr){
					var cnt2 = 0, lastOpt;
					$.each(attr.options, function(nr2, opt){
						lnks.eq(cnt).data('opt', $.extend({
							attr_id: attr.id,
							selected: false,
							disabled: false,
							order: nr
						}, opt));
						cnt++;
						cnt2++;
						lastOpt = opt;
					});
					if (cnt2 == 1) {
						lnks.eq(cnt - 1).addClass('selected').data('opt').selected = true;
						attr.selected = lastOpt.id;
					} else {
						attr.selected = false;
					}
				});
			},
			mouseEnter = function(){
				var attr = $(this).data('opt').attr_id;
				var opt = $(this).data('opt').id;
				if (EYE.product.combos[attr].options[opt].image) {
					var img = EYE.product.combos[attr].options[opt].image.name;
					$('#productImages a:first')
						.attr('href', imagePath + img)
						.find('img')
							.attr('src',thumbPath + img);
				}
			},
			mouseLeave = function(){
				$('#productImages a:first')
					.attr('href', imagePath + currentImage)
					.find('img')
						.attr('src',thumbPath + currentImage);
			};
		return {
			init: function(){
				if ((el = document.getElementById('productFormCombos'))) {
					$('#productForm').bind('submit', submit);
					currentImage = EYE.product.image;
					setCombo();
					$('#productCombo').bind('change', setCombo);
					$(el).bind('click', click);
					$('a', el).bind('mouseenter',mouseEnter).bind('mouseleave', mouseLeave);
				}
			}
		};
	}();
	EYE.register(EYE.productCombos.init, 'init');
	
	EYE.siblingProductsCarousel = function(){
		var el, slider, timer, dir= 0, x = 0, minX, speed = 3, indic, ration, maxX,
			current = false, tooltipLeft, tooltipWidth, tooltipIndic, totalProducts,
			slide = function (){
				x = Math.min(0, Math.max(minX, x + dir*speed));
				slider.style.left = x + 'px';
				//indic.style.left = 20 - x*ratio + 'px';
			},
			start = function (ev) {
				dir = this.id == 'productsSliderNext' ? -1 : 1;
				timer = setInterval(slide, 18);
			},
			faster = function () {
				speed = 20;
				$(document).bind('mouseup', slower);
				return false;
			},
			slower = function (){
				speed = 3;
				return false;
			},
			stop = function (ev) {
				clearInterval(timer);
			},
			move = function (ev) {
				var tgtEl = ev.target;
				while (tgtEl.nodeName.toLowerCase() != 'div') {
					if (tgtEl.nodeName.toLowerCase() == 'a') {
						var left = document.getElementById('wrapper').offsetLeft;
						if (current != tgtEl) {
							if (current) {
								/*var imgEl = $(current).find('img');
								if (!/gray\//g.test(imgEl.attr('src'))) {
									imgEl.attr('src', imgEl.attr('src').replace(/thumbs\//g, 'thumbs/gray/'));
								}*/
							}
							var prodId = parseInt($(tgtEl).attr('rel'), 10) ||0;
							/*var imgEl = $(tgtEl).find('img');
							if (/gray\//g.test(imgEl.attr('src'))) {
								imgEl.attr('src', imgEl.attr('src').replace(/gray\//g, ''));
							}*/
							if (EYE.siblingProducts[prodId]) {
								current = tgtEl;
								tooltipLeft = $(tgtEl).offset().left;
								if (EYE.siblingProducts[prodId].combos) {
									var combos = '';
									$.each(EYE.siblingProducts[prodId].combos, function(nr, val){
										if (val.images == 1) {
											return;
										}
										val.opt = val.options;
										combos += tmpl(val.images > 0 ? 'prodTooltipImages':'prodTooltipAttr', val) + '</span>';
									});
								} else {
									var combos = '';
								}
								var tooltip = $('#productTooltip')
									.find('>div')
										.html(tmpl('prodTooltip', $.extend(
											{}, 
											EYE.siblingProducts[prodId], 
											{
												index: $(totalProducts).index(tgtEl)+1, 
												total: totalProducts.length, 
												combos: combos
											}
											)))
										.end()
									.css('left', tooltipLeft).show().get(0);
								tooltipWidth = tooltip.offsetWidth;
								tooltipLeft = Math.max (left + 20 , Math.min(left + 960 - tooltipWidth, tooltipLeft));
								tooltip.style.left = tooltipLeft + 'px';
							}
						}
						tooltipIndic.style.left = Math.min(tooltipWidth - 13, ev.pageX - tooltipLeft) + 'px';
						return;
					}
					tgtEl = tgtEl.parentNode;
				}
				if (current) {
					/*var imgEl = $(current).find('img');
					if (!/gray\//g.test(imgEl.attr('src'))) {
						imgEl.attr('src', imgEl.attr('src').replace(/thumbs\//g, 'thumbs/gray/'));
					}*/
					current = false;
					$('#productTooltip').hide();
				}
			},
			stopMove = function(ev){
				if (current) {
					/*var imgEl = $(current).find('img');
					if (!/gray\//g.test(imgEl.attr('src'))) {
						imgEl.attr('src', imgEl.attr('src').replace(/thumbs\//g, 'thumbs/gray/'));
					}*/
					current = false;
					$('#productTooltip').hide();
				}
			};
		return {
			init: function(){
				if ((el = document.getElementById('productsSlider'))) {
					slider = document.getElementById('productsSliderWrapper');
					totalProducts = slider.getElementsByTagName('a');
					if (slider.offsetWidth > el.offsetWidth) {
						minX = el.offsetWidth - slider.offsetWidth;
						$('#productsSliderPrev, #productsSliderNext')
							.css('visibility', 'visible')
							.bind('mouseenter', start)
							.bind('mouseleave', stop)
							.bind('mousedown', faster)
							.bind('click', function(){
								return false;
							});
						var currentEl = $('a.current', slider).parent();
						if (currentEl.size() == 1) {
							x = Math.min(0, Math.max(minX, -currentEl.get(0).offsetLeft + (el.offsetWidth-currentEl.get(0).offsetWidth) / 2));
							$(slider).css('left', x);
						}
						//ratio = 940/slider.offsetWidth;
						//indic = $('#productsSliderIndic').css('width',  940*ratio).show().get(0);
						//maxX = 940 - indic.offsetWidth;
					}
					$(el).bind('mouseenter', function(){
						$(document).bind('mousemove', move);
					}).bind('mouseleave', function(){
						$(document).unbind('mousemove', move);
						stopMove();
					});
					tooltipIndic = $('#productTooltipIndic').get(0);
				}
			}
		};
	}();
	EYE.register(EYE.siblingProductsCarousel.init, 'init');
	
	EYE.topProducts = function(){
		var el,
			change = function (){
				var top = document.getElementById(this.value);
				close();
				if (top) {
					$(top).show();
				}
			},
			close = function (ev) {
				$(el)
					.parent().parent()
					.find('div.topItem').hide();
				if (ev) {
					$(el).val('0');
				}
				return false;
			};
		return {
			init: function(){
				if ((el = document.getElementById('top5Products'))) {
					$(el).bind('change', change)
						.parent()
						.parent()
						.find('div.topItem>p a')
							.bind('click', close);
				}
			}
		};
	}();
	EYE.register(EYE.topProducts.init, 'init');
	
	EYE.productGallery = function(){
		var images={}, el, active = false, timer,
			brandPath = '/images/eshop/manufacturers/',
			click = function(ev){
				var targetEl = $(ev.target);
				if (targetEl.is('a') || targetEl.is('img')) {
					show();
				}
				return false;
			},
			overlay = function() {
				$('#overlay').hide().css({
					width: $(document).width(),
					height: $(document).height(),
					display: 'block'
				});
			},
			show = function(){
				var html=[];
				active = true;
				$.each(images, function(img, val){
					html.push(tmpl('galleryItem', {img: img}));
				});
				$('#productGalleryHeader')
					.find('ul').html(html.join('')).end()
					.find('p')
						.find('span').text($('#productInfo h1').text()).end();
						//.find('img').attr('src', brandPath+EYE.product.brand);
				$('#productGallery').show();
				$('#overlay').bind('click', close);
				overlay();
				showImage($('#productGalleryHeader ul a:first').get(0));
				window.scrollTo(0,0);
			},
			showImage = function (el) {
				var targetEl = $(el).blur();
				if (targetEl.is('a') && !targetEl.parent().is('.active')) {
					$('#productGalleryHeader ul li').removeClass('active');
					targetEl.parent().addClass('active');
					$('#productGalleryContent').html('<img src="'+targetEl.attr('href')+'" />');
					resize();
				}
			},
			resize = function(){
				if (active) {
					var height = $('#productGalleryHeader').get(0).offsetHeight;
					var width = Math.min(682, $(window).height()-20-height);
					overlay();
					$('#productGalleryContent img').attr({
							width: width-28,
							height: width-28
						});
				}
			},
			close = function(){
				active = false;
				$('#overlay, #productGallery').hide();
				$('#overlayIframe').unbind('click', close);
				return false;
			};
		return {
			init: function(){
				if ((el = document.getElementById('productImages'))) {
					if (EYE.product.combos) {
						$.each(EYE.product.combos, function(nr, attr){
							if (attr.options) {
								$.each(attr.options, function(nr2, opt){
									if (opt.image) {
										images[opt.image.name]=true;
									}
								});
							}
						});
					} else {
						$('a:first', el).each(function(){
							images[$(this).attr('rel')]= true;
						});
					}
					$('a', el).not(':first').each(function(){
						images[$(this).attr('rel')]= true;
					});
					$(el).bind('click', click);
					$('#productGalleryHeader ul').bind('click', function(ev){
						var targetEl = $(ev.target);
						if (targetEl.is('img')) {
							targetEl = targetEl.parent();
						}
						showImage(targetEl.get(0));
						return false;
					});
					$('#productGalleryClose').bind('click', close);
					$(window).bind('resize', function(){
						clearTimeout(timer);
						timer = setTimeout(resize, 500);
					});
				}
			}
		};
	}();
	EYE.register(EYE.productGallery.init, 'init');
	
	EYE.checkout = function(){
		var el,
			asCompany = function(ev){
				if ($(this).attr('checked')) {
					$('p.asCompany', el).show();
					$('p.asPerson', el).hide();
				} else {
					$('p.asCompany', el).hide();
					$('p.asPerson', el).show();
				}
			},
			useBilling = function(){
				$(this).parent().parent().find('input, select').not(this).attr('disabled', $(this).attr('checked'));
			};
		return {
			init: function(){
				if ((el = document.getElementById('checkout'))) {
					asCompany.apply($('#as_company').bind('click', asCompany).get(0));
					useBilling.apply($('#use_billing').bind('click', useBilling).get(0));
				}
			}
		};
	}();
	EYE.register(EYE.checkout.init, 'init');
	
	EYE.yahoo = function(){
		var show = function(){
				var offs = $(this).offset();
				$('#yahoo').css({
					top: offs.top + 1,
					left: offs.left + this.offsetWidth
				}).stop().show().fadeTo(400, 1);
			}, 
			hide = function(){
				$('#yahoo').stop().fadeTo(400, 0, function(){
					$(this).hide();
				});
			};
		return {
			init: function(){
				if (document.getElementById('registrationFormLite') || document.getElementById('accountForm') || $('form.form').size() > 0) {
					$('#registrationFormLite input[name=email], #accountForm input[name=email], form.form input[name*=email]')
						.bind('focus', show).bind('blur', hide);
					$('#yahoo').css('opacity', 0);
				}
			}
		};
	}();
	EYE.register(EYE.yahoo.init, 'init');
	
	EYE.brands = function(){
		var el,
			goTo = function(ev){
				var trgt = $(ev.target).closest('a');
				if (trgt.size() == 1) {
					var trgtEl = $(trgt.blur().attr('href'));
					if (trgtEl.size() == 1) {
						$('html, body').animate(
							{
								scrollTop: trgtEl.offset().top-100
							}, 
							800, 
							function(){
								trgtEl.animate({opacity: 0.2}, 400).animate({opacity: 1}, 400)
							});
					}
					return false;
				}
			};
		return {
			init: function(){
				if ((el = document.getElementById('brandsIndex'))) {
					$(el).bind('click', goTo);
				}
			}
		};
	}();
	EYE.register(EYE.brands.init, 'init');
})();
