// Spring calendar jQuery plugin
(function($){  
$.fn.springCalendar = function(options) {  
	var defaults = {};
	var options = $.extend(defaults, options);
	var l = {
    	"el" : {
        	"dayNamesShort" : ['Κυρ','Δευτ','Τριτ','Τετ','Πεμ','Παρ','Σαβ'],
        	"monthNames" : ['Ιανουάριος', 'Φεβρουάριος', 'Μάρτιος', 'Απρίλιος', 'Μαϊος',
                        	'Ιούνιος', 'Ιούλιος','Αύγουστος', 'Σεπτέμβριος', 'Οκτώβριος',
                        	'Νοέμβριος', 'Δεκέμβριος']
    	}
	}
    
	return this.each(function(index,el) {
   	 
    	// Create unique ID
    	var wrapId = "spring_eventcalendar_" + index;
    	$(this).attr('id',wrapId);
   	 
    	$calendar = $(this).find('.calendar_area');
   	 
    	$calendar.fullCalendar({
        	header: {
            	left:   'prev',
            	center: 'title',
            	right:  'next'
        	},
        	buttonText: {
            	prev: '',
            	next: ''
        	},
        	dayNamesShort: options.lang == 'el' ? l.el.dayNamesShort : [],
        	monthNames: options.lang == 'el' ? l.el.monthNames : [],
        	titleFormat: {
             	month: 'MMMM'
        	},
        	events: $calendar.attr('rel'),
        	loading: function(isLoading) {
       		 $('.qtip').remove();
       		 $('.tx-springevents-pi1 .calendar_area .fc-content table tbody tr.fc-last td.fc-other-month div').css('height',0);
            	if (isLoading) {
           		 
                	$('#'+wrapId + ' .loading').show();
                	$('#'+wrapId + ' .calendar_area').css({'opacity':'0.3', 'margin-top':'-6px'});
					
					if ($.browser.msie) {
						if($.browser.version=='7.0' ){
							$('#'+wrapId + ' .calendar_area').css({'position':'relative', 'top':'-16px'});
						}
						else{
							$('#'+wrapId + ' .calendar_area').css({'position':'relative', 'top':'-22px'});
						}
					}
                	$('.tx-springevents-pi1 .calendar_area .fc-header tbody tr td.fc-header-left').css('margin-left',0);
                	// Remove any classes added in eventRender
                	var d = $calendar.fullCalendar('getDate');
					var previousM = d.getMonth()-1;
					var nextmonth = d.getMonth()+1;
					$('.fc-day-number').removeClass('month-'+previousM);
					$('.fc-day-number').removeClass('month-'+nextmonth);
					 
					$('.fc-day-number').removeClass('event-day');
					
					$('td:not(.fc-other-month) .fc-day-number').each(function(){
						
						if($(this).data('qtip')){
						
							$(this).data('qtip').options.content.text= '';
							
						}
					});
					
            	} else {
						if ($.browser.msie) {
							$('#'+wrapId + ' .calendar_area').css({'position':'relative', 'top':'0px'});
						}
						$('.tx-springevents-pi1 .calendar_area .fc-header tbody tr td.fc-header-left').css('margin-left','16px');
           		 
						$('#'+wrapId + ' .calendar_area').css('opacity','1');
						$('#'+wrapId + ' .loading').hide();
   			 
            	}
        	},
        	 
        	// Color the days with events
        	eventRender: function(event, element) {
			
				$('.qtip').remove();
      	 
				var shared = {
					  prerender: true,
						overwrite : true,
						position : {
							my : 'top center',
							at : 'bottom center',
							adjust : {
								screen : true
							}
						},
						style : {
						classes : 'ui-tooltip-ajax ui-tooltip-light ui-tooltip-shadow ui-tooltip-rounded-link'
						},
						hide : {
							delay: 100,
							fixed: true
						}
				};
      	 
				var tempContent1='';
				
            	var startDate = new Date(event.start);
            	var startDay = startDate.getDate();
            	var endDate = new Date(event.end);
            	var endDay = endDate.getDate();
				
            	var month = event.month;
          	 
            	var startMonth = startDate.getMonth();
            	var endMonth = endDate.getMonth();
				var endYear = endDate.getYear();
				
				var d = $calendar.fullCalendar('getDate');
				var currMonth = d.getMonth();
				
				
				if(month==12){
					month=0;
				}
				
				if(endMonth || endYear!==70){//multiple day event
					
						if(startMonth==endMonth){//multiple day event in the same month
							
							var i=startDay;
							
							if(month == startMonth){
								for(i=startDay;i<=endDay;i++){
									var $box = $('td:not(.fc-other-month) .fc-day-number').filter(function() {

										return $(this).text() == i;
									});
									$box.parent().find('.fc-day-number').addClass('month-'+month);
									$box.parent().find('.fc-day-number').addClass('event-day');
								
									if( $box.data('qtip') ) {
										
											 tempContent1 = $box.data('qtip').options.content.text;
										 
											 if(tempContent1.indexOf(event.title) >= 0){
												 
												 if($box.closest('td').hasClass('fc-thu') || $box.closest('td').hasClass('fc-fri') || $box.closest('td').hasClass('fc-sat')){
													 $box.qtip( $.extend({}, shared, {
															 content : {
																	 text : tempContent1
																},
																position : {
																	my : 'top right',
																	at : 'bottom center',
																	adjust : {
																		screen : true
																	}
															}
															 }));
												 }
												 else{
													$box.qtip( $.extend({}, shared, {
														 content : {
																 text : tempContent1
															}
														 }));
												 }
											 }
											 else{
												if(tempContent1){
													
													tempContent1 = tempContent1 +'<a href="'+event.url+'">'+event.title+'</a>';
													
													if($box.closest('td').hasClass('fc-thu') || $box.closest('td').hasClass('fc-fri') || $box.closest('td').hasClass('fc-sat')){
														 $box.qtip( $.extend({}, shared, {
																 content : {
																		 text : tempContent1
																	},
																	position : {
																		my : 'top right',
																		at : 'bottom center',
																		adjust : {
																			screen : true
																		}
																}
																 }));
													 }
													 else{
														$box.qtip( $.extend({}, shared, {
															 content : {
																	 text : tempContent1
																}
															 }));
													 }
													
												}
												else{
													if($box.closest('td').hasClass('fc-thu') || $box.closest('td').hasClass('fc-fri') || $box.closest('td').hasClass('fc-sat')){
														 $box.qtip( $.extend({}, shared, {
																 content : {
																		 text : '<a href="'+event.url+'">'+event.title+'</a>'
																	},
																	position : {
																		my : 'top right',
																		at : 'bottom center',
																		adjust : {
																			screen : true
																		}
																}
																 }));
													 }
													 else{
														$box.qtip( $.extend({}, shared, {
															 content : {
																	 text : '<a href="'+event.url+'">'+event.title+'</a>'
																}
															 }));
													 }
												 }
											 }
										
									
									}
									else{
										
										if($box.closest('td').hasClass('fc-thu') || $box.closest('td').hasClass('fc-fri') || $box.closest('td').hasClass('fc-sat')){
											$box.qtip( $.extend({}, shared, {
											 content : {
													text : '<a href="'+event.url+'">'+event.title+'</a>'
												},
											 position : {
												my : 'top right',
												at : 'bottom center',
												adjust : {
													screen : true
												}
											}
											 }));
										}
										else{
											$box.qtip( $.extend({}, shared, {
												content : {
												text : '<a href="'+event.url+'">'+event.title+'</a>'
											}
											}));
										}
									
									}
								
								
								
								
							}
						}
						
					}
					if(startMonth < endMonth){//multiple day event - more than one month
					
						if(startMonth==month){
						
							var i=startDay;
							for(i=startDay;i<=31;i++){
									var $box = $('td:not(.fc-other-month) .fc-day-number').filter(function() {

										return $(this).text() == i;
									});
									$box.parent().find('.fc-day-number').addClass('month-'+month);
									$box.parent().find('.fc-day-number').addClass('event-day');
								
									if( $box.data('qtip') ) {
										
											 tempContent1 = $box.data('qtip').options.content.text;
										 
											 if(tempContent1.indexOf(event.title) >= 0){
												 
												 if($box.closest('td').hasClass('fc-thu') || $box.closest('td').hasClass('fc-fri') || $box.closest('td').hasClass('fc-sat')){
													 $box.qtip( $.extend({}, shared, {
															 content : {
																	 text : tempContent1
																},
																position : {
																	my : 'top right',
																	at : 'bottom center',
																	adjust : {
																		screen : true
																	}
															}
															 }));
												 }
												 else{
													$box.qtip( $.extend({}, shared, {
														 content : {
																 text : tempContent1
															}
														 }));
												 }
											 }
											 else{
												if(tempContent1){
													
													tempContent1 = tempContent1 +'<a href="'+event.url+'">'+event.title+'</a>';
													
													if($box.closest('td').hasClass('fc-thu') || $box.closest('td').hasClass('fc-fri') || $box.closest('td').hasClass('fc-sat')){
														 $box.qtip( $.extend({}, shared, {
																 content : {
																		 text : tempContent1
																	},
																	position : {
																		my : 'top right',
																		at : 'bottom center',
																		adjust : {
																			screen : true
																		}
																}
																 }));
													 }
													 else{
														$box.qtip( $.extend({}, shared, {
															 content : {
																	 text : tempContent1
																}
															 }));
													 }
													
												}
												else{
													if($box.closest('td').hasClass('fc-thu') || $box.closest('td').hasClass('fc-fri') || $box.closest('td').hasClass('fc-sat')){
														 $box.qtip( $.extend({}, shared, {
																 content : {
																		 text : '<a href="'+event.url+'">'+event.title+'</a>'
																	},
																	position : {
																		my : 'top right',
																		at : 'bottom center',
																		adjust : {
																			screen : true
																		}
																}
																 }));
													 }
													 else{
														$box.qtip( $.extend({}, shared, {
															 content : {
																	 text : '<a href="'+event.url+'">'+event.title+'</a>'
																}
															 }));
													 }
												 }
											 }
										
									
									}
									else{
										
										if($box.closest('td').hasClass('fc-thu') || $box.closest('td').hasClass('fc-fri') || $box.closest('td').hasClass('fc-sat')){
											$box.qtip( $.extend({}, shared, {
											 content : {
													text : '<a href="'+event.url+'">'+event.title+'</a>'
												},
											 position : {
												my : 'top right',
												at : 'bottom center',
												adjust : {
													screen : true
												}
											}
											 }));
										}
										else{
											$box.qtip( $.extend({}, shared, {
												content : {
												text : '<a href="'+event.url+'">'+event.title+'</a>'
											}
											}));
										}
									
									}
								
								
								
								
							}
							
						}
						if(endMonth==month){
							
							var i=1;
							for(i=1;i<=endDay;i++){
									var $box = $('td:not(.fc-other-month) .fc-day-number').filter(function() {

										return $(this).text() == i;
									});
									$box.parent().find('.fc-day-number').addClass('month-'+month);
									$box.parent().find('.fc-day-number').addClass('event-day');
								
									if( $box.data('qtip') ) {
										
											 tempContent1 = $box.data('qtip').options.content.text;
										 
											 if(tempContent1.indexOf(event.title) >= 0){
												 
												 if($box.closest('td').hasClass('fc-thu') || $box.closest('td').hasClass('fc-fri') || $box.closest('td').hasClass('fc-sat')){
													 $box.qtip( $.extend({}, shared, {
															 content : {
																	 text : tempContent1
																},
																position : {
																	my : 'top right',
																	at : 'bottom center',
																	adjust : {
																		screen : true
																	}
															}
															 }));
												 }
												 else{
													$box.qtip( $.extend({}, shared, {
														 content : {
																 text : tempContent1
															}
														 }));
												 }
											 }
											 else{
												if(tempContent1){
													
													tempContent1 = tempContent1 +'<a href="'+event.url+'">'+event.title+'</a>';
													
													if($box.closest('td').hasClass('fc-thu') || $box.closest('td').hasClass('fc-fri') || $box.closest('td').hasClass('fc-sat')){
														 $box.qtip( $.extend({}, shared, {
																 content : {
																		 text : tempContent1
																	},
																	position : {
																		my : 'top right',
																		at : 'bottom center',
																		adjust : {
																			screen : true
																		}
																}
																 }));
													 }
													 else{
														$box.qtip( $.extend({}, shared, {
															 content : {
																	 text : tempContent1
																}
															 }));
													 }
													
												}
												else{
													if($box.closest('td').hasClass('fc-thu') || $box.closest('td').hasClass('fc-fri') || $box.closest('td').hasClass('fc-sat')){
														 $box.qtip( $.extend({}, shared, {
																 content : {
																		 text : '<a href="'+event.url+'">'+event.title+'</a>'
																	},
																	position : {
																		my : 'top right',
																		at : 'bottom center',
																		adjust : {
																			screen : true
																		}
																}
																 }));
													 }
													 else{
														$box.qtip( $.extend({}, shared, {
															 content : {
																	 text : '<a href="'+event.url+'">'+event.title+'</a>'
																}
															 }));
													 }
												 }
											 }
										
									
									}
									else{
										
										if($box.closest('td').hasClass('fc-thu') || $box.closest('td').hasClass('fc-fri') || $box.closest('td').hasClass('fc-sat')){
											$box.qtip( $.extend({}, shared, {
											 content : {
													text : '<a href="'+event.url+'">'+event.title+'</a>'
												},
											 position : {
												my : 'top right',
												at : 'bottom center',
												adjust : {
													screen : true
												}
											}
											 }));
										}
										else{
											$box.qtip( $.extend({}, shared, {
												content : {
												text : '<a href="'+event.url+'">'+event.title+'</a>'
											}
											}));
										}
									
									}
								
							}
						
						}
					}
					
				}
				else{//one day event
					
					
					var $box = $('td:not(.fc-other-month) .fc-day-number').filter(function() {
						return $(this).text() == startDay;
					});
					$box.parent().find('.fc-day-number').addClass('month-'+month);
					if(month == startMonth){
						$box.parent().find('.fc-day-number').addClass('event-day');
					}
					
					if( $box.data('qtip') ) {
					
						
						if(month == startMonth){
							
							 tempContent1 = $box.data('qtip').options.content.text;
							 
							 if(tempContent1.indexOf(event.title) >= 0){
								 
								 if($box.closest('td').hasClass('fc-thu') || $box.closest('td').hasClass('fc-fri') || $box.closest('td').hasClass('fc-sat')){
									 $box.qtip( $.extend({}, shared, {
											 content : {
													 text : tempContent1
												},
												position : {
													my : 'top right',
													at : 'bottom center',
													adjust : {
														screen : true
													}
											}
											 }));
								 }
								 else{
									$box.qtip( $.extend({}, shared, {
										 content : {
												 text : tempContent1
											}
										 }));
								 }
							 }
							 else{
								if(tempContent1){
									
									tempContent1 = tempContent1 +'<a href="'+event.url+'">'+event.title+'</a>';
									
									if($box.closest('td').hasClass('fc-thu') || $box.closest('td').hasClass('fc-fri') || $box.closest('td').hasClass('fc-sat')){
										 $box.qtip( $.extend({}, shared, {
												 content : {
														 text : tempContent1
													},
													position : {
														my : 'top right',
														at : 'bottom center',
														adjust : {
															screen : true
														}
												}
												 }));
									 }
									 else{
										$box.qtip( $.extend({}, shared, {
											 content : {
													 text : tempContent1
												}
											 }));
									 }
									
								}
								else{
									if($box.closest('td').hasClass('fc-thu') || $box.closest('td').hasClass('fc-fri') || $box.closest('td').hasClass('fc-sat')){
										 $box.qtip( $.extend({}, shared, {
												 content : {
														 text : '<a href="'+event.url+'">'+event.title+'</a>'
													},
													position : {
														my : 'top right',
														at : 'bottom center',
														adjust : {
															screen : true
														}
												}
												 }));
									 }
									 else{
										$box.qtip( $.extend({}, shared, {
											 content : {
													 text : '<a href="'+event.url+'">'+event.title+'</a>'
												}
											 }));
									 }
								 }
							 }
							
							
						}
						
						
					}
					else{
						//if not qtip
						if(month == startMonth){
								 
								 if($box.closest('td').hasClass('fc-thu') || $box.closest('td').hasClass('fc-fri') || $box.closest('td').hasClass('fc-sat')){
									 $box.qtip( $.extend({}, shared, {
											 content : {
													 text : '<a href="'+event.url+'">'+event.title+'</a>'
												},
												position : {
													my : 'top right',
													at : 'bottom center',
													adjust : {
														screen : true
													}
											}
											 }));
								 }
								 else{
									$box.qtip( $.extend({}, shared, {
										 content : {
												 text :'<a href="'+event.url+'">'+event.title+'</a>'
											}
										 }));
								 }
							 
							
							
						}
						else{
							
							
							
						}
						
					}
					
					
				}
				
            	
               	return false;
        	}
    	});
	 
   	 
	}); // end plugin constructor

};
})(jQuery);   

// Initialize all calendars
jQuery(function() {
    jQuery('.calendar_wrap').springCalendar({lang:'el'});
    
    

    jQuery("ul.tabs").tabs("div.panes > div");
    
    jQuery('.seminarPanes').accordion({
   		 active: false,
   		 autoHeight: false,
   		 alwaysOpen: false,
   		 header:'.accordion-header',
   		 collapsible:true
    });
});

