// For discussion and comments, see: http://remysharp.com/2009/01/07/html5-enabling-script/
(function(){if(!/*@cc_on!@*/0)return;var e = "abbr,article,aside,audio,bb,canvas,datagrid,datalist,details,dialog,eventsource,figure,footer,header,mark,menu,meter,nav,output,progress,section,time,video".split(','),i=e.length;while (i--){document.createElement(e[i])}})()

var FNDEV = (function (jq) {
    var m = {};

    // The animation sequence code is licensed under the
    // Creative Commons Attribution-Share Alike 3.0 Germany License
    // http://creativecommons.org/licenses/by-sa/3.0/de/deed.en
    m.animate_elements = function (elements) {
        elements = jq.makeArray(elements);
        var
            animate_next,
            speed_up = 1,
            t_ani_min = 150,
            t_ani_maxadd = 350,
            t_final_fade = t_ani_maxadd;

        try {
            if (typeof window.sessionStorage === 'object') {
                try {
                    speed_up = sessionStorage.visits = parseInt(sessionStorage.visits || 0, 10) + 1;
                } catch (e) {
                    // No cookies allowed, okay.
                }
            }
        } catch (e2) {
            // sessionStorage unknown or other problems...
        }

        // randomize
        elements.sort(function () {
            return (0.5 - Math.random());
        });
        // sort by importance
        elements.sort(function (a, b) {
            return jq(a).height() - jq(b).height();
        });

        (function animate_next() {
            if (elements.length < 1) {
                return;
            }
            var
                element = jq(elements.pop()),
                // weight: larger items fade in slower
                weight = Math.pow(Number(element.css('font-size').slice(0, -2)) / 24, 1.9),
                t_ani = (t_ani_min * weight) / speed_up,
                t_pause = t_ani / (2 + Math.random() * 2);
            element.animate({ opacity: 1.0 }, {
                    duration: t_ani,
                    complete: function () {
                        jq(this).animate(
                            { opacity: jq.data(this, 'original_opacity') },
                            t_final_fade);
                    }
                });
            setTimeout(animate_next, t_pause);
        }()); // call function immediately
    };

    m.init_portfolio_tracker = function (clicky) {
        jq('#portfolio ul li').one('mouseenter', function (event) {
            var item_id = jq('img', event.currentTarget).attr('src').slice(13, -4);
            clicky.log(window.location.href + '#p-' + item_id, item_id, 'pageview');
        });
    };

    m.on_document_ready = function () {
        jq('#cloud span')
            .each(function () {
                jq.data(this, 'original_opacity', jq(this).css('opacity'));
            })
            .css({opacity: 0, visibility: 'visible'});

        // Fake inherited colors for A elements. Go f*** yourself, IE!
        /*@cc_on

        @if (@_jscript_version <= 5.7) // <IE8

            jq('a').each(function () {
                jq(this).css('color', jq(this).parent().css('color'));
            });

        @end

        @*/
    };

    m.on_window_load = function () {
        m.animate_elements(jq('#cloud span'));
    };

    return m;

}(jQuery));
