//on dom ready...
//
	
//

window.addEvent('domready', function() {

	
	// animacja zdjęć w galerii
	
	/* settings */
	var showDuration = 3200;
	var container = $$('.galleries ul');
	if (container != null) {
		var items = container[0].getElements('li');
	}
	
	if (items != null && items.length > 1) {
		var currentIndex = 0;
		var interval;
		/* opacity and fade */
		items.each(function(t,i){ 
			//t.getElements('span').set('opacity', 0.5);
			if(i > 0) {
				t.set('opacity', 0);
			}
		});
		
		/* worker */
		var show = function() {
			items[currentIndex].fade('out');
			items[currentIndex = currentIndex < items.length - 1 ? currentIndex+1 : 0].fade('in');
		};
		/* start once the page is finished loading */
		window.addEvent('load',function(){
			interval = show.periodical(showDuration);
		});
	}

	//$("img[rel]").overlay();
	//$("a[rel]").overlay();
	
	// ustal numer elementu do rozwinięcia w mainMenu
	var number = 0;
	var itemFounded = false;
	
	$$('#productsMenu ul.accordion').each(function(el) {
		var items = el.getElements('li');
		items.each(function(el) {
			if (el.getProperty('class') == 'selected')
				itemFounded = true;
		});
		if (itemFounded) return;
		else number++;
	});
	
	if (itemFounded == true) {
		var myAccordion = new Accordion($$('.toggler'), $$('.accordion'), {
			opacity: false,
			initialDisplayFx: true,
			alwaysHide: true,
			show: number
		});
	} else {
		var myAccordion = new Accordion($$('.toggler'), $$('.accordion'), {
			opacity: false,
			initialDisplayFx: false,
			alwaysHide: true,
			display: -1
		});
	}
	
	
//	var myAccordion = new Accordion($$('.toggler'), $$('.accordion'), {
//		display: -1,
//		alwaysHide: true
//	});
	
	$$('.toggler').setStyles({
		cursor: 'pointer'
	});
	
	
	
	var SimpleSlideshow = new Class({
		options: {
			showControls: true,
			showDuration: 5000,
			showTOC: false,
			tocWidth: 20,
			tocClass: 'toc',
			tocActiveClass: 'toc-active'
		},
		Implements: [Options,Events],
		initialize: function(container,elements,options) {
			//settings
			this.container = $(container);
			this.elements = $$(elements);
			this.currentIndex = 0;
			this.interval = '';
			if(this.options.showTOC) this.toc = [];
			
			//assign
			this.elements.each(function(el,i){
				if(this.options.showTOC) {
					this.toc.push(new Element('a',{
						text: i+1,
						href: '#',
						'class': this.options.tocClass + '' + (i == 0 ? ' ' + this.options.tocActiveClass : ''),
						events: {
							click: function(e) {
								if(e) e.stop();
								this.stop();
								this.show(i);
							}.bind(this)
						},
						styles: {
							left: ((i + 1) * (this.options.tocWidth + 10))
						}
					}).inject(this.container));
				}
				if(i > 0) el.set('opacity',0);
			},this);
			
			//next,previous links
			if(this.options.showControls) {
				this.createControls();
				
			}
			//events
			this.container.addEvents({
				mouseenter: function() { this.stop(); }.bind(this),
				mouseleave: function() { this.start(); }.bind(this)
			});

		},
		show: function(to) {
			this.elements[this.currentIndex].fade('out');
			if(this.options.showTOC) this.toc[this.currentIndex].removeClass(this.options.tocActiveClass);
			this.elements[this.currentIndex = ($defined(to) ? to : (this.currentIndex < this.elements.length - 1 ? this.currentIndex+1 : 0))].fade('in');
			if(this.options.showTOC) this.toc[this.currentIndex].addClass(this.options.tocActiveClass);
		},
		start: function() {
			this.interval = this.show.bind(this).periodical(this.options.showDuration);
		},
		stop: function() {
			$clear(this.interval);
		},
		//"private"
		
		createControls: function() {
			var next = new Element('a',{
				href: '#',
				id: 'next',
				text: '>>',
				events: {
					click: function(e) {
						if(e) e.stop();
						this.stop(); 
						this.show();
					}.bind(this)
				}
			}).inject(this.container);
			var previous = new Element('a',{
				href: '#',
				id: 'previous',
				text: '<<',
				events: {
					click: function(e) {
						if(e) e.stop();
						this.stop(); 
						this.show(this.currentIndex != 0 ? this.currentIndex -1 : this.elements.length-1);
					}.bind(this)
				}
			}).inject(this.container);
		}
	
	});
	

	var slideshow = new SimpleSlideshow('slideshow-container','#slideshow-container a');
	slideshow.start();	
	
	$$('#flyout-ribbon').FlyoutRibbon();
	
//	/* settings */
//	var showDuration = 5000;
//	var container = $('slider');
//	var images = container.getElements('a');
//	var currentIndex = 0;
//	var interval;
//	/* opacity and fade */
//	images.each(function(img,i){ 
//		if(i > 0) {
//			img.set('opacity',0);
//		}
//	});
//	/* worker */
//	var show = function() {
//		images[currentIndex].fade('out');
//		images[currentIndex = currentIndex < images.length - 1 ? currentIndex+1 : 0].fade('in');
//	};
//	/* start once the page is finished loading */
//	window.addEvent('load',function(){
//		interval = show.periodical(showDuration);
//	});
	
});
