var resizeAddValue = 1;
var inFullScreenMode = false;

//alert(parent.ZoomData);

//resizeAddValue = setGlobalScale(resizeAddValue);




function fs() {
    var maxWidth = 1278;
    var maxHeight = 718;
    var $window = $(window);

    var height = $window.height();
    //var ldiff = (width - maxWidth) / 2;


    //$(window).bind("resize")
    //var ratioWidth = $(window).width() / maxWidth;
    //var ratioHeight = $(window).height() / maxHeight;
    //var ratio = Math.min(ratioWidth, ratioHeight);
    //
    //

//scale = Math.min(width / maxWidth, height / maxHeight);
    //console.log("screenScale: " + scale);
    //setWidth=maxSetWidth*scale;
    //alert(ratio);
    //setHeight=maxSetHeight*scale;
    //var lMargin = ratioWidth * 100 / 2;
    //alert(lMargin);
    //alert(ratioWidth * 100 / 2);

    var fullScreenWidth = screen.availWidth;
    var ratio = fullScreenWidth / maxWidth;


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

    $("#fullscreen").bind("click", function(e) {
        if ($(document).fullScreen() == null) {

            //alert("ie");

            try {
                // var divObj = e.target;
                //$(document).fullScreen(true);
                // document.getElementsByTagName("body")[0].msRequestFullscreen();

                var wscript = new ActiveXObject("Wscript.shell");
                wscript.SendKeys("{F11}");


                if (inFullScreenMode == false) {
                    resizeAddValue = setFullScreenMode(resizeAddValue, ratio);
                    inFullScreenMode = true;
                } else {
                    inFullScreenMode = false;
                    resizeAddValue = exitFullScreenMode(resizeAddValue);
                    //resizeAddValue = 1;
                }


            } catch (err) {
                //window.parent.moveTo(0, 0);
                //window.parent.resizeTo(screen.availWidth, screen.availHeight);
                if (inFullScreenMode == false) {
                    animIcon("on");
                    window.parent.$("iframe").addClass("iFrameFullScreenMode");
                    window.parent.$("#footer").addClass("hideWebBlocks");
                    window.parent.$(".page_wrap").addClass("page_wrap_full");
                    window.parent.$("html").addClass("rightSpaceFix");
                    $("body").addClass("bodMarg");
                    $("html").addClass("htmOver");
                    $("#slideshow").addClass("slCenter");

                    setFullScreenScale(ratio);
                    resizeAddValue = ratio;
                    inFullScreenMode = true;
                } else {
                    animIcon("off");
                    window.parent.$("iframe").removeClass("iFrameFullScreenMode");
                    window.parent.$("#footer").removeClass("hideWebBlocks");
                    window.parent.$(".page_wrap").removeClass("page_wrap_full");
                    window.parent.$("html").removeClass("rightSpaceFix");
                    $("body").removeClass("bodMarg");
                    $("html").removeClass("htmOver");
                    $("#slideshow").removeClass("slCenter");
                    $("#slideshow").css("transform", "none");
                    resizeAddValue = 1;

                    inFullScreenMode = false;
                }

                //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);
             
             //alert("s");
             } else {
             //alert("s2");
             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 {
            //console.log("full");
            $(document).toggleFullScreen();
        }

    });
    $(document).bind("fullscreenchange", function() {
        // console.log("html",);
        //var ratio = fullScreenWidth / maxWidth;


        if ($(document).fullScreen()) {
            window.parent.$("html").addClass("rightSpaceFix");
            //window.parent.$("body").addClass("rightSpaceFix");

            //setTimeout("makeFullScreen()", 0);
            resizeAddValue = setFullScreenMode(resizeAddValue, ratio);

            // if (ratioHeight < ratioWidth){
            //    $("#slideshow").css("margin-left", lMargin + "px");
            //}
            inFullScreenMode = true;

        } else {
            //animateControlActiveOff('#fullscreen');
            window.parent.$("html").removeClass("rightSpaceFix");
            /* $("html").removeClass("htmOver");
             var src = $('#fullscreen img.over').attr("src").replace("fullscreen_over_active.png", "fullscreen_over.png");
             $('#fullscreen img.over').attr("src", src);
             $('#fullscreen img.normal').css("opacity", 1);
             $('#fullscreen img.active').css("opacity", 0);
             
             $("#slideshow").removeClass("slCenter");
             $("body").removeClass("bodMarg");
             $("#slideshow").css("transform", "none");
             resizeAddValue = 1;*/
            resizeAddValue = exitFullScreenMode(resizeAddValue);
            inFullScreenMode = false;
        }

    });


}

function setFullScreenMode(resizeAddValue, ratio) {
    //var maxWidth = 1278;
    $("html").addClass("htmOver");
    $("#slideshow").addClass("slCenter");
    $("body").addClass("bodMarg");


    //$(parent.document.body).outerWidth(true);//$window.width();


    /*animateControlActiveOn('#fullscreen');
    var src = $('#fullscreen img.over').attr("src").replace("fullscreen_over.png", "fullscreen_over_active.png");
    $('#fullscreen img.over').attr("src", src);
    $('#fullscreen img.normal').css("opacity", 0);*/
    
    setFullScreenScale(ratio);
   

    //$("#slideshow").addClass("slCenter");
    //$("body").addClass("bodMarg");

    //var ratio = fullScreenWidth / maxWidth;
    resizeAddValue = ratio;
    animIcon("on");

    /*$("#slideshow").css('transform', 'scale(' + (ratio) + ')');
     $("#slideshow").css('-ms-transform', 'scale(' + (ratio) + ')');
     $("#slideshow").css('-moz-transform', 'scale(' + (ratio) + ')');
     $("#slideshow").css('-webkit-transform', 'scale(' + (ratio) + ')');*/
   

    return resizeAddValue;

}

function exitFullScreenMode(resizeAddValue) {
    $("html").removeClass("htmOver");
    /*var src = $('#fullscreen img.over').attr("src").replace("fullscreen_over_active.png", "fullscreen_over.png");
    $('#fullscreen img.over').attr("src", src);
    $('#fullscreen img.normal').css("opacity", 1);
    $('#fullscreen img.active').css("opacity", 0);*/
    

    $("#slideshow").removeClass("slCenter");
    $("body").removeClass("bodMarg");
    $("#slideshow").css("transform", "none");
    resizeAddValue = 1;
    animIcon("off");

    return resizeAddValue;

}

function setFullScreenScale(ratio) {
    $("#slideshow").css('transform', 'scale(' + (ratio) + ')');
    $("#slideshow").css('-ms-transform', 'scale(' + (ratio) + ')');
    $("#slideshow").css('-moz-transform', 'scale(' + (ratio) + ')');
    $("#slideshow").css('-webkit-transform', 'scale(' + (ratio) + ')');
}

function animIcon(status) {
    if (status == "on") {
        animateControlActiveOn('#fullscreen');
        var src = $('#fullscreen img.over').attr("src").replace("fullscreen_over.png", "fullscreen_over_active.png");
        $('#fullscreen img.over').attr("src", src);
        $('#fullscreen img.normal').css("opacity", 0);
    } else {
        var src = $('#fullscreen img.over').attr("src").replace("fullscreen_over_active.png", "fullscreen_over.png");
        $('#fullscreen img.over').attr("src", src);
        $('#fullscreen img.normal').css("opacity", 1);
        $('#fullscreen img.active').css("opacity", 0);
    }
}

/*function setGlobalScale(rate){
 if (parent.ZoomData != ""){
 
 if (inFullScreenMode == false){
 if(!$.browser.mozilla){
 resizeAddValue = parent.ZoomData;
 }else{
 resizeAddValue = 1;
 }
 
 }else{
 resizeAddValue = rate;
 }
 
 } else {
 if (inFullScreenMode) {
 resizeAddValue = rate;
 }
 else {
 resizeAddValue = 1;
 }
 }
 
 return resizeAddValue;
 }*/