// JavaScript Document
function getIcon() {
	$.ajax({
		   type : "GET",
		   url : 'geticon.php',
		   data : 'c='+$('#cat_id').val(),
		   success : function(html) {
			   	$('#icon').html(html);
		   }
   });
}

function getPage(page,data) {
	$.ajax({
		   type : "GET",
		   url : page,
		   data : data,
		   success : function(html) {
			   	$('#calendar').html(html);
				qtipevents();
		   }
   });
}

function miniCal(p,m,y,b) {
	$.ajax({
		   type : "GET",
		   url : p,
		   data : "m="+m+"&y="+y+"&t=mini",
		   success : function(html) {
			   	$('#mini_calendar').html(html);
				qtipevents();
		   }
   });	
}

function fullCal(p,m,y,t,b) {
	getPage(p,"m="+m+"&y="+y+"&t="+t);
}

function dayCal(p,m,y,d,b) {	
	getPage(p,"m="+m+"&y="+y+"&d="+d+"&t=day");
}

function qtipevents() {
// Setup the tooltip with the content
	$('.event_link').each(function() {
		var position;
		var location;
		if($(this).attr('day')<2) {
			position = 'rightBottom';
			location = 'leftTop';
		} else if ($(this).attr('day')>1 && $(this).attr('day')<5) {
			position = 'bottomMiddle';
			location = 'topMiddle';
		} else {
			position = 'leftBottom';
			location = 'rightTop';
		}
		$(this).qtip({
			style: { 
				width: 300,
				padding: 5,
				//background: '#ffffff',
				color: '#444444',
				textAlign: 'left',
				border: {
					width: 3,
					radius: 3,
					color: '#a7aaac'
				},
				tip: location,
				title: {
					'background': '#ebebeb',
					'font-size': '1.2em',
					'line-height': '1.3em'
				}
			},
			name: 'light', // Inherit the rest of the attributes from the preset dark style
			show: {
				effect: {
					length: 500
				},
				when: $(this).attr('event')
			},
			hide: {
				when: 'mouseout',
				fixed: true,
				effect: {
					length: 500
				},
				delay: 500
			},
			content: {
			   text: $(this).attr('content'),
			   title: {
				  text: ($(this).attr('mini'))?$(this).attr('mini'):$(this).html(),
				  button: ($(this).attr('event_id'))?'<a href="event.php?eid='+$(this).attr('event_id')+'">View Event</a>':false
			   }
				/*url: 'showarticle.php',
				method: 'post',
				data: { 
					id: $(this).attr('event_id')
				}*/
			},
			position: {
				corner: {
					//target: 'rightMiddle'
					target: position,
					tooltip: location
				},
				adjust: {
					y: -4
				}
			}
		});
	});
}
