var daysOld = 120;  //determines which albums to exclude - the number of days back from today

$(document).ready(function(){
    //Full Caption Sliding (Hidden to Visible)
    $('.tile.captionfull').hover(function() {
        $(".cover", this).stop().animate({top:'50px'},{queue:false,duration:160});
    }, function() {
        $(".cover", this).stop().animate({top:'140px'},{queue:false,duration:160});
    });

    var albumURL = "http://graph.facebook.com/valleyviewseek/albums?callback=?";
    $.ajax({
        url: albumURL,
        dataType: 'json',
        success: function(json) {
            $.each(json.data, function(i,item){
                if ((item.name != 'Profile Pictures') && (item.name != 'Wall Photos')) {
                        //var d=new Date("October 12, 1987 10:23:00");
                        //var e=new Date(item.created_time * 1000);
                        var createdDateStr = item.created_time.substring(0,10);  //remove all the extra stuff on the FB date, keeping just the YYYY-MM-DD
                        var createdDate = new Date(createdDateStr);  //convert to a javascript date object
                        createdDate = createdDate.setDate(createdDate.getDate() - 0);  //a kluge to convert to seconds from 1970
                        var today = new Date();
                        var cutoffDate = today.setDate(today.getDate() - daysOld);  //setup the cut off date...any albums older that this date are excluded.  
                        if (createdDate > cutoffDate) {
                            $('#coda-slider-1').append("\
                                <div class='panel'>\n\
                                    <div class='panel-wrapper'>\n\
                                        <div class='thumb-wrapper' style='background-image: url(\"http://graph.facebook.com/" + item.id + "/picture\"); background-color:#000;'>\n\
                                        </div>\n\
                                        <h2 class='title'><a href='" + item.link + "'>" + item.name + "</a></h2>\n\
                                    </div>\n\
                                </div>"
                            );
                        }
                }
            });
            //Initiate the Media slider
            $('#coda-slider-1').codaSlider();
        }
    });

    $('#details-toggle').click(function() {
//        $(this).parent().removeClass("collapsed").addClass("expanded")
        $(this).parent().toggleClass("collapsed", 5000);
        //alert($(this).parent().hasClass("collapsed"));
        if ($(this).parent().hasClass("collapsed")  ) {
            $(this).html("show more &#9660;");
        } else {
            $(this).html("hide &#9650;");
        }
        //alert("Hello");
    })
    //id, name, description, count, dateCreated, picture

});

