//ESKY APP PUBLIC
/**
 * The first two numbers in the century to be used when decoding a two digit year. Since a two digit year is ambiguous (and date.setYear
 * only works with numbers < 99 and so doesn't allow you to set years after 2000) we need to use this to disambiguate the two digit year codes.
 *
 * @name format
 * @type String
 * @cat Plugins/Methods/Date
 * @author Kelvin Luck
 */
Date.fullYearStart = '20';

(function() {

	/**
	 * Adds a given method under the given name
	 * to the Date prototype if it doesn't
	 * currently exist.
	 *
	 * @private
	 */
	function add(name, method) {
		if( !Date.prototype[name] ) {
			Date.prototype[name] = method;
		}
	};

	/**
	 * Checks if the year is a leap year.
	 *
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.isLeapYear();
	 * @result true
	 *
	 * @name isLeapYear
	 * @type Boolean
	 * @cat Plugins/Methods/Date
	 */
	add("isLeapYear", function() {
		var y = this.getFullYear();
		return (y%4==0 && y%100!=0) || y%400==0;
	});

	/**
	 * Checks if the day is a weekend day (Sat or Sun).
	 *
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.isWeekend();
	 * @result false
	 *
	 * @name isWeekend
	 * @type Boolean
	 * @cat Plugins/Methods/Date
	 */
	add("isWeekend", function() {
		return this.getDay()==0 || this.getDay()==6;
	});

	/**
	 * Check if the day is a day of the week (Mon-Fri)
	 *
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.isWeekDay();
	 * @result false
	 *
	 * @name isWeekDay
	 * @type Boolean
	 * @cat Plugins/Methods/Date
	 */
	add("isWeekDay", function() {
		return !this.isWeekend();
	});

	/**
	 * Gets the number of days in the month.
	 *
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.getDaysInMonth();
	 * @result 31
	 *
	 * @name getDaysInMonth
	 * @type Number
	 * @cat Plugins/Methods/Date
	 */
	add("getDaysInMonth", function() {
		return [31,(this.isLeapYear() ? 29:28),31,30,31,30,31,31,30,31,30,31][this.getMonth()];
	});

	/**
	 * Gets the name of the day.
	 *
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.getDayName();
	 * @result 'Saturday'
	 *
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.getDayName(true);
	 * @result 'Sat'
	 *
	 * @param abbreviated Boolean When set to true the name will be abbreviated.
	 * @name getDayName
	 * @type String
	 * @cat Plugins/Methods/Date
	 */
	add("getDayName", function(abbreviated) {
		return abbreviated ? Date.abbrDayNames[this.getDay()] : Date.dayNames[this.getDay()];
	});

	/**
	 * Gets the name of the month.
	 *
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.getMonthName();
	 * @result 'Janurary'
	 *
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.getMonthName(true);
	 * @result 'Jan'
	 *
	 * @param abbreviated Boolean When set to true the name will be abbreviated.
	 * @name getDayName
	 * @type String
	 * @cat Plugins/Methods/Date
	 */
	add("getMonthName", function(abbreviated) {
		return abbreviated ? Date.abbrMonthNames[this.getMonth()] : Date.monthNames[this.getMonth()];
	});

	/**
	 * Get the number of the day of the year.
	 *
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.getDayOfYear();
	 * @result 11
	 *
	 * @name getDayOfYear
	 * @type Number
	 * @cat Plugins/Methods/Date
	 */
	add("getDayOfYear", function() {
		var tmpdtm = new Date("1/1/" + this.getFullYear());
		return Math.floor((this.getTime() - tmpdtm.getTime()) / 86400000);
	});

	/**
	 * Get the number of the week of the year.
	 *
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.getWeekOfYear();
	 * @result 2
	 *
	 * @name getWeekOfYear
	 * @type Number
	 * @cat Plugins/Methods/Date
	 */
	add("getWeekOfYear", function() {
		return Math.ceil(this.getDayOfYear() / 7);
	});

	/**
	 * Set the day of the year.
	 *
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.setDayOfYear(1);
	 * dtm.toString();
	 * @result 'Tue Jan 01 2008 00:00:00'
	 *
	 * @name setDayOfYear
	 * @type Date
	 * @cat Plugins/Methods/Date
	 */
	add("setDayOfYear", function(day) {
		this.setMonth(0);
		this.setDate(day);
		return this;
	});

	/**
	 * Add a number of years to the date object.
	 *
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.addYears(1);
	 * dtm.toString();
	 * @result 'Mon Jan 12 2009 00:00:00'
	 *
	 * @name addYears
	 * @type Date
	 * @cat Plugins/Methods/Date
	 */
	add("addYears", function(num) {
		this.setFullYear(this.getFullYear() + num);
		return this;
	});

	/**
	 * Add a number of months to the date object.
	 *
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.addMonths(1);
	 * dtm.toString();
	 * @result 'Tue Feb 12 2008 00:00:00'
	 *
	 * @name addMonths
	 * @type Date
	 * @cat Plugins/Methods/Date
	 */
	add("addMonths", function(num) {
		var tmpdtm = this.getDate();

		this.setMonth(this.getMonth() + num);

		if (tmpdtm > this.getDate())
			this.addDays(-this.getDate());

		return this;
	});

	/**
	 * Add a number of days to the date object.
	 *
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.addDays(1);
	 * dtm.toString();
	 * @result 'Sun Jan 13 2008 00:00:00'
	 *
	 * @name addDays
	 * @type Date
	 * @cat Plugins/Methods/Date
	 */
	add("addDays", function(num) {
		this.setDate(this.getDate() + num);
		return this;
	});

	/**
	 * Add a number of hours to the date object.
	 *
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.addHours(24);
	 * dtm.toString();
	 * @result 'Sun Jan 13 2008 00:00:00'
	 *
	 * @name addHours
	 * @type Date
	 * @cat Plugins/Methods/Date
	 */
	add("addHours", function(num) {
		this.setHours(this.getHours() + num);
		return this;
	});

	/**
	 * Add a number of minutes to the date object.
	 *
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.addMinutes(60);
	 * dtm.toString();
	 * @result 'Sat Jan 12 2008 01:00:00'
	 *
	 * @name addMinutes
	 * @type Date
	 * @cat Plugins/Methods/Date
	 */
	add("addMinutes", function(num) {
		this.setMinutes(this.getMinutes() + num);
		return this;
	});

	/**
	 * Add a number of seconds to the date object.
	 *
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.addSeconds(60);
	 * dtm.toString();
	 * @result 'Sat Jan 12 2008 00:01:00'
	 *
	 * @name addSeconds
	 * @type Date
	 * @cat Plugins/Methods/Date
	 */
	add("addSeconds", function(num) {
		this.setSeconds(this.getSeconds() + num);
		return this;
	});

	/**
	 * Sets the time component of this Date to zero for cleaner, easier comparison of dates where time is not relevant.
	 *
	 * @example var dtm = new Date();
	 * dtm.zeroTime();
	 * dtm.toString();
	 * @result 'Sat Jan 12 2008 00:01:00'
	 *
	 * @name zeroTime
	 * @type Date
	 * @cat Plugins/Methods/Date
	 * @author Kelvin Luck
	 */
	add("zeroTime", function() {
		this.setMilliseconds(0);
		this.setSeconds(0);
		this.setMinutes(0);
		this.setHours(0);
		return this;
	});

	/**
	 * Returns a string representation of the date object according to Date.format.
	 * (Date.toString may be used in other places so I purposefully didn't overwrite it)
	 *
	 * @example var dtm = new Date("01/12/2008");
	 * dtm.asString();
	 * @result '12/01/2008' // (where Date.format == 'dd/mm/rrrr'
	 *
	 * @name asString
	 * @type Date
	 * @cat Plugins/Methods/Date
	 * @author Kelvin Luck
	 */
	add("asString", function() {
		var r = Date.format;
		return r
			.replace(/(yyyy|rrrr)/i, this.getFullYear())
			.replace(/(yy|rr)/i, (this.getFullYear()+'').substring(2))
			.replace(/mmm/i, this.getMonthName(true))
			.replace(/mm/i, _zeroPad(this.getMonth()+1))
			.replace(/dd/i, _zeroPad(this.getDate()));
	});

	/**
	 * Returns a new date object created from the passed String according to Date.format or false if the attempt to do this results in an invalid date object
	 * (We can't simple use Date.parse as it's not aware of locale and I chose not to overwrite it incase it's functionality is being relied on elsewhere)
	 *
	 * @example var dtm = Date.fromString("12/01/2008");
	 * dtm.toString();
	 * @result 'Sat Jan 12 2008 00:00:00' // (where Date.format == 'dd/mm/rrrr'
	 *
	 * @name fromString
	 * @type Date
	 * @cat Plugins/Methods/Date
	 * @author Kelvin Luck
	 */
	Date.fromString = function(s)
	{
		if(!s) return new Date();

		var f = Date.format;
		var d = new Date('01/01/1977');
		var iY = f.indexOf('rrrr');
		if (iY > -1) {
			d.setFullYear(Number(s.substr(iY, 4)));
		} else {
			// TODO - this doesn't work very well - are there any rules for what is meant by a two digit year?
			d.setFullYear(Number(Date.fullYearStart + s.substr(f.indexOf('rr'), 2)));
		}
		var iM = f.indexOf('mmm');
		if (iM > -1) {
			var mStr = s.substr(iM, 3);
			for (var i=0; i<Date.abbrMonthNames.length; i++) {
				if (Date.abbrMonthNames[i] == mStr) break;
			}
			d.setMonth(i);
		} else {
			d.setMonth(Number(s.substr(f.indexOf('mm'), 2)) - 1);
		}
		d.setDate(Number(s.substr(f.indexOf('dd'), 2)));
		if (isNaN(d.getTime())) {
			return false;
		}
		return d;
	};

	// utility method
	var _zeroPad = function(num) {
		var s = '0'+num;
		return s.substring(s.length-2);
		//return ('0'+num).substring(-2); // doesn't work on IE :(
	};

})();
// ============================== Calendar object ============================== //
/**
 * Calendar object. Needs Date prototype extensions by Jasrn Zaefferer and Brandon Aaron
 *
 * Example:
 * var c = new Calendar();
 * c.setDate({month:7,year:2008});
 * document.write(c.build(2));
 *
 * @constructor
 * @param {string} selected date string
 */
function isDate(string){
	var re = new RegExp("^[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}$","i");
	if (re.test(string) == false || string == '') {
		return false;
	}
	return true;
}
function Calendar(selectedStr) {
	this.date = new Date();
	this.html = '';
	this.selectedStr = (selectedStr); // || new Date().asString() ;

}
/**
 * Sets internal month and year in the Calendar object. Returns array of month and year;
 * @param {int} month
 * @param {int} year
 * @return {object} month and year array
 */
Calendar.prototype.setDate = function(o) {
//alert('In:'+o.month+"/"+o.year);
	var n = new Date();
	this.month = (isNaN(o.month) || o.month == null) ? n.getMonth() : o.month;
	this.year  = (isNaN(o.year) || o.year == null) ? n.getFullYear() : o.year;
//alert('Out:'+this.month+"/"+this.year);
	return {month:this.month,year:this.year};
}
Calendar.prototype.setLinkedDate = function(o) {
	this.linkedDate = o;
}
/**
 * Converts string date to object for easy use with setDate method.
 * @param {string} string
 * @return {object} date as object
 */
Calendar.prototype.dateToObject = function(string) {
	var s = Date.fromString(string);
	if(!s || s.getFullYear()<1900 || string.length<8) var s = new Date();
	//var s = (isDate(string)) ? Date.fromString(string) : new Date();
	return {day:s.getDate(),month:s.getMonth(),year:s.getFullYear()};
}
/**
 * Changes current month and sets new one. Function accepts two values: "next" and "prev".
 * It returns array of new month and year.
 * @param {string} prev or next month
 * @return {object} new month and year
 */
Calendar.prototype.go = function(go) {
	var o = {month:this.month,year:this.year};
	if(go=="next"&&o.month++>=11){
		o.month=0;o.year++;
	}
	if(go=="prev"&&o.month--<=0){
		o.month=11;o.year--;
	}
	//return this.setDate(o);
	return o;
}
/**
 * Builds HTML code with numer of moths specified by function parameter
 * @param {int} number of months to show
 * @return {string} Calendar HTML code
 */
Calendar.prototype.build = function(p) {
	this.generateMonth(this.selectedStr,p);
	for(i=1;i<p.loop;i++) {
		this.setDate(this.go("next"));
		this.generateMonth(this.selectedStr,p);
	}
	return this.html;
}
/**
 * Generates HTML code for one month specified by internal date of Calendar.
 * @param {string} selected date string
 * @return {string} Calendar HTML code
 */
Calendar.prototype.generateMonth = function(selectedStr,p){
	if(!this.month&&!this.year) this.setDate();

	var fd = new Date(this.year, this.month).getDay() - Date.firstDayOfWeek; // First Day
	var monthLength = new Date(this.year, this.month).getDaysInMonth();
	var monthName = Date.monthNames[this.month];

	var pastDates = p.pastDates;
	
	var selected = new Date.fromString(selectedStr);
	var today = new Date().zeroTime();
	var maxOutDate = p.outBlock;
	var maxRetDate = p.inBlock;
	
	var blocked = new Date().zeroTime().addDays(p.blockedDays);
	var linked = (this.linkedDate) ? new Date(this.linkedDate.year,this.linkedDate.month,this.linkedDate.day).zeroTime() : false ;

	var html = '<table class="calendar-table" cellpadding="0" cellspacing="0">';
	html += '<tr><th colspan="7">'+monthName + "&nbsp;" + this.year+'</th></tr>';
	html += '<tr class="calendar-header">';
	for(var i = Date.firstDayOfWeek, j=0; i <= 12; i++ ){
		html += '<td class="calendar-header-day">'+Date.abbrDayNames[(i>6) ? i-7 : i]+'</td>';
		if(j++>=6) break;
	}
	html += '</tr><tr>';

	var day = 1;
	for (var i = 0; i < 9; i++) {
	for (var j = 0; j <= 6; j++) {
		html += '<td class="calendar-day">';
		if (day <= monthLength && (i > 0 || j >= ((fd>=0) ? fd : 7+fd))) {
			var calDay = new Date(this.year,this.month,day).zeroTime();
			css = 'month-day';
			css += (calDay-today==0) ? ' is-today' : '';
			css += (calDay.isWeekend()) ? ' is-weekend' : '';
			css += (calDay<blocked) ? ' is-blocked' : '';
			css += (calDay<today && !pastDates) ? ' is-disabled' : '';
			css += (calDay-selected==0) ? ' is-selected' : '';
			css += (linked&&calDay<linked) ? ' is-linked-disabled' : '';
			if (p.service == 'insurances') {
				css += (calDay < new Date().zeroTime().addDays(2) && calDay >= new Date().zeroTime()) ? ' only-cc-payment-insurances' : '';
			}
			else if (p.service != 'hotels') {
				css += (calDay < new Date().zeroTime().addDays(2) && calDay > new Date().zeroTime()) ? ' only-cc-payment-flights' : '';
			}
			css += (linked&&calDay-linked==0) ? ' is-linked' : '';
			css += (!linked&&calDay>maxOutDate || linked&&calDay>maxRetDate) ? ' is-out-of-range' : '';
			html += '<a class="'+css+'" rel="'+calDay.asString()+'">'+day+'</a>';
			day++;
		} else {
			html += '&nbsp;';
		}
		html += '</td>';
	}
	if (day > monthLength) { break; } else { html += '</tr><tr>'; }
	}
	html += '</tr></table>';
	this.html += html;
	return this.html;
}
/**
 * Builds event calendar's HTML code with number of moths specified by function parameter
 * @param {int} number of months to show
 * @return {string} Calendar HTML code
 */
Calendar.prototype.buildEC = function(p) {
	this.generateECMonth(this.selectedStr,p);
	for(i=1;i<p.loop;i++) {
		this.setDate(this.go("next"));
		this.generateECMonth(this.selectedStr,p);
	}
	return this.html;
}
/**
 * Generates event calendar's HTML code for one month specified by internal date of Calendar.
 * @param {string} selected date string
 * @return {string} Calendar HTML code
 */
Calendar.prototype.generateECMonth = function(selectedStr,p){
	if(!this.month&&!this.year) this.setDate();

	var fd = new Date(this.year, this.month).getDay() - Date.firstDayOfWeek; // First Day
	var monthLength = new Date(this.year, this.month).getDaysInMonth();
	var monthName = Date.monthNames[this.month];

	var selected = new Date.fromString(selectedStr);
	var today = new Date().zeroTime();
	var eventDates = p.eventDates;

	var html = '<table class="calendar-table" cellpadding="0" cellspacing="0">';
	html += '<tr><th colspan="7">'+monthName + "&nbsp;" + this.year+'</th></tr>';
	html += '<tr class="calendar-header">';
	for(var i = Date.firstDayOfWeek, j=0; i <= 12; i++ ){
		html += '<td class="calendar-header-day">'+Date.abbrDayNames[(i>6) ? i-7 : i]+'</td>';
		if(j++>=6) break;
	}
	html += '</tr><tr>';

	var day = 1;
	for (var i = 0; i < 9; i++) {
	for (var j = 0; j <= 6; j++) {
		html += '<td class="calendar-day">';
		if (day <= monthLength && (i > 0 || j >= ((fd>=0) ? fd : 7+fd))) {
			var calDay = new Date(this.year,this.month,day).zeroTime();
			css = 'month-day';
			css += (eventDates.indexOf(calDay.asString())==-1) ? ' is-disabled' : ' has-event';
			css += (calDay-today==0) ? ' is-today' : '';
			css += (calDay.isWeekend()) ? ' is-weekend' : '';
			css += (calDay-selected==0) ? ' is-selected' : '';
			html += '<a class="'+css+'" rel="'+calDay.asString()+'">'+day+'</a>';
			day++;
		} else {
			html += '&nbsp;';
		}
		html += '</td>';
	}
	if (day > monthLength) { break; } else { html += '</tr><tr>'; }
	}
	html += '</tr></table>';
	this.html += html;
	return this.html;
}
// ============================== Calendar object ============================== //

// ============================== jQuery extension for Calendar ============================== //
jQuery.extend({
	esky_calender_translate: {
		'OutGreaterThenReturn' : 'Out date is greater then in date.',
		'OutDateToClose' : 'Out date is to close to current date.',
		'DateOutOfRange' : 'Selected date is out of range.'
	}
});
jQuery.fn.extend({
	esky_calendar_render: function(parameters) {
		$this = $(this);
		var defaults = {
			thisInput: false,
			linkedInput: false,
			month: null,
			year: null,
			loop: 1,
			go: false,
			fade: false,
			outBlock: new Date().zeroTime().addDays(364),
			inBlock: new Date().zeroTime().addDays(363),
			blockedDays: 0,
			allowSameDay: false,
			service: false,
			pastDates: false
		};
		var p = $.extend({},defaults, parameters);

		var tI = document.getElementById(p.thisInput).value;

		var c = new Calendar(tI);

		if (p.linkedInput!=false) {
			var lI = document.getElementById(p.linkedInput).value;
			// Use linked date from other input field (other calendar) only if
			// this input and linked input have diffrernt names and
			// date is not set or calendar was displayed by navigating with buttons
			if (p.thisInput != p.linkedInput && (!p.month && !p.year)) {
				$.extend(p, c.dateToObject(lI));
				c.setLinkedDate(c.dateToObject(lI));
			}
			if (p.thisInput != p.linkedInput && ((!p.month && !p.year) || p.go != false)) {
				c.setLinkedDate(c.dateToObject(lI));
			}
		}

		var d = (!p.month && !p.year) ? c.dateToObject(tI) : p ;
		c.setDate(d);

		var pv = $.extend({},p,c.go("prev"),{go:"prev"});
		var px = $.extend({},p,c.go("next"),{go:"next"});

		var cd = new Date();
		var pc = $.extend({},p,{month:cd.getMonth(),year:cd.getFullYear(),go:true});

		$this
			.html(c.build(p))
			.prepend(
				$('<div class="calendar-navigation"></div>').
				prepend(
					$('<a href="javascript:void(0);" class="calendar-button calendar-next" title="'+cal_text.NEXT+'">&raquo;</a>').click(function(e){
					$this.esky_calendar_render(px);
					e.stopPropagation();
					}))
				.prepend($('<a href="javascript:void(0);" class="calendar-button calendar-current">'+cal_text.THISMONTH+'</a>').click(function(){$this.esky_calendar_render(pc)}))
				.prepend($('<a href="javascript:void(0);" class="calendar-button calendar-previous" title="'+cal_text.PREV+'">&laquo;</a>').click(function(e){
					$this.esky_calendar_render(pv);
					e.stopPropagation();
				}))
			)
			.append($('<div class="calendar-navigation"></div>')
				.prepend($('<a href="javascript:void(0);" class="calendar-button calendar-close">'+cal_text.CLOSE+'</a>').click(function(){$this.remove()}))
			);

		$('a.month-day').not('.is-disabled,.is-blocked')
		.click(function(){
			$('#'+p.thisInput).not(':disabled').val( $(this).attr('rel') ).removeClass('virgin').blur().trigger('change');
			$('#custom-field-help').remove();
			/*if(typeof(calculateCheckoutDate)=='function') calculateCheckoutDate(p.thisInput);*/ // Only for HOTELS ASF
			$this.remove();
		})
		.mouseover(function(){
			$(this).addClass('is-hover');
		})
		.mouseout(function(){
			$(this).removeClass('is-hover');
		});

		if(p.allowSameDay==false){
			$('a.is-linked').not('.is-disabled').unbind().click(function(){
				return false;
			});
		}
		$('a.is-blocked').not('.is-disabled,.is-linked,.is-linked-disabled').unbind().click(function(){
			return false;
		});
		$('a.is-out-of-range').unbind().click(function(){
			return false;
		});
		$('a.is-disabled,a.is-linked-disabled').unbind().click(function(){
			return false;
		});
		if(!p.pastDates) {
			$('a.only-cc-payment-flights').not('.is-disabled').tipBox(TXT_OnlyCCPaymentFlights);
			$('a.only-cc-payment-insurances').not('.is-disabled').tipBox(TXT_OnlyCCPaymentInsurances);
		};

		$this.bgIframe();
		return $this;
	},
	esky_calendar: function(parameters){
		if ($('#esky_calendar').size()>0) {
			$('#esky_calendar').remove();
			return false;
		}
		var $this = $(this);
		var input = $('#'+$this.attr('rel'));
		var xy = input.offset();
		$('body').append(
			$('<div></div>')
			.attr('id','esky_calendar')
			.css({position:'absolute',top:xy.top+input.height()+8,left:xy.left})
			.hide()
		);
		if(parameters.fade>0){
			$('#esky_calendar').esky_calendar_render(parameters).fadeIn(parameters.fade);
		}else{
			$('#esky_calendar').esky_calendar_render(parameters).show();
		}
		return $this;
	},
	event_calendar_render: function(parameters) {
		$this = $(this);
		var defaults = {
			month: null,
			year: null,
			loop: 1,
			go: false,
			blockedDays: 0,
			eventDates: null
		};

		var p = $.extend({},defaults, parameters);

		var today = new Date();
		var tI = today.asString();

		var c = new Calendar($this.attr('title'));

		var d = (!p.month && !p.year) ? c.dateToObject(tI) : p ;
		c.setDate(d);

		var pv = $.extend({},p,c.go("prev"),{go:"prev"});
		var px = $.extend({},p,c.go("next"),{go:"next"});

		var cd = new Date();
		var pc = $.extend({},p,{month:cd.getMonth(),year:cd.getFullYear(),go:true});

		$this
			.html(c.buildEC(p))
			.prepend(
				$('<div class="calendar-navigation"></div>').
				prepend(
					$('<a href="javascript:void(0);" class="calendar-button calendar-next" title="'+cal_text.NEXT+'">&raquo;</a>').click(function(e){
					$this.event_calendar_render(px);
					e.stopPropagation();
					}))
				.prepend($('<a href="javascript:void(0);" class="calendar-button calendar-previous" title="'+cal_text.PREV+'">&laquo;</a>').click(function(e){
					$this.event_calendar_render(pv);
					e.stopPropagation();
				}))
			);
		$this.slideDown('normal');

		$('a.month-day').not('.is-disabled,.is-blocked')
		.click(function(){
			$('#eventCalendar')
				.find('a.is-selected').removeClass('is-selected').end()
				.attr('title', $(this).attr('rel'));
			$(this).addClass('is-selected');
			$('div.panel-content-sub div.content').prepend('<div class="ajaxPI">' + TXT_PLEASEWAIT + '</div>');
			var pubDate = $(this).attr('rel');
			$.post(ibeConfig.pressFindByDate, {date:pubDate}, function(data){
				var press_found = '';
				for (var r in data) {
					if (r>0) {
						press_found += '<p class="separated"></p>';
					}
					press_found += '<h2>';
					if (data[r].press_releasetype == 1) {
						press_found += 'Konferencja: ';
					}
					press_found += data[r].press_title;
					if (data[r].source_image != undefined)
						press_found += '<img class="press-logo" src="/images/press/sources/big-' + data[r].source_image + '" alt="' + data[r].press_source + '" title="' + data[r].press_source + '" />';

					press_found += '</h2>';
					press_found += '<p class="pub-date"><span>' + data[r].press_date + '</span></p><div class="clear"></div>';
					press_found += data[r].press_content;
					if (data[r].press_source != undefined) {
						press_found += '<p class="source"><span>źródło: ' + data[r].press_source + '</span></p><div class="clear"></div>';
					}
				}
				press_found += '<p><a class="back" href="' + ibeConfig.press + '">powrót do działu "dla prasy"</a></p>';
				$('div.panel-content-sub div.content div.ajaxPI').slideUp('fast', function(){
					$(this).parent().empty().append(press_found).fadeIn('slow');
				});
				$('div#breadcrumbs div.content').empty().append('<a href="' + ibeConfig.host + '/">Strona główna</a> &raquo; <a href="' + ibeConfig.press + '">Dla prasy</a> &raquo; <strong>Informacje prasowe, ' + pubDate + '</strong>');
			}, 'json');
		})
		.mouseover(function(){
			$(this).addClass('is-hover');
		})
		.mouseout(function(){
			$(this).removeClass('is-hover');
		});

		if(p.allowSameDay==false){
			$('a.is-linked').not('.is-disabled').unbind().click(function(){
				return false;
			});
		}
		$('a.is-blocked').not('.is-disabled,.is-linked,.is-linked-disabled').unbind().click(function(){
			return false;
		});
		$('a.is-out-of-range').unbind().click(function(){
			return false;
		});
		$('a.is-disabled,a.is-linked-disabled').unbind().click(function(){
			return false;
		});

		return $this;
	},
	event_calendar: function(){
		var $this = $(this);
		$.post(ibeConfig.pressCalendar, null, function(data){
			$this.event_calendar_render({eventDates: data});
		});
		return $this;
	}
});
// ============================== jQuery extension for Calendar ============================== //
