;(function($){
    $.fn.viddy =    function(options){
        var config = {
            playerPath: '/_flash/jwplayer.swf',
            playIcon: '/_images/icon-play.png'
        };

        if(options) $.extend(config, options);

        // Browser ability detection. Returns boolean
        function canPlayMP4() {
            var vid = document.createElement("video");
            if ( typeof(vid.canPlayType) == 'undefined' || // detect browsers with no <video> support
            vid.canPlayType('video/mp4') == ''){
                return false;
            } else {
                return true;
            }
        }

        return this.each(function() {
            var video = $(this);
            var videoUrl = video.find('source').attr('src'),
                image = config.image || video.attr('poster'),
                height = config.height || video.height(),
                width = config.width || video.width();

            // Using feature detection
           // Fallback to JWPlayer

            // create flash container div
            var flashdiv = $('<div />');
            flashdiv.flash(
                {
                    src: config.playerPath,
                    width: width,
                    height: height,
                    flashvars: { file: videoUrl, image: image }
                },
                { version: 8 }
            );

            // insert flash and remove video
            video.before(flashdiv);
            video.css('display','none');
        });
    };
})(jQuery);

