var Site = {
	
	productCount: 0,
	productsWidth: 0,
	productPos: 0,
	
	start: function() {
			
		if ($('products')) Site.moomooagogo();

	},
	
	moomooagogo: function() {

		$$('.product').each(function(el){
			Site.productsWidth += (el.getStyle('width').toInt() + el.getStyle('padding-right').toInt() + el.getStyle('padding-left').toInt());
			Site.productCount++;
		});
		$('products').setStyle('width',this.productsWidth);
		
		Site.moomooascrollscroll();
		
	},
	
	moomooascrollscroll: function() {
		
		Element.Events.extend({
			'wheelup': {
				type: Element.Events.mousewheel.type,
				map: function(event){
					event = new Event(event);
					if (event.wheel >= 0) this.fireEvent('wheelup', event)
				}
			},
			
			'wheeldown': {
				type: Element.Events.mousewheel.type,
				map: function(event){
					event = new Event(event);
					if (event.wheel <= 0) this.fireEvent('wheeldown', event)
				}
			}
		});
		
		var fx = new Fx.Style($('zippz'), 'left', {duration: 900, wait: false});
		
		var scroll = new Fx.Scroll('content', {
					wait: false,
					duration: 900,
					transition: Fx.Transitions.Quad.easeInOut
				});
				
		var slide = new Slider($('trackz'), $('zippz'), {
			onChange: function(pos){
				scroll.toElement('product-' + pos );
				Site.productPos = pos;
				$('upd').setHTML('Product: ' + pos + '  / ' + Site.productCount);
			},
			onTick: function(pos){
				fx.custom(pos);
			},
			steps: Site.productCount
		}).set(this.productPos);

		$('products').addEvents({
			'wheelup': function(e) {
				e = new Event(e).stop();
				if (Site.productPos <= Site.productCount) {
					slide.set(Site.productPos++);
				}
			},
			'wheeldown': function(e) {
				e = new Event(e).stop();
				if (Site.productPos >= 0) {
					slide.set(Site.productPos--);
				}
			}
		});
		
	},
	
	moomooafixfix: function() {
		var scroll = new Fx.Scroll('content', {
					wait: false,
					duration: 500,
					transition: Fx.Transitions.Quad.easeInOut
				});
		scroll.toElement('product-' + Site.productPos );
	}

};

window.addEvent('load', Site.start);
window.addEvent('resize',Site.moomooafixfix);