<!-- Class Execution -->
gbl.classes.subscribe = {
	init : function(){
		
				
		gbl.page_vars = commentData($('global_vars')); // <= { someData: 123, other: 'foo' }		
			
		if ($$('a[name=subscribe]')[0]) { new Subscribe({ 'button' : $$('a[name=subscribe]')[0]}) };
	}
};


<!-- Classes -->
var Subscribe = new Class({
	
	Implements: Options,

	options: {	

		button: false
		//subscription_list : false
	
	},
	
	initialize : function(options){
		
		this.setOptions(options);
			
			
		if (!this.options.button) return;
		//if (!this.options.subscription_list) return;
		
		this.private = {
			ical_url : 'http://yousayyeah.com/calendar/ical',
			subscription_list : []
		}
		
		
		/*if (subscription_categories.length > 0)*/ this.private.subscription_list.push( { 'id' : '1', 'name' : 'All Events (with your selected filters)', 'url' : this.private.ical_url+''+this.read_category_cookie() } );
		if (gbl.page_vars.user_id.length > 0) this.private.subscription_list.push( { 'id' : '2', 'name' : 'My Events', 'url' : this.private.ical_url+'?calendar='+gbl.page_vars.user_id } );
		
		this.els = {};
		
		this.add_events();		
		this.create_view();
	},
	
	add_events : function(){
		
		var t = this;
		
		
		this.options.button.addEvent('click',function(){
			
			t.toggle_view();
			
		});
		
	},
	
	read_category_cookie : function(){
		
		var cookie = Cookie.read("subscribe_to");
		
		if (cookie == null) return ''
		
		return cookie 
	},
	
	update_category_list : function(){
		
		$('input_1').set('value', this.private.ical_url+''+this.read_category_cookie())		
		
	},
	
	toggle_view : function(){
		
		active = 'white_button_pressed is_button';
		inactive = 'white_button is_button';
		
		if (this.options.button.get('class') == active) this.options.button.set('class',inactive);
		else this.options.button.set('class',active);
							 
		if (this.els.container){
			
			if (this.els.container.hasClass('hide')) { this.els.container.removeClass('hide'); this.update_category_list(); }
			else this.els.container.addClass('hide');
				
		}
	},
	
	create_view : function(){
				
		var button_coords = this.options.button.getCoordinates(this.options.button.getParent())
				
		this.els.container = new Element('ul', {
			'id' : 'subscribe',
			'class' : 'flyout',
			styles : {
				
				'position' : 'absolute',
				'top' : button_coords.top+button_coords.height+2,
				'left' : button_coords.left,
				'z-index' : 2000
				
			}
		})	
		
		this.els.container.addClass('hide');
		
		//this.options.button.setStyle('z-index',3000);
		//this.options.button.getParent().setStyle('z-index',4000)
		
		// Fix IE7< Stacking Error
					this.els.container.inject(this.options.button.getParent());

		if (Browser.Engine.trident){
				this.els.container.getParents().each(function(el,i){
					
					el.setStyle('z-index',2000)
				
				});
		};

		
		new Element('li',{ 'class' : 'headline' }).set('text','Subscribe to a Calendar').inject(this.els.container)
		new Element('li',{ 'class' : 'description' }).set('text','Just copy and paste the url into iCal or Google Calendar.').inject(this.els.container)
		for (var i = 0; i < this.private.subscription_list.length; i++){
			
			var content = this.private.subscription_list[i];		
			var html = '<em>{name}</em><input type="text" class="text" value="{url}" id="input_{id}"/>'
			html = html.substitute(content)
		
			var el1 = new Element('li').set('html',html)
			
//			var el2 = new Element('a',{ 'name' : type.id }).set('text',type.name);
			
			
			//el2.inject(el1)
		
			el1.inject(this.els.container);
			
			el1.getElement('input').addEvent('focus',function(){
			
				this.select();
				
			});
			
		};
				
	}	
	
	
});