window.isHD = function (c){
    if (window.HD !== undefined) {
         if(typeof(c) == 'function') c();
         return window.HD;
    }

    var imageAddr = "http://speedtest.vodafone.es/speedtest/random350x350.jpg" + "?n=" + Math.random();
    var startTime, endTime;
    var downloadSize = 245388;
    var download = new Image();
    download.onload = function () {
        endTime = (new Date()).getTime();
        var duration = (endTime - startTime) / 1000;
        var bitsLoaded = downloadSize * 8;
        var speed = (((bitsLoaded / duration) / 1024) / 1024).toFixed(2);
        window.HD = speed > 2 ? true : false;
        if(typeof(c) == 'function') c();
    }
    startTime = (new Date()).getTime();
    download.src = imageAddr;  
};

isHD();

/**
 * MediaQuery Scripts
 * [version 1.0]
 */

(function () {
    var $element, lastValue, mediaQueryFunctions = {};

    addToMediaQuery = function (key, callback) {
        if (!$element) {
            $element = $('<div class="media-queries"></div>').hide().appendTo('body');

            $(window).resize(executeMediaQuery);

            $(document).ready(function () {
                executeMediaQuery();
            });
        }

        if (!mediaQueryFunctions[key]) {
            mediaQueryFunctions[key] = [];
        }

        mediaQueryFunctions[key].push(callback);
    }

    var executeMediaQuery = function () {
        var width = $element.width();

        if (width !== lastValue) {
            if (mediaQueryFunctions[width]) {
                $.each(mediaQueryFunctions[width], function (key, callback) {
                    callback(width);
                });
            }

            lastValue = width;
        }
    };
})();