	

	var TextSize = {
		config: {
			minSize: 8,
			maxSize: 18,
			defaultSize: 11
		},
		init: function() {
			$$('.text-big').addEvent('click', function(e) { e.stop(); TextSize.increaseSize(); });
			$$('.text-default').addEvent('click', function(e) { e.stop(); TextSize.resetSize(); });
			$$('.text-small').addEvent('click', function(e) { e.stop(); TextSize.decreaseSize(); });
		},
		increaseSize: function() {
		   $$('p').each( function(elem) {
		   		var fontSize = elem.getStyle('font-size');
		   		var newFontSize = parseInt(fontSize) + 1;
		   		if( newFontSize <= TextSize.config.maxSize ) {
			   		elem.setStyle('font-size',newFontSize);
			    }
		   });
		},
		decreaseSize: function() {
			$$('p').each( function(elem) {
		   		var fontSize = elem.getStyle('font-size');
		   		var newFontSize = parseInt(fontSize) - 1;
		   		if( newFontSize >= TextSize.config.minSize ) {
			   		elem.setStyle('font-size',newFontSize);
			    }
		   });
		},
		resetSize: function() {
			$$('p').each( function(elem) {
				elem.setStyle('font-size', TextSize.config.defaultSize );
			});
		}
	}	
	
	var ArchivesWidget = {
	   
	   config: {
	       archivesUrl: '/archiwum_content/index.php'
	   },
	
	   init: function() {
	       if( $chk( $('archives-widget') ) !== false ) {
	       
	           //Get the initial widget
	           var req = new Request({
                    url: ArchivesWidget.config.archivesUrl,
                    encoding: 'utf-8',
                    method: 'get',
                    data: 'external=true',
                    noCache: true,
                    onSuccess: function(response) {
                        $('archives-container').set('html', response );
                        //Init the form
	                    ArchivesWidget.initForm();
                    }.bind(this)
               }).send();
	       }
	   },
	   
	   initForm: function() {
	   	       
	       $('archive-search-form').addEvent('submit', function(e) {
	           e.stop();
	           
	           var passphraze = $('search-passphraze').get('value');
	           var yearsFrom  = $('search-years-from').get('value');
	           var yearsTo    = $('search-years-to').get('value');
	           
	           var req = new Request({
                    url: ArchivesWidget.config.archivesUrl,
                    method: 'get',
                    data: 'external=true&passphraze=' + passphraze + '&years_from=' + yearsFrom + '&years_to=' + yearsTo,
                    noCache: true,
                    onRequest: function() {
                        var statusMsg = new Element('span', {
                            'class' : 'working',
                            'html'  : 'trwa wyszukiwanie...'
                        });
                        
                        statusMsg.inject( $('submit-search'), 'before' );
                    },
                    onSuccess: function(response) {
                        $('archives-container').set('html', response );
                        
                        //Init the form
	                    ArchivesWidget.initForm();
                    }.bind(this)
               }).send();
	   
	       });
	   }
	
	}
	
	window.addEvent('domready', function() {
	
		// Text resize module
		TextSize.init();
		
		// Archives widget
		ArchivesWidget.init();
		
		// Newsletter element
		$('newsletter').addEvent( 'click', function(e) { e.stop(); $('newsletter-box').toggle(); });
		$('newsbutton').addEvent( 'click', function(e) { e.stop(); $('newsletter-box').toggle(); });
		$('newsletter-footer').addEvent( 'click', function(e) { e.stop(); window.scroll(0,0); $('newsletter-box').toggle(); });
		
		//variables for making things more simple below
		var itemsHolder = $('mt-container');
		var myItems = $$('.mt-list-item');
		var thePrevBtn = $('strzalalewa');
		var theNextBtn = $('strzalaprawa');
		
		//create an instance of the slider, and start it up
		if( $chk( $('mt-container') ) ) {
			var mySlider = new SL_Slider({
				slideTimer: 6000,
				isPaused: true,
				container: itemsHolder,
				items: myItems,
				prevBtn: thePrevBtn,
				nextBtn: theNextBtn
			});
			mySlider.start();
		}
		
		$('most-read-list').addEvent('click', function(e) {
			e.stop();
			this.addClass('selected');
			$('most-comments-list').removeClass('selected');
			$$('ul.most-comments-list')[0].setStyle('display','none');
			$$('ul.most-read-list')[0].setStyle('display','block')
		});
		
		$('most-comments-list').addEvent('click', function(e) {
			e.stop();
			this.addClass('selected');
			$('most-read-list').removeClass('selected');
			$$('ul.most-read-list')[0].setStyle('display','none');
			$$('ul.most-comments-list')[0].setStyle('display','block')
		});
	});
