﻿//
//     JQuery Text resize + Cookie recall
//     by Jonny Kamaly
//     based on script written by Faisal &amp; Homar
//

var sitefunctions = {
    textresize: function() {
        // show text resizing links
        $(".skriftstorelse").show();

        // set cookie name
        var $cookie_name = "sitename-FontSize";

        var originalFontSize = $("html").css("font-size");
        // if exists load saved value, otherwise store it
        if ($.cookie($cookie_name)) {
            var $getSize = $.cookie($cookie_name);
            $("html").css({ fontSize: $getSize + ($getSize.indexOf("px") != -1 ? "" : "px") }); // IE fix for double "pxpx" error
        } else {
            $.cookie($cookie_name, originalFontSize);
        }

        // Reset
        $("#FontSizeReset").bind("click", function() {
            $("html").css("font-size", originalFontSize);
            $.cookie($cookie_name, originalFontSize);
        });

        // Increase
        $("#FontSizeInc").bind("click", function() {
            var currentFontSize = $("html").css("font-size");
            var currentFontSizeNum = parseFloat(currentFontSize, 10);
            var newFontSize = currentFontSizeNum * 1.2;
            if (newFontSize, 11) {
                $("html").css("font-size", newFontSize);
                $.cookie($cookie_name, newFontSize);
            }
            return false;
        });

        // Decrease
        $("#FontSizeDec").bind("click", function() {
            var currentFontSize = $("html").css("font-size");
            var currentFontSizeNum = parseFloat(currentFontSize, 10);
            var newFontSize = currentFontSizeNum * 0.8;
            if (newFontSize, 11) {
                $("html").css("font-size", newFontSize);
                $.cookie($cookie_name, newFontSize);
            }
            return false;
        });

        // Multiply original textsize by 1.2
        $("#FontSizeStep1").bind("click", function() {
            var currentFontSizeNum = parseFloat(originalFontSize, 10);
            var newFontSize = currentFontSizeNum * 1.2;
            if (newFontSize, 11) {
                $("html").css("font-size", newFontSize);
                $.cookie($cookie_name, newFontSize);
            }
            return false;
        });

        // Multiply original textsize by 1.2
        $("#FontSizeStep2").bind("click", function() {
            var currentFontSizeNum = parseFloat(originalFontSize, 10);
            var newFontSize = currentFontSizeNum * 1.8;
            if (newFontSize, 11) {
                $("html").css("font-size", newFontSize);
                $.cookie($cookie_name, newFontSize);
            }
            return false;
        });

        // Add 5 to original textsize 
        $("#FontSizeStep3").bind("click", function() {
            var currentFontSizeNum = parseFloat(originalFontSize, 10);
            var newFontSize = currentFontSizeNum + 5;
            if (newFontSize, 11) {
                $("html").css("font-size", newFontSize);
                $.cookie($cookie_name, newFontSize);
            }
            return false;
        });

        // Add 10 to original textsize 
        $("#FontSizeStep4").bind("click", function() {
            var currentFontSizeNum = parseFloat(originalFontSize, 10);
            var newFontSize = currentFontSizeNum + 10;
            if (newFontSize, 11) {
                $("html").css("font-size", newFontSize);
                $.cookie($cookie_name, newFontSize);
            }
            return false;
        });

    }
}

$(document).ready(function() {
    //NB! DO NOT change id's

    // Three controls, Decrease, Reset, Increase (unlimited inc/dec)
    //$(".skriftstorelse").prepend('<a href="#" id="FontSizeInc" class="skriftStrLink"><img alt="&Oslash;k skriftst&oslash;rrelse" src="/_layouts/IMAGES/HelseForAlle/StorA.png" class="link" /></a>');
    //$(".skriftstorelse").prepend('<a href="#" id="FontSizeReset" class="skriftStrLink"><img alt="Nullstill skriftst&oslash;rrelse" src="/_layouts/IMAGES/HelseForAlle/MiddelsA.png" class="link" /></a>');
    //$(".skriftstorelse").prepend('<a href="#" id="FontSizeDec" class="skriftStrLink"><img alt="Reduser skriftst&oslash;rrelse" src="/_layouts/IMAGES/HelseForAlle/LitenA.png" class="link" /></a>');

    // Three controls, Normal, 1.2 enlargement and 1.8 enlargement    
    //$(".skriftstorelse").prepend('<a href="#" id="FontSizeStep2" class="skriftStrLink"><img alt="&Oslash;k skriftst&oslash;rrelse" src="/_layouts/IMAGES/HelseForAlle/StorA.png" class="link" /></a>');
    //$(".skriftstorelse").prepend('<a href="#" id="FontSizeStep1" class="skriftStrLink"><img alt="Nullstill skriftst&oslash;rrelse" src="/_layouts/IMAGES/HelseForAlle/MiddelsA.png" class="link" /></a>');
    //$(".skriftstorelse").prepend('<a href="#" id="FontSizeReset" class="skriftStrLink"><img alt="Reduser skriftst&oslash;rrelse" src="/_layouts/IMAGES/HelseForAlle/LitenA.png" class="link" /></a>');

    // Three controls, Normal, +2 and +4    
    $(".skriftstorelse").prepend('<a href="#" id="FontSizeStep4" class="skriftStrLink"><img alt="&Oslash;k skriftst&oslash;rrelse" src="/_layouts/IMAGES/HelseForAlle/StorA.png" class="link" /></a>');
    $(".skriftstorelse").prepend('<a href="#" id="FontSizeStep3" class="skriftStrLink"><img alt="Nullstill skriftst&oslash;rrelse" src="/_layouts/IMAGES/HelseForAlle/MiddelsA.png" class="link" /></a>');
    $(".skriftstorelse").prepend('<a href="#" id="FontSizeReset" class="skriftStrLink"><img alt="Reduser skriftst&oslash;rrelse" src="/_layouts/IMAGES/HelseForAlle/LitenA.png" class="link" /></a>');


    sitefunctions.textresize();
})
