$(document).ready(function(){	
	$('.arrow_left img').live('click',function() {
		$('#calendar').css('height', $('#calendar').height() + 'px');
		$('#calendar').html('&nbsp;');
		month = $(this).attr('param_1');
		year = $(this).attr('param_2');
		
		$.ajax({
			async: false,
			url: "/get_calendar.php",
			data: "month=" + month + "&year=" + year,		
			cache: false,
			success: function(html){
				$('#calendar').html(html);
			}
		});			
	});
	$('.arrow_right img').live('click',function() {
		$('#calendar').css('height', $('#calendar').height() + 'px');
		$('#calendar').html('&nbsp;');
		month = $(this).attr('param_1');
		year = $(this).attr('param_2');
		
		$.ajax({
			async: false,
			url: "/get_calendar.php",
			data: "month=" + month + "&year=" + year,		
			cache: false,
			success: function(html){
				$('#calendar').html(html);
			}
		});
	});
	
	$('td.science, td.art, td.both').live('click',function() {		
		date = $(this).attr('rel');		
		
		$.ajax({
			async: false,
			url: "/set_date_in_session.php",
			data: "date=" + date,		
			cache: false,
			success: function(html){
				document.location.href='/pl/kalendarium/41/1/stop/';							
			}
		});
	});
	
	$('td.science, td.art, td.both').live('mouseenter',function() {
		day = $(this).attr('param_1');
		obj = $(this);				
		start_drag(day, obj);
	});
	$('td.science, td.art, td.both').live('mouseleave',function() {					
		stop_drag();
	});
	
	$('#btn_show_event').click(function() {
		year = $('select#event_year').val();
		month = $('select#event_month').val();
		type = $('select#event_type').val();
		date = year + '-' + month + '-1';
		$.ajax({
			async: false,
			url: "/set_date_in_session.php",
			data: "date=" + date + '&type=' + type ,		
			cache: false,
			success: function(html){
				document.location.href='/pl/kalendarium/41/1/stop/';							
			}
		});
	});
	
	/* SEARCH */  
		$('#search_phrase').focus(function() {
			if ($(this).val() == '' || $(this).val() == 'Szukaj w serwisie') {
				$(this).val('');
			}
		});	
		$('#search_phrase').blur(function() {
			if ($(this).val() == '') {
				$(this).val('Szukaj w serwisie');
			}
		});		
		$('#btn_search_phrase').click(function() {
			if ($('#search_phrase').val() == '' || $('#search_phrase').val() == 'Szukaj w serwisie') {
				alert('Proszę wpisać szukaną frazę');				
			} else {
				phrase = $('#search_phrase').val();
				document.location.href="/szukaj/" + phrase + "/";
			}					
		});
	/* EOF: SEARCH */	
});


function stop_drag() {
	$("div.calendar_box").hide();
}
function start_drag(day, obj) {
	$("#calendar_box_" + day).show();
	$(obj).mousemove(function(e){		
		$("#calendar_box_" + day).show();
		$("#calendar_box_" + day).css({
			top: (e.pageY - 190) + "px",
			left: (e.pageX - 235) + "px"
		});				
	});
}

