var Toolbar=Class.create();
Object.extend(Toolbar,{
	initialize: function() {
    	this.originalFontSize = this.getOriginalSize();
		this.currentFontSize = "";
		
		if(! jQuery.cookie) { 
			var script = document.createElement('script'); 
				script.type = 'text/javascript'; 
				script.src = '/common_scripts/js/jquery/plugins/cookie/jquery.cookie.pack.js'; 
				$j("head:first").append(script);
		}
		

		if($j.cookie("textSize") && !isNaN($j.cookie("textSize"))) {
			this.setSize($j.cookie("textSize"));
		} else {
			$j.cookie("textSize", this.originalFontSize);
			this.currentFontSize = this.originalFontSize;
		}
	},
	getOriginalSize: function() {
		var value = $j('.reziseable:first').css('font-size');
		//alert(value);
		return value;
	},
	setSize: function(value) {
		value = parseFloat(value);
		value = Math.min(value, 22);
		value = Math.max(value, 10);
		//alert('set: ' + value+"px");
		$j('.reziseable').css({
			'font-size': value+"px",
			'line-height': '1.6em'
		});
		$j.cookie('textSize', value);
		this.currentFontSize = value;
	},
	getCurrentSize: function() {
		return this.currentFontSize;
	},
	popup:function(url) {
		popWindow=window.open(url,"_blank","toolbar=0,status=0,resizable=1,scrollbars=1,width=900,height=600"); 
		if(popWindow){ popWindow.focus(); }
	}, 
	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);
			//$j.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;
		}
	},
	print:function() {
		window.print();
	}
});

$j(document).ready(function() { Toolbar.initialize(); });
