window.addEvent('domready', function() {		
	// animacja zdjęć w galerii
	
	
	
	/* settings */
	var showDuration = 3200;
	var container = $$('.galleries ul');
	if (container != null) {
		try{
		 var items = container[0].getElements('li');
		}
		catch(err){
		
		}	
	}
	
	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);
		});
	}
	
	// czyszczenie pola z mailem na newsletter, animacja logotypów w stopce
	Element.implement({ 
		clearFocusResetBlur: function(attr){ 
			var valueString = this.get(attr); 
			this.addEvents({ 
				'focus': function(){ 
					if( this.get('value') == valueString ) this.set('value',''); 
				}, 
				'blur': function(){ 
					if( this.get('value') == "" ) this.set('value',valueString); 
				} 
			}); 
		},
		
		switchBWtoC: function(){
			var BWsrc = this.get('src');
			var Csrc = this.get('rel');
			//var Csrc = this.getStyle('background-image').replace('url(', '').replace(')', '');
			//Csrc = Csrc.replace('\'', '');
			//Csrc = Csrc.replace('&quot;', '');
			
			
			this.addEvents({ 
				'mouseover': function(){ 
					this.set('src', Csrc); 
				}, 
				'mouseleave': function() {
					this.set('src', BWsrc);
				}
				 
			});
		},
		
		youTubeIt: function(id) {
			this.set('id', 'youtube_'+id);
			var size = this.getSize();
			var text = this.innerHTML;
            var movie_id = "";
            
            var x = text.indexOf("v");
            for (var j=2; j<13; j++){
                    movie_id = movie_id + text.charAt(x+j);
            }
            
            var W = size.x;
            if (W > 525) {
            	W = 525;
            }
            
            if (movie_id.length == 11){
                    var youtube_link = "http://www.youtube.com/v/" + movie_id;
                    swfobject.embedSWF(youtube_link, this.get('id'), W, W * 3/4, "9.0.0");

            }
		},
		
		bannerIt: function(id) {
			this.set('id', 'banner_swf_'+id);
			var size = this.getSize();
			var banner_src = this.innerHTML;
			
			swfobject.embedSWF(banner_src, this.get('id'),size.x, size.y, "9.0.0");
		}
		
	}); 
	
	
	//$('email').clearFocusResetBlur('alt');
	
	//$$('.logotypes img').switchBWtoC();
	
	var youTubeID = 1;
	$$('p.movie').each(function(t) {
		t.youTubeIt(youTubeID);
		youTubeID++;
	});
	
	var bannerID = 1;
	$$('.banner_swf').each(function(t) {
		t.bannerIt(bannerID);
		bannerID++;
	});
	
	
	
});

window.addEvents({
		'load': function(){
			
			/* info rotator example */	
			new SlideItMoo({overallContainer: 'SlideItMoo_info_outer',
							elementScrolled: 'SlideItMoo_info_inner',
							thumbsContainer: 'SlideItMoo_info_items',		
							itemsVisible:1,
							itemsSelector: '.info_item',
							itemWidth:390,
							showControls:0,
							autoSlide: 3500,
							transition: Fx.Transitions.Sine.easeIn,
							duration: 1500,
							direction:1});	
		}
	});
	

