﻿var toolbar;

function Toolbar(){
    this.initialize = function() {
        this.originalFontSize = this.getOriginalSize();
        this.currentFontSize = "";

        if ($.cookie("textSize") && !isNaN($.cookie("textSize"))) {
            this.setSize($.cookie("textSize"));
        } else {
            $.cookie("textSize", this.originalFontSize);
            this.currentFontSize = this.originalFontSize;
        }
    };
    this.getOriginalSize = function() {
        var value = $('.reziseable:first').css('font-size');
        //alert(value);
        return value;
    };
    this.setSize = function(value) {
        value = parseFloat(value);
        value = Math.min(value, 22);
        value = Math.max(value, 10);
        //alert('set: ' + value+"px");
        $('.reziseable').css({
            'font-size': value + "px",
            'line-height': '1.6em'
        });
        $.cookie('textSize', value);
        this.currentFontSize = value;
    };
    this.getCurrentSize = function() {
        return this.currentFontSize;
    };
    this.popup = function(url) {
        popWindow = window.open(url, "_blank", "toolbar=0,status=0,resizable=1,scrollbars=1,width=900,height=600");
        if (popWindow) { popWindow.focus(); }
    };
    this.resize = function(action) {
        if (action == 'Enlarge') {
            var currentFontSize = this.getCurrentSize();
            var currentFontSizeNum = parseFloat(currentFontSize, 10);
            var newFontSize = currentFontSizeNum * 1.2;
            var newFontSizeRounded = Math.round(newFontSize);
            this.setSize(newFontSize);
            return false;
        } else if (action == 'Reset') {
            this.setSize(this.originalFontSize);
            //$.cookie('textSize', null);
            return false;
        } else if (action == 'Decrease') {
            var currentFontSize = this.getCurrentSize();
            var currentFontSizeNum = parseFloat(currentFontSize, 10);
            var newFontSize = currentFontSizeNum * 0.8;
            var newFontSizeRounded = Math.round(newFontSize);
            this.setSize(newFontSize);
            return false;
        }
    };
    this.print= function() {
        window.print();
    };
}

$(document).ready(function() {
    toolbar = new Toolbar();
    toolbar.initialize();
});
