


$(document).ready(function() {

    function marca_datas(array_datas, y, m, d, class_name){
        if(typeof(array_datas) != 'undefined')
        {
            for(i=0; i<array_datas.length; i++)
            {	
                data_split = array_datas[i].split(".");
    
                if (d == data_split[0] && m == (data_split[1]-1) &&  y == data_split[2])
                {
                    $td.addClass(class_name);
                }
            }
        }
    }
    
	$('.calendario_bottom').datePicker({
	    inline:true,
	    showYearNavigation:false,
	    startDate:'01/01/1996',
	    showHeader:$.dpConst.SHOW_HEADER_LONG,
	    renderCallback:function($td, thisDate, month, year){
	        marca_datas(acontecera, thisDate.getFullYear(), thisDate.getMonth(), thisDate.getDate(), 'acontecera');
	        marca_datas(aconteceu, thisDate.getFullYear(), thisDate.getMonth(), thisDate.getDate(), 'aconteceu');
            /*if (thisDate.getDay()==0 || thisDate.getDay()==6) {
                $td.addClass('weekend');
                $td.addClass('disabled');
            }*/
        }
	});
	
	//define a data selecionada pelo usuário na index
	set_date = (start_month+1)+'/'+(start_day)+'/'+start_year; 
	//$('.calendario_bottom').dpSetSelected(new Date(set_date).asString());
	
	$('.calendario_bottom').bind('dateSelected', function(e, selectedDate, $td) {
        var url = selectedDate.getFullYear() + '/' + parseInt(selectedDate.getMonth() + 1) + '/' + selectedDate.getDate() + '/';
        window.location.href = '/calendario/' + url;	    
	});
    
    
    $('.prev-month').bind('click', function(event) {
        $('.dp-nav-prev-month').trigger('click');
        return false;
    });
    
    $('.next-month').bind('click', function(event) {
        $('.dp-nav-next-month').trigger('click');
        return false;
    });
	
    // exibir texto
    
    $('#lista_calendario h4').toggle(function() {
        $(this).next().slideDown();
    }, function() {
        $(this).next().slideUp();
    });
    
    var hash = window.location.hash || false;
    
    if (hash) {
        $( hash ).find('.texto').slideDown();
    }

});

