// JavaScript Document
<!--
/* ===-- FontSizer --=== */
function FontSize(idx, cssLinkId, controlImgSrc){
	this.idx = idx;
	this.cssLinkId = cssLinkId;
	this.controlImgSrc = controlImgSrc;
	this.cssLink = null;
	FontSize.prototype.initialize = function(){
		this.cssLink = document.getElementById(this.cssLinkId);
	}
	FontSize.prototype.enable = function(){
        //alert(getAllSheets());
		//alert("FontSize.enable:\nlink: " + this.cssLink);
        //alert(this.idx);
        
        // loop trough all available styleseets and simple disable - no switch of rel!!!
        for( var x = 0, ss = getAllSheets(); ss[x]; x++ ) {
             if( ss[x].title ) {
//                alert(ss[x].title);
                ss[x].disabled = true;
                ss[x].rel = "alternate stylesheet";
             }
        }
        
         // now active the correct one, only way it to make it run in safari too,
         // all other browsers work like they did before...
         for( var x = 0, ss = getAllSheets(); ss[x]; x++ ) {
             if( ss[x].title ) {
                if( ss[x].title == this.cssLinkId) {
                    //alert(ss[x].title);
                    ss[x].disabled = false;
                    ss[x].rel = "stylesheet";
                }
             }
        }
        
        return false;
        
		if(this.cssLink != null){
			this.cssLink.removeAttribute("disabled");
			this.cssLink.disabled = false;
			this.cssLink.rel = "stylesheet";
		}
		//this.debug();
	};
	FontSize.prototype.disable = function(){
        return;
		//alert("FontSize.disable:\nlink: " + this.cssLink);
		if(this.cssLink != null){
			this.cssLink.setAttribute("disabled", "disabled");
			this.cssLink.disabled = true;
			this.cssLink.rel = "alternate stylesheet";
		}
		//this.debug();
	};
	FontSize.prototype.debug = function(){
		alert(
				"FoneSize(" + this.idx + "):\n" +
				"disabled: " + this.cssLink.getAttribute("disabled") + "\n" +
				"disabled: " + this.cssLink.disabled + "\n" +
				"rel: " + this.cssLink.rel + "\n" +
				"\n" +
				"caller: " + FontSize.prototype.debug.caller
		);
	};
}

var FontSizer = {
	currentFontSizeIdx: 0,
	prevFontSizeIdx: 0,
	CurrentFontSize: null,
	controlId: "fontsizerControl",
	controlImg: null,
	add: function(dif){
		this.prevFontSizeIdx = this.currentFontSizeIdx;
		
		var newFontSizeIdx = this.currentFontSizeIdx + dif;
		
		var size = document.getElementById('copy').className;
		    size = Number(size.charAt(size.length-1));
		var newFontSizeValue = size + dif;
		if(newFontSizeValue <= FontSize.length-1) {
			//this.CurrentFontSize = FontSize[newFontSizeValue][1];
			this.controlImg = FontSize[newFontSizeValue][2];
			this.currentFontSizeIdx = newFontSizeValue;
			this.set(newFontSizeValue);
		}
	},
	dec: function(dif){
		this.prevFontSizeIdx = this.currentFontSizeIdx;
		
		var newFontSizeIdx = this.currentFontSizeIdx + dif;
		
		var size = document.getElementById('copy').className;
		    size = Number(size.charAt(size.length-1));
		var newFontSizeValue = size - dif;
		if(newFontSizeValue <= FontSize.length-1) {
			//this.CurrentFontSize = FontSize[newFontSizeValue][1];
			this.controlImg = FontSize[newFontSizeValue][2];
			this.currentFontSizeIdx = newFontSizeValue;
			this.set(newFontSizeValue);
		}
	},
	set: function(fontSizeIdx){
		this.CurrentFontSize = FontSize[fontSizeIdx][1];
		this.controlImg = FontSize[fontSizeIdx][2];
		this.currentFontSizeIdx = fontSizeIdx;
		
		document.getElementById('copy').className = this.CurrentFontSize;
		try{
		var preElem = document.getElementById(FontSize[this.prevFontSizeIdx][1]);
		preElem.disabled = true;
		elem.rel = "alternate stylesheet";
		} catch(e){
			//do nothing
		}
		
		var elem = document.getElementById(this.CurrentFontSize);
		elem.disabled = false;
                elem.rel = "stylesheet";
		
		//alert("FontSizeId: "+fontSizeIdx+"\nEnabling CSS: "+this.CurrentFontSize);
		
		this._adjustControl(); //swap image

			/*
			if(this.CurrentFontSize != null){
				
				if(this.CurrentFontSizeIdx < FontSize.length){
					NewFontSize.enable();
					this.CurrentFontSize.disable();
				} else{
					this.CurrentFontSize.disable();
					NewFontSize.enable();
				}
			} else{
				NewFontSize.enable();
			}
			*/

	},
	_initilizeFontSizes: function(){
		for(var i = 0; i < this.FontSizes.length; i++){
			this.FontSizes[i].initialize();
		}
	},
	_getFontSizeByIdx: function(idx){
		var _FontSize = null;
		for(var i = 0; i < this.FontSizes.length; i++){
			if(this.FontSizes[i].idx == idx){
				_FontSize = this.FontSizes[i];
				break;
			}
		}
		return _FontSize;
	},
	_adjustControl: function(){
		var Control = document.getElementById(this.controlId);
		if(Control) {		
			Control.src = this.controlImg;
		}
	}
	
	
	}

var FontSize = new Array();
    FontSize[0] = new Array(1, "size1", "../images/fontsize_module_control_size1.gif");
    FontSize[1] = new Array(1, "size1", "../images/fontsize_module_control_size1.gif");
    FontSize[2] = new Array(2, "size2", "../images/fontsize_module_control_size2.gif");
    FontSize[3] = new Array(3, "size3", "../images/fontsize_module_control_size3.gif");
/*
function initFontSizer(){
	FontSizer.init(new Array(fontSize1,fontSize2,fontSize3), 1, "fontsizerControl");
}
*/
//registerOnload(initFontSizer);
//-->

function printerFriendly() {
	window.print();
}
