var gallery = null;
window.addEvent('domready', function () {
	gallery = new Gallery();
})		

var Gallery = new Class ({
	
	offset: 150,
	
	initialize: function () {
		busy: false
	},
	
	init_gallery: function () {
		
		/*** ZMIANA PRZEZROCZYSTOSCI **/
		this.big_img = $('images_big').getElements('.photo');
		this.fx_big_img = new Fx.Elements (this.big_img);
		
		this.big_img.each (function (item) {
			if (item.getStyle('visibility') == 'hidden') {
				item.fade('hide');
			}
		})
		
		$('images_small').getElements('img').each (function (item, k) {
			
			item.addEvent('click', function () {
				var obj = {}
				
				this.big_img.each(function(item2, i){
					if (i == k) {
						obj[i] = { 
							'opacity': 1
						}
					} else {
						obj[i] = { 
							'opacity': 0
						}						
					}
				})
				
				this.fx_big_img.start(obj);
								
			}.bind(this))	
		}.bind(this))
		
		
		
		/*** PRZEWIJANE MINIATURKI ***/
		this.cont = $('prod_scroller_outer');
		this.count = this.cont.getElements('.thumb').length;
	
		this.height = this.cont.getElements('.thumb')[0].getStyle("height").toInt() + this.cont.getElements('.thumb')[0].getStyle("margin-top").toInt() + this.cont.getElements('.thumb')[0].getStyle("margin-bottom").toInt();
		$('prod_scroller_inner').setStyle('height', (this.height*this.count));

		
		//po kliknieciu na strzalke w lewo przesun w lewo
		//$('up_arrow_small').addEvent('click', function (event){
			//event = new Event(event).stop();
			//this.up();
		//}.bind(this))
		
		//po kliknieciu na strzalke w prawo przesun w prawo		
		//$('down_arrow_small').addEvent('click', function (event){
		//	event = new Event(event).stop();
		//	this.down();
		//}.bind(this))		
		
		
		this.fx_cont = new Fx.Scroll(this.cont, {
			duration: 700,
			wheelStops: false,
			transition: Fx.Transitions.Quad.easeInOut
		});
	},
	
	up: function () {
		var y = this.cont.getScroll().y;
		this.fx_cont.start (0, y - this.offset)
	},
	
	down: function () {
				
		var y = this.cont.getScroll().y;
		this.fx_cont.start (0, y + this.offset)
	}		
})





var Anim_Gallery2 = new Class({
	left_offset: 341,
	
	initialize: function () {
		//po kliknieciu na strzalke w lewo przesun w lewo
		$('left_arr_small').addEvent('click', function (event){
			event = new Event(event).stop();
			this.left();
		}.bind(this))
		
		//po kliknieciu na strzalke w prawo przesun w prawo		
		$('right_arr_small').addEvent('click', function (event){
			event = new Event(event).stop();
			this.right();
		}.bind(this))		
		
		//element przesuwany
		this.cont = $('other_outer');
		var count = $('others').getElements('.other_prod').length;
		var width = $('others').getElements('.other_prod')[0].getStyle("width").toInt() +  $('others').getElements('.other_prod')[0].getStyle("margin-right").toInt()+15; // to +2 to jest border
		
		$('other_inner').setStyle('width', (width*count) - 11);
		
		this.fx_cont = new Fx.Scroll(this.cont, {
			duration: 500,
			wheelStops: false,
			transition: Fx.Transitions.Quad.easeInOut
		});
		
		$$('.other_prod').each (function (item) {
			
			item.addEvent('mouseover', function (event) {
				
				this.tween('border-color', '#a7a7a7');
				event.stop();
			});
			item.addEvent('mouseout', function (event) {
				this.tween('border-color', '#E3E3E3');
				event.stop();
			});			
		})
		
	},
	
	left: function () {
		var x = this.cont.getScroll().x;	
		this.fx_cont.start (x - this.left_offset,0)
	},
	
	right: function () {
		var x = this.cont.getScroll().x;
		this.fx_cont.start (x +this.left_offset,0)
	}
})

