// JavaScript Document

var CalendarEventScroller =  new Class({
	
	initialize: function(element, options) {
		this.setOptions({
						movePrev:"",
						moveNext:""
						}, options);
	
	this.el = $(element);
	this.elID = element; 
	this.currentChosen=0;
	this.movePrev =$(this.options.movePrev);
	this.moveNext =$(this.options.moveNext);
	this.contentPrefix = this.options.contentPrefix;
	this.contentCount=0;
	
	this.contentHandlers = $$('#' + this.elID + ' li');
	//this.contentPrefix = 'calEv';
	
	this.scroll_fx = new Fx.Scroll(this.elID, {
	wait: false,
	duration: 800,
	offset: {'x': 3, 'y': 0},
	transition: Fx.Transitions.Quad.easeInOut
});
	
	this.contentHandlers.each(function(item, index) {
    if(index%3==0) {
		item.setProperty('id', this.contentPrefix +'_' + index/3);
		this.contentCount=this.contentCount+1;
	}
	}.bind(this)); 
	
	this.movePrev.addEvent('click', function(event) {
	event = new Event(event).stop();
	if(this.currentChosen!=0) {
	this.scroll_fx.toElement(this.contentPrefix +'_' + (this.currentChosen-1));
	this.currentChosen=this.currentChosen-1;
	}
	
	this.changeActivity();
	
	}.bind(this));
	
	
	this.moveNext.addEvent('click', function(event) {
	event = new Event(event).stop();
	if(this.currentChosen<(this.contentCount -1)) {
	this.scroll_fx.toElement(this.contentPrefix +'_' + (this.currentChosen+1));
	this.currentChosen=this.currentChosen+1;
	}
	
	this.changeActivity();
	
	}.bind(this));
	

	this.changeActivity();
	},
	
	changeActivity: function() {
	if(this.currentChosen>0) this.movePrev.removeClass('notActive'); else this.movePrev.addClass('notActive');
	if(this.currentChosen<this.contentCount-1) this.moveNext.removeClass('notActive'); else this.moveNext.addClass('notActive');	
	}
	});

CalendarEventScroller.implement(new Options);

var CalendarMonthChangeR = new Class({
									
	initialize:function(){
	this.reinitialize();	
	},
	
	reinitialize: function()
	{
	this.movePrev =$('monthPrev1');
	this.moveNext =$('monthNext1');
	
	
	this.NextLink = $('monthNext1').getProperty('title');
	$('monthNext1').removeProperty('title');
	
	this.PrevLink = $('monthPrev1').getProperty('title');
	$('monthPrev1').removeProperty('title');
	

	this.zapytanie = new Ajax('/calendar_right_generate.php',
							  {
								  update: $('js_calendar_td'),
								  method: 'get', 

								  onRequest: function()
								  {
									  $('js_calendar_td').setHTML('<br/><br/><br/><br/><br/><p align=center>ŁADUJE</p>');	  
								  },
								  onComplete: function()
								  {
									  this.reinitialize()
								  }.bind(this)});	
		
		
	
	$('monthNext1').addEvent('click', function() {
	this.zapytanie.options.update = $('js_calendar_td');
	this.zapytanie.options.data = 'pobierz='+this.NextLink;
    this.zapytanie.request();
	}.bind(this));
	
	$('monthPrev1').addEvent('click', function() {
	this.zapytanie.options.update = $('js_calendar_td');
	this.zapytanie.options.data = 'pobierz='+this.PrevLink;
    this.zapytanie.request();
	}.bind(this));
	
	}
});

var CalendarMonthChangeM = new Class({
									
	initialize:function(){
	this.reinitialize();	
	},
	
	reinitialize: function()
	{
	this.movePrev =$('monthPrev2');
	this.moveNext =$('monthNext2');
	
	
	this.NextLink = $('monthNext2').getProperty('title');
	$('monthNext2').removeProperty('title');
	
	this.PrevLink = $('monthPrev2').getProperty('title');
	$('monthPrev2').removeProperty('title');
	

	this.zapytanie = new Ajax('/calendar_right_generate.php',
							  {
								  update: $('js_calendar_td1'),
								  method: 'get', 

								  onRequest: function()
								  {
									  $('js_calendar_td1').setHTML('<br/><br/><br/><br/><br/><p align=center>ŁADUJE</p>');	  
								  },
								  onComplete: function()
								  {
									  this.reinitialize()
								  }.bind(this)});	
		
		
	
	$('monthNext2').addEvent('click', function() {
	this.zapytanie.options.update = $('js_calendar_td1');
	this.zapytanie.options.data = 'pobierz='+this.NextLink;
    this.zapytanie.request();
	}.bind(this));
	
	$('monthPrev2').addEvent('click', function() {
	this.zapytanie.options.update = $('js_calendar_td1');
	this.zapytanie.options.data = 'pobierz='+this.PrevLink;
    this.zapytanie.request();
	}.bind(this));
	
	}
});

