var resizeAddValue = 1;

function fnIsAppleMobile() {

    if (navigator && navigator.userAgent && navigator.userAgent != null)
    {
        var strUserAgent = navigator.userAgent.toLowerCase();
        var arrMatches = strUserAgent.match(/(iphone|ipod|ipad)/);
        if (arrMatches)
            return true;
    } // End if (navigator && navigator.userAgent) 

    return false;
}

function fnIsMobile() {

    if (navigator && navigator.userAgent && navigator.userAgent != null)
    {
        var strUserAgent = navigator.userAgent.toLowerCase();
        var arrMatches = strUserAgent.match(/(iphone|ipod|ipad|android)/);
        if (arrMatches)
            return true;
    } // End if (navigator && navigator.userAgent) 

    return false;
}

function resizerPerform() {

    var zoom_res = 1;

    var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
    svg.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
    svg.setAttribute('version', '1.1');
    document.body.appendChild(svg);
    var z = svg.currentScale;
    document.body.removeChild(svg);

    function dppxfunc(precision) {

        var searchDPPX = function(level, min, divisor) {
            var wmq = window.matchMedia;
            while (level >= min && !wmq("(min-resolution: " + (level / divisor) + "dppx)").matches) {
                level--;
            }
            return level;
        };

        var maxDPPX = 5.0; // Firefox 22 has 3.0 as maximum, but testing a bit greater values does not cost much
        var minDPPX = 0.1; // Firefox 22 has 0.3 as minimum, but testing a bit smaller values does not cost anything
        var divisor = 1;
        var result;
        for (var i = 0; i < precision; i++) {
            result = 10 * searchDPPX(maxDPPX, minDPPX, divisor);
            maxDPPX = result + 9;
            minDPPX = result;
            divisor *= 10;
        }

        return result / divisor;
    }

    var dppx = dppxfunc(10);
    var zpr = z * 100;

    if (fnIsMobile()) {
        z = screen.availWidth / window.innerWidth;
        if ((z < 1) && (!(fnIsAppleMobile()))) {
            z = currMoZoom;
        }
        currMoZoom = z;
        dppx = z;
    }


    var bodyWidth = window.innerWidth;

    if (bodyWidth < 1356) {
        currFFZoom = bodyWidth / 1356;
        currIEZoom = currFFZoom * 100;

        var ZoomD = Math.round(currIEZoom * z);

        if ($.browser.mozilla) {
            $('body').css('MozTransform', 'scale(' + currFFZoom * dppx + ')');
            var zoom_res = currFFZoom * dppx;
        } else {
            $('body').css('zoom', ' ' + currIEZoom * z + '%');
            if (navigator.appName == "Microsoft Internet Explorer") {
                // Ur piece of validation
            } else {
                $('html').css('min-width', window.innerWidth + 'px');
            }
            $("iframe").contents().find("body").css('zoom', ' ' + ZoomD + '%');
            var zoom_res = currFFZoom * z;

        }
    } else {
        if ($.browser.mozilla) {
            $('body').css('MozTransform', 'scale(' + dppx + ')');
            var zoom_res = dppx;
        } else {
            $('body').css('zoom', zpr + '%');
            if (navigator.appName == "Microsoft Internet Explorer") {
                // Ur piece of validation 
            } else {
                $('html').css('min-width', '1356px');
            }
            $("iframe").contents().find("body").css('zoom', zpr + '%');
            var zoom_res = z;
        }
    }

    ZoomData = zoom_res;
    resizeAddValue = zoom_res;
    return zoom_res;
}

function fs() {
    if ($(document).fullScreen() == null) {
        //animateControlDisableOff('#fullscreen');
    }

    $("#fullscreen").bind("click", function() {
        if ($(document).fullScreen() == null) {
            try {
                var wscript = new ActiveXObject("Wscript.shell");
                wscript.SendKeys("{F11}");
            } catch (err) {
                alert('Jūsų saugumo nustatymai nepalaiko viso ekrano rėžimo, prašome paspausti F11 savo klaviatūroje.');
                animateControlDisableOff('#fullscreen');
            }
            setTimeout(function() {
                if (Math.abs($(window).height() - screen.height) < 5 && Math.abs($(window).width() - screen.width) < 5) {
                    animateControlActiveOn('#fullscreen');
                    var src = $('#fullscreen img.over').attr("src").replace("fullscreen_over.png", "fullscreen_over_active.png");
                    $('#fullscreen img.over').attr("src", src);
                } else {
                    animateControlActiveOff('#fullscreen');
                    var src = $('#fullscreen img.over').attr("src").replace("fullscreen_over_active.png", "fullscreen_over.png");
                    $('#fullscreen img.over').attr("src", src);
                }
            }, 500);
        }
        else {
            $(document).toggleFullScreen();
        }

    });
    $(document).bind("fullscreenchange", function() {
        if ($(document).fullScreen()) {
            animateControlActiveOn('#fullscreen');
            var src = $('#fullscreen img.over').attr("src").replace("fullscreen_over.png", "fullscreen_over_active.png");
            $('#fullscreen img.over').attr("src", src);
        }
        else {
            animateControlActiveOff('#fullscreen');
            var src = $('#fullscreen img.over').attr("src").replace("fullscreen_over_active.png", "fullscreen_over.png");
            $('#fullscreen img.over').attr("src", src);
        }
        ;
    });
}