var Site = {
    init: function() {
        Site.TextSize.init({ selector: '.textSize a', cookieName: 'textsize'});		
    },
    
    TextSize: {
            cName: null,
            opts: { duration: 60 },
            scale: ['0.75em', '0.85em', '0.95em', '1.05em'],
            myScale: null,
            els: null,
            curr: 0,
            init: function(obj) {

				if (thisPageName!="educational-videos.aspx" && thisPageName!="lgs-forum.aspx") {

                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								

                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) || $(document.body)
                this.targetEl.setStyles({ 'font-size': this.scale[this.myScale] })

                }
            },
            setCookie: function() {
 				if (thisPageName!="educational-videos.aspx" && thisPageName!="lgs-forum.aspx")
	               Cookie.write(this.cName, this.myScale, this.opts)
            },
            processScale: function(el, index) {    
 				if (thisPageName!="educational-videos.aspx" && thisPageName!="lgs-forum.aspx"){
					
                switch (index) {
                    case 0:
                        this.myScale = (this.myScale - 1 < 0) ? 0 : this.myScale - 1
                        break;
                    case 1:
                        this.myScale = (this.myScale + 1 > this.scale.length - 1) ? this.scale.length - 1 : this.myScale + 1
                        break;
                    case 2:
                        this.myScale = (this.myScale - 1 < 0) ? 0 : this.myScale - 1
                        break;
                    case 3:
                        this.myScale = (this.myScale + 1 > this.scale.length - 1) ? this.scale.length - 1 : this.myScale + 1
                        break;             
                }
                this.setCookie();
                this.targetEl.setStyle('font-size', this.scale[this.myScale]);
				}
            }
        }
    }

window.addEvent("domready", function() {
    Site.init();
});
