'use strict';
var lastEmojiId = 0;

$(document).ready(function() {


    $("#datepicker").datepicker({
            changeMonth: true,
            changeYear: true,
            onSelect: function() { 
            var dateObject = $(this).datepicker('getDate'); 
            console.log('Month: '+ dateObject.getMonth()+ ', Date: '+ dateObject.getDate()+ ', Year: '+ dateObject.getFullYear());

            var dateText = weekday(dateObject.getDay()) + ' ' + monthToString(dateObject.getMonth()) + ' ' + 
                        dateObject.getDate() + ', ' + dateObject.getFullYear();
            console.log(dateText);
            var ele = $("p:contains("+ dateText +")");
            //console.log('divID found: ' + ele.offset().top);
            if (ele.length) {
                $('html, body').animate({
                    scrollTop: ele.offset().top - 282
                }, 500);
            }
        }
    })
    .hide();

    $("#calendar-button").click(function() {
       $("#datepicker").toggle(); 
       var calendarHeight = $('#datepicker').height();
       if ($('#datepicker').is(':visible')) {
            $('body').css('padding-top', calendarHeight+72+'px');
        }
        else {
            $('body').css('padding-top', 72+'px');
        }
    });

    $('.playButton').click(audioToggle);
    
});


function weekday(day) {
    //console.log(day.getDay());
    var d;
    switch(day) {
        case 1:
            d = "Mon.";
            break;
        case 2:
            d = "Tue.";
            break;
        case 3:
            d = "Wed.";
            break;
        case 4:
            d = "Thu.";
            break;
        case 5:
            d = "Fri.";
            break;
        case 6:
            d = "Sat.";
            break;
        case 0:
            d = "Sun.";
            break;
    }
    return d;
}


function monthToString(m) {
    var monthText;
    switch(m) {
        case 0:
            monthText = "Jan";
            break;
        case 1:
            monthText = "Feb";
            break;
        case 2:
            monthText = "Mar";
            break;
        case 3:
            monthText = "Apr";
            break;
        case 4:
            monthText = "May";
            break;
        case 5:
            monthText = "Jun";
            break;
        case 6:
            monthText = "Jul";
            break;
        case 7:
            monthText = "Aug";
            break;
        case 8:
            monthText = "Sep";
            break;
        case 9:
            monthText = "Oct";
            break;
        case 10:
            monthText = "Nov";
            break;
        case 11:
            monthText = "Dec";
            break;
    }
    return monthText;
}

function audioToggle(e){
    e.stopPropagation();
    if($(this).hasClass("on")){
        $(this).removeClass("on");
        var elements = document.getElementsByClassName($(this).attr('id'));
        elements[0].pause();
        // document.getElementById('player').pause()
        $(this).attr("src", "../images/play.png")        
    }else{
        $(this).addClass("on");
        var elements = document.getElementsByClassName($(this).attr('id'));
        elements[0].src = elements[0].src +"?"+ new Date().getTime();
        console.log(elements[0].src);
        elements[0].play();
        // document.getElementById('player').play()
        $(this).attr("src", "../images/pause.png")
    }
}
@@ -3173,32 +3173,171 @@
 is).attr('id'));
+%0A%0A        var idx = elements%5B0%5D.src.indexOf('?');%0A        if(idx!=-1)%0A            elements%5B0%5D.src = elements%5B0%5D.src.substr(0,idx);%0A        
 %0A        element
@@ -3395,45 +3395,8 @@
 ();%0A
-        console.log(elements%5B0%5D.src);
 %0A   

fix URL growing bug