AccessibilityToolWP = Class.create();
Object.extend(AccessibilityToolWP.prototype, 
{
	initialize: function(el) {
		this.container = $(el);
		if (this.container == undefined) return 0;
		
		this.btnA = this.container.down("div#tbA");
		this.btnPlus = this.container.down("div#tbAplus");
		this.btn2plus = this.container.down("div#tbA2plus");
		
		this.state = "small";
		
		this.textStyle = "text.css";		
		this.textStyleMed = "textMed.css";
		this.textStyleBig = "textBig.css";
		
		this.textStyleActive = "text.css";
		
		this.doBig = function() {
			if(this.state != "big"){
				var tmp = new Array();
				tmp.push({ "name":this.textStyleActive, "newname":this.textStyleBig});
				this.templateChange(tmp);
				this.state = "big";
				this.btn2plus.addClassName('underLined');
				this.btnA.removeClassName('underLined');
				this.btnPlus.removeClassName('underLined');
				this.textStyleActive = this.textStyleBig;
			}
		}
		
		this.doMedium = function() {
			if(this.state != "medium"){
				var tmp = new Array();
				tmp.push({ "name":this.textStyleActive, "newname":this.textStyleMed});
				this.templateChange(tmp);
				this.state = "medium";
				this.btnPlus.addClassName('underLined');
				this.btnA.removeClassName('underLined');
				this.btn2plus.removeClassName('underLined');
				this.textStyleActive = this.textStyleMed;
			}
		}
		
		this.doNormal = function() {
			if(this.state != "small"){
				var tmp = new Array();
				tmp.push({ "name":this.textStyleActive, "newname":this.textStyle});
				this.templateChange(tmp);
				this.state = "small";
				this.btnA.addClassName('underLined');
				this.btnPlus.removeClassName('underLined');
				this.btn2plus.removeClassName('underLined');
				this.textStyleActive = this.textStyle;
			}
		}
		
		this.doContrast = function() {
			alert("contrast");
		}
		
		this.templateChange = function(arguments) {

			var ss = this.takeSheet();

			for( var x = 0; x < ss.length; x++ ) {
				
				var tmp = this.takeCSSNameFromPath(ss[x].href)
				
				var name = tmp[0];
				var path = tmp[1];				
				
				for( var j = 0; j < arguments.length; j++ ) {
			
					if(name == arguments[j]["name"]){

						ss[x].disabled = true;
						
						ss[x].href = path+arguments[j]["newname"];

						ss[x].disabled = false;
					}
				}
			}
		}
		
		this.takeSheet = function() {			
				if( document.getElementsByTagName ) {
					var Lt = document.getElementsByTagName('LINK');
					var St = document.getElementsByTagName('STYLE');
				} else {
					// browser minori - restituisce array vuoto
					return []; 
				}
				//per tutti i tag link ...
				for( var x = 0, os = []; Lt[x]; x++ ) {
					//controlla l'attributo rel per vedere se contiene 'style'
					if( Lt[x].rel ) {
						var rel = Lt[x].rel;
					} else if( Lt[x].getAttribute ) {
						var rel = Lt[x].getAttribute('rel');
					} else {
						var rel = '';
					}
					if(typeof(rel)=='string'&&rel.toLowerCase().indexOf('style')+1){
						//riempe la variabile os con i stylesheets linkati
						os[os.length] = Lt[x];
					}
				}
				//include anche tutti i tags style e restituisce l'array
				for( var x = 0; St[x]; x++ ) {
					os[os.length] = St[x];
				}
				return os;			
		}
		
		this.takeCSSNameFromPath = function(_str) {
		    if (_str==undefined)
		    {
		            var tmp = new Array(-1, -1);
                    return tmp;

		    }
			var pp = _str.lastIndexOf("/");
			var name = _str.substr(pp+1);
			var path = _str.substring(0,pp+1)

			var tmp = new Array(name, path)
			return tmp
		}

		
		this.act1 = this.doBig.bind(this);
		this.act2 = this.doNormal.bind(this);
		this.act3 = this.doMedium.bind(this);
		
		this.btnA.observe("click", this.act2, false);
		this.btnPlus.observe("click", this.act3, false);
		this.btn2plus.observe("click", this.act1, false);
	}

});