calendar = {
	draw : function(div,input){
		
			$('#' + div).datepicker({
					onSelect: function(date) {
						calendar.selectit(date, div,input);
						
					},
					prevText: '<',
					nextText: '>',
					changeMonth: false,
					changeYear: false,
					currentText: '',
					dayNamesMin: ['D', 'L', 'M', 'M', '$', 'V', 'S'],
					dateFormat: 'yy-mm-dd',
					timeFormat:'hh:ii',
					showOtherMonths: true
				//	beforeShowDay: calendar.eventsDay
				});
	},
	eventsDay : function(date) {
		//alert(calendar.eventsDates.length);
	    for (i = 0; i < calendar.eventsDates.length; i++) {
	      if (date.getMonth() == calendar.eventsDates[i][0] - 1 && date.getDate() == calendar.eventsDates[i][1]) {
	        return [true, 'event'];
	      }
	    }
	  return [true, ''];
	},
	toggle : function(div){
		$('#' + div).toggle();

	},
	selectit :function(date,div,el){
		y = date.substr(0,4);
		m = date.substr(5,2);
		d = date.substr(8,2);
		h = date.substr(11,2);
		min = date.substr(14,2);

		$('#' + el +'Year option[value='+y+']').attr('selected', 'selected');
		$('#' + el +'Month option[value='+m+']').attr('selected', 'selected');
		$('#' + el +'Day option[value='+d+']').attr('selected', 'selected');
		$('#' + el +'Hour option[value='+h+']').attr('selected', 'selected');
		$('#' + el +'Min option[value='+min+']').attr('selected', 'selected');
		calendar.toggle(div);
	
	}
}

function loadPiece(divName) {    
	$("#pagination a").bind('click', function() {
		var thisHref = $(this).attr("href"); 	
		$("#" + divName).load(thisHref);

	   	return false;
	});
}

/* ------------------------------------------------------------------------
	jQuery plugin to make the columns of equal heights.
	Author: Stephane Caron
------------------------------------------------------------------------- */

$.fn.equalHeight = function(offset) {
	var highestCol = 0;
	if(!offset) offset = 0;
	
	$(this).each(function(){
		if($(this).height() > highestCol) highestCol = $(this).height();
	});
	
	if($.browser.msie) {
		$(this).height(highestCol + offset);
	}else{
		$(this).css('min-height',highestCol + offset);
	}
}

/* ------------------------------------------------------------------------
	jQuery plugin to make fix the width on a column based on an
	element contained inside it.
	Author: Stephane Caron
------------------------------------------------------------------------- */

$.fn.fixWidth = function(element) {
	$(this).each(function(){
		if($(this).find(element+':first')[0].nodeName.toUpperCase() == "IMG"){
			var $container = $(this);
			myImage = new Image();
			myImage.src = $(this).find(element+':first').attr('src');
			myImage.onload = function(){
				$container.width($container.find(element+':first').width());
			}
		}else{
			$(this).width($(this).find(element+':first').width());
		}
	});
}