$(function() {
    // select the thumbnails and make them trigger our overlay
    $("a[href$=.jpg]").overlay({
        onLoad: function() {
            // count image click
            //this.getTrigger().hide();
            var thisLink = this.getTrigger();
            var id = this.getTrigger().attr("rel");
            var dataString = 'action=count&photograph='+ id ;
            $.ajax({
                type: "POST",
                data: dataString,
                url: "count.php",
                success: function(msg){
                    var currentCount = parseInt($(thisLink).next("span").text());
                    if((parseFloat(currentCount) == parseInt(currentCount)) && !isNaN(parseInt(currentCount))){
                        // nothing it is an integer
                    } else {
                        currentCount = 0;
                    }
                    if (!$.cookie('afterDarkEdu')) {
                        $(thisLink).next("span").text(currentCount+1);
                        var date = new Date();
                        date.setTime(date.getTime() + (60*60*24*30*1000));
                        $.cookie('afterDarkEdu', 'gallery', {expires: date });
                    }
                }
            });
        },
        // each trigger uses the same overlay with the id "gallery"
        target: '#gallery',
        top:  	'5%',
        // optional exposing effect
        expose: '#f1f1f1'
    // let the gallery plugin do its magic!
    }).gallery({
        // template: 'Photographer: <strong>${title}</strong><span><a href="xxxxxx" title="Download Hires Version of this image.">Download Hires Image</a></span>',
        template: 'Photographer: <strong>${title}</strong>',
        // the plugin accepts its own set of configuration options
        speed: 800
    });
});