﻿$(document).ready(function() {
    if (isMobileSafari()) {
        $("body").css("position", "absolute");
    }
});

function isMobileSafari() {
    return (navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod') != -1) || (navigator.userAgent.indexOf('iPad') != -1);
}

Global.load(function () {
    var ie = {
        IsBeingDifficult: function () {
            var answer = false;
            if (navigator.appVersion.indexOf("MSIE") != -1) {
                answer = (parseFloat(navigator.appVersion.split("MSIE")[1]) < 7) ? true : false;
            }
            return answer;
        }
    };

    if (ie.IsBeingDifficult()) {
        var siteCookie = 'visited' + $('.logo').text().toLowerCase();
        if (getCookie(siteCookie) != 'true') {
            setCookie(siteCookie, 'true', 1);

            var l = $(window).width() / 2 - 200,
                t = $(window).height() / 2 - 260;

            $('#fader').fadeIn();
            $('<div id="darknessification" />').appendTo('body');
            $('<div id="ieIsBrokenGraphic">' +
                '<ul>' +
                    '<li><a href="http://www.google.com/chrome" target="_blank">Chrome</a></li>' +
                    '<li class="firefox"><a href="http://www.mozilla.org/en-US/firefox/new/" target="_blank">Firefox</a></li>' +
                    '<li class="opera"><a href="http://www.opera.com/" target="_blank">Opera</a></li>' +
                    '<li class="safari"><a href="http://www.apple.com/safari/" target="_blank">Safari</a></li>' +
                    '<li class="ie"><a href="http://windows.microsoft.com/en-US/internet-explorer/products/ie/home" target="_blank">Internet Explorer</a></li>' +
                '</ul>' +
              '</div>'
            ).css({ top: t, left: l }).show().appendTo('body');
        }
    }

    $('#darknessification, #ieIsBrokenGraphic').live('click', function () {
        $('#darknessification, #ieIsBrokenGraphic').remove();
    });

    function setCookie(cookieName, value, days) {
        var expirationDate = new Date();
        expirationDate.setDate(expirationDate.getDate() + days);

        var cookieValue = escape(value) + ((days == null) ? "" : "; expires=" + expirationDate.toUTCString());
        document.cookie = cookieName + "=" + cookieValue;
    };

    function getCookie(cookieName) {
        var i, x, y, cookies = document.cookie.split(";");
        for (i = 0; i < cookies.length; i++) {
            x = cookies[i].substr(0, cookies[i].indexOf("="));
            y = cookies[i].substr(cookies[i].indexOf("=") + 1);
            x = x.replace(/^\s+|\s+$/g, "");
            if (x == cookieName) {
                return unescape(y);
            }
        }
    };
});
