var Site = {
	init: function() {
		Site.TextSize.init({ selector: '.textSize a', cookieName: 'azilecttextsize', targeted: $$('#secondaryNav', '#primaryContent', '#sidebar .callout') });
	},
	
    TextSize: {
        cName: null,
        opts: { duration: 60, path: "/"},
        scale: ['1.0em', '1.1em', '1.2em'],
        myScale: null,
        els: null,
        curr: 0,
        init: function(obj) {
            this.els = $$(obj.selector)
            
            if (this.els.length == 0) return;
			
            this.cName = obj.cookieName
			
			if (!$chk(Cookie.read(this.cName))) Cookie.write(this.cName, 0, this.opts) //if doesnt exist, set cookie to 0					
            
			this.myScale = parseInt(Cookie.read(this.cName)) || 0 //in case cookies are disabled use 0								
			
			//console.log(this.)
			
            this.els.each(function(el, i) {
                el.set('href', 'javascript:void(0);')
                el.addEvent('click', function() {
                    this.processScale(el, i)
                }.bind(this))
            }, this);
			
            this.targetEl = $$(obj.targeted);
			
			this.processScale(this.els[this.myScale], this.myScale.toInt());
        },
        setCookie: function() {
            Cookie.write(this.cName, this.myScale.toString(), this.opts);
        },
        processScale: function(el, index) {
            if (this.myScale != index) {
				this.els[this.myScale].removeClass("active");				
			}

			this.els[index].addClass("active");
			
			this.myScale = index;
            this.setCookie();
            this.targetEl.setStyle('font-size', this.scale[this.myScale]);
        }
    }	
};

window.addEvent("domready", function() {
	Site.init();
});
