var visitorsvoice = Class.create({
	
	initialize: function() {
		this.container = $("visitorsvoice");
		
		this.thx = this.container.getElementsBySelector(".thx")[0];
		this.form = this.container.getElementsBySelector(".form")[0];
		
		this.thx.setStyle({
			display: "none"
		});
		
		this.cookie = new CookieJar({
			expires: (86400*30),
			path: '/',
			domain: '.skiamade.com'
		});
		
		var data = this.cookie.get("visitorsvoice");
				
		//data = "show";
		
		if (data == "show") {
			this.show();
		}
		else if(data == "shown") {
			
		}
		else {
			this.setFirstvisit();
		}
	},
	
	setFirstvisit: function () {
		this.cookie.put("visitorsvoice","show");
	},
	
	show: function () {
		
		var selectBox = this.container.getElementsBySelector("select")[0];
		selectBox.observe("change", this.track.bind(this, selectBox));
		//selectBox.observe("click", this.track.bind(this, selectBox));
		
		this.container.setStyle({
			display: "block"
		});
		
		this.cookie.put("visitorsvoice","shown");
	},
	
	hide: function () {
		this.container.setStyle({
			display: "none"
		});
	},
	
	showThx: function () {
		this.form.setStyle({
			display: "none"
		});
		this.thx.setStyle({
			display: "block"
		});
		
		window.setTimeout(this.hide.bind(this),2000);
	},
	
	track: function (selectBox) {
		
		var selectedValue = selectBox.options[selectBox.selectedIndex].value;
		
		if(selectedValue != "") {
			// track event
			pageTracker._trackEvent('VisitorsVoice', 'Source', selectedValue);
			pageTracker._setVar(selectedValue);
			
			this.showThx();
		}
	}
	
});