window.addEvent('domready', function() {



   //make the accordion  
   var accordion = new Accordion($$('.toggler'),$$('.element'), {  
        opacity: 1,  
        onActive: function(toggler) { toggler.setStyle('font-weight', 'bold'); },  
        onBackground: function(toggler) { toggler.setStyle('font-weight', 'normal'); }  
    });  
      
    //make it open on hover  
    $$('.toggler').addEvent('mouseenter', function() { this.fireEvent('click'); });  



























//$('loader').setProperty('display', 'none');
	var actObject;
	new SmoothScroll({ duration:700 }, window);
	
	
	/* Wysylanie komentarza */
	if($('myForm') != null) {
	$('myForm').addEvent('submit', function(e) {
		//Prevents the default submit event from loading a new page.
		e.stop();
		$('myForm').removeEvents();
		$('myForm').addEvent('submit',function(e) {
			e.stop();
		});
		//
				this.set('send', {onComplete: function(response) { 
			//log.removeClass('ajax-loading');
			
			var showme = new Chain();
				var one = function() {
					var komc = new Fx.Morph($('writecomment'), {
							duration: 20,
							transition: 'cubic'
						}).start({'opacity': 0});
				};
				var hax = function() {
				$('writecomment').empty();
				$('writecomment').set('html', response);
				}
				var two = function() {
					var komc = new Fx.Morph($('writecomment'), {
							duration: 300,
							transition: 'cubic'
						}).start({'opacity': 1,'background-color': '#fff4a6', 'padding': 0});
				};
				
					showme.chain(one);
					showme.chain(hax);
				showme.chain(two);

		showme.callChain.delay(20, showme);
		showme.callChain.delay(30, showme);
		showme.callChain.delay(500, showme);	

		}});
		//Send the form.
		this.send();
		//
	});
	}
	/*
	
	$$('.nice').each(function(el) {
		el.addEvents({
			'mouseenter': function() {
				this.morph({
					'color': '#000000'
				});
			},
			'mouseleave': function() {
				this.morph({
					'color': '#999999'
				});
			}
			});
		});*/
		
	$$('.item').each(function(el) {
		el.addEvents({
			'mouseenter': function() {
				this.morph({
					'background-color': '#000000'
				});
			},
			'mouseleave': function() {
				this.morph({
					'background-color': '#2b2722'
				});
			}
			});
		});



	$$('.toplink').each(function(el) {
		el.morph({
				'opacity': 0.5,
				'color': '#000000'
			});
	
	
		el.addEvents({
		'mouseenter': function(){
			// Always sets the duration of the tween to 1000 ms and a bouncing transition
			// And then tweens the height of the element
			this.morph({
				'opacity': 1,
				'color': '#dfdfdf'
			});
			//alert('asd');
		},
		'mouseleave': function(){
			// Resets the tween and changes the element back to its original size
			this.morph({
				'opacity': 0.5,
				'color': '#000000'
			});
		}
		});
	});
	
	
	
	var inObject
			$$('.load-css').each(function(el) {
				el.addEvent('click', function(e) {
					e = new Event(e).stop();
////
	var x = new Chain();
	var one = function() {
		$('loader').setProperty('opacity', '0');
		$('loader').setProperty('display', 'block');
		var page = new Fx.Morph($('loader'), {
						duration: 200,
						transition: 'cubic'
					}).start({'height': 1000});
	};

	var two = function() { var css = new Asset.css(el.get('rel'), { }); };
	
	var three = function() {
		var pagel = new Fx.Morph($('loader'), {
						duration: 200,
						transition: 'cubic'
					}).start({'height': 0});
	};
	x.chain(one);
	x.chain(two);
	x.chain(three);
	x.callChain.delay(500, x);
	x.callChain.delay(20, x);
	x.callChain.delay(800, x);
////
						
						
					
				});
			});





	
});

var Kwix = {

	start: function(){
//	alert('ok');
		Kwix.parseKwicks();
	},

	parseKwicks: function(){

		var squeeze_to = 140;
		var max_width = 350;

		//get original widths
		var start_widths = new Array();
		var kwicks = $$('#kwick .kwick');
		var fx = new Fx.Elements(kwicks, {wait: false, duration: 250, transition:Fx.Transitions.Expo.easeInOut}); //Expo.easeInOut
		kwicks.each(function(kwick, i){

			start_widths[i] = kwick.getStyle('width').toInt();

			//mouse is in, squeeze and expand
			kwick.addEvent('mouseenter', function(e){
				kwick.morph({'opacity': 1});
				var obj = {};
				obj[i] = {
					'width': [kwick.getStyle('width').toInt(), max_width]
						
				};

				var counter = 0;

				kwicks.each(function(other, j){
					if (other != kwick){
						var w = other.getStyle('width').toInt();
						if (w != squeeze_to) obj[j] = {'width': [w,squeeze_to] };
						other.morph({'opacity': 0.5});
					}
				});
				fx.start(obj);
			}
			);
		});

		//mouse is out, squeeze back
		$('kwick').addEvent('mouseleave', function(e){
			var obj = {};
			kwicks.each(function(other, j){
				obj[j] = {'width': [other.getStyle('width').toInt(), start_widths[j]]};
						other.morph({'opacity': 1});
			});
			fx.start(obj);
		});
	}
};

//lock and load!
window.addEvent('domready',Kwix.start);



