function setDate(date){
 var month = ['января', 'февраля', 'марта', 'апреля', 'мая', 'июня', 'июля', 'августа', 'сентября', 'октября', 'ноября', 'декабря'];
 var day = ['Воскресенье', 'Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота'];
 var sp = date.split('-');
 //var 
 d = new Date();
 d.setDate(parseInt(sp[0].replace(/^0+/, '')));
 d.setMonth(parseInt(sp[1].replace(/^0+/, ''))-1);
 d.setYear(parseInt(sp[2]));
 
 $('.curdate').html(day[d.getDay()]+ ', <u>' + d.getDate() + ' ' + month[d.getMonth()] + '</u>');
 $('#list').granatLoad({
 			url: $.getCurUrl()+date, 
 			focusurl: false,
 			success: function(){ 					
 					setTimeout(function(){	 							
	 					$('#list')
	 						.find('.overimg')
								.mouseover(ov)
								.mouseout(bl); 					
 					}, 1000); 						 					
 			} 
 });
}

function dosearch(input)
{
	$(input).val('');
}

function doblur(input)
{
	if ($(input).val() == '')
	{
		$(input).val('Найти события');
	}
}

function bl(){
		$('#cal_popup').hide();
	}
	
function ov(event){
 		var $this = $(this);
 		
		$('#overimg').attr('src', $this.attr('src')); 
		$('#overcap').html('<h3>'+$this.attr('title')+'</h3>');
		$('#overdesc').html($this.attr('desc'));
		$('#overdate').html($this.attr('date'));
		
		var top = 0;
		var left = event.pageX > $(document).width()/2
						? event.pageX-500
						: event.pageX+10;
						
		left = left > ($(document).width() - 50) 
							? $(document).width() - 600				
							: left;
		
		top = event.pageY > ($(document).height() - 150) 
							? event.pageY-160				
							: event.pageY+20;					
		//top = event.pageY+20;						
		$('#cal_popup')
			.css({left: left+'px', top: top+'px'})			
			.show();			
	}

$(function(){
		
	$('.overimg')
		.mouseover(ov)
		.mouseout(bl);		
		
	$('.curdate').click(function(){	
			$(this).datepicker('dialog', '', setDate, {
							yearRange: '2007:2030', 
							dateFormat: 'dd-mm-yy'
			});
		});	
		
	var scrolltimer = false;	
	
	function ScrollCal(dx, period)
	{
			if (period == undefined) period = 500;
			$('#callist').animate(
					{
							scrollLeft: $('#callist').scrollLeft()+dx
					},{
						complete: scrolltimer ? function(){	ScrollCal(dx, period); } : null,
						duration: period,
						easing: 'linear',
						queue: false	
				  });
	}	
		
	$('#arrow_left').mouseover(function(){			
			scrolltimer = true
			ScrollCal(-50, 100);			
	});	
	
	$('#arrow_right').mouseover(function(){			
			scrolltimer = true
			ScrollCal(50, 100);			
	});
	
	$('#arrow_right, #arrow_left').mouseout(function(){
			scrolltimer = false;
	});	
	
});

window.granatTitle = 'PartyPrevew.ru';