/*global window, jQuery, swfobject*/
(function ($) {
    'use strict';
    var location = window.document.location,
        latest_flash_version = '11.1.102.62';

    $('#contact').one('click', function () {
        $('#contact-me').show();
    }).click(function () {
        return false;
    });

    if (location.protocol === 'http:' && false) {
        $('<div />', {
            id: 'enable-https'
        }).append(
            $('<a />', {
                href: 'https://hidekiy.com' + location.pathname,
                text: '[enable https]'
            })
        ).appendTo('body');
    }

    (function () {
        var ver;

        if (swfobject.hasFlashPlayerVersion('1')
                && !swfobject.hasFlashPlayerVersion(latest_flash_version)) {

            ver = swfobject.getFlashPlayerVersion();

            $('<p />', {
                text: [
                    'Your Flash Plugin (v',
                    [ver.major, ver.minor, ver.release].join('.'),
                    ') looks really out of date. Please update it.'
                ].join(''),
                css: {
                    background: 'pink',
                    position: 'absolute',
                    top: 0,
                    left: 0,
                    margin: 0
                }
            }).appendTo('body');
        }
    }());

    (function () {
        var $loading = $('<img />', {
            src: '/img/ajax-loader.gif',
            width: 32,
            height: 32,
            css: {
                opacity: 0.80,
                margin: '0 20px',
                borderRadius: '6px'
            }
        }).appendTo('#activity');

        $.getJSON('//friendfeed.com/api/v2/feed/hidekiy?num=10&callback=?', function (data) {
            var $ul = $('<ul />').appendTo('#activity');
            $loading.hide();

            $.each(data.entries, function () {
                var entry = this,
                    $li = $('<li />'),
                    $foot;

                $('<p />', {
                    html: entry.body,
                    css: {
                        margin: '0'
                    }
                }).appendTo($li);

                if (entry.thumbnails) {
                    $li.append('<br />');

                    $.each(entry.thumbnails, function (index) {
                        var img = this;

                        if (index > 3) { return false; }

                        $('<img />', {
                            width: img.width,
                            height: img.height,
                            src: img.url
                        }).appendTo($li);
                    });
                }

                $foot = $('<p />', {
                    css: {
                        fontSize: '10px',
                        textAlign: 'right',
                        margin: '5px 0 0 0'
                    }
                });

                $foot.append('via ');
                $('<a />', {href: entry.via.url, text: entry.via.name}).appendTo($foot);
                $foot.append(' at ' + entry.date);
                $foot.appendTo($li);

                $li.appendTo($ul);
            });
        });
    }());
}(jQuery));
