

	/*
	 * 
	 * 
	 */
	 
	 (function(){
	 	
		if (typeof window.snd == 'undefined')window.snd = {};
		 
	 	
	 	snd.creator = (function(){
		 	
			//private variables here
		 	
		 	return {
		 		
		 		init:function(){
		 			var that = this;
		 			this.loading = false;
		 			this.container = $('#creatorContainer')[0];
		 			this.wrapper = $('.wrapper',this.container)[0];
		 			this.form = $('form',this.container)[0];
		 			this.betaKeyNode = $('input[type=text]',this.container)[0];
		 			this.cta = $('a',this.container)[0];
		 			$(this.cta).bind('click',function(){
		 				that.callHome();
		 			});
		 			$(this.form).bind('submit',function(){
		 				that.callHome();
		 			});
		 		},
		 		callHome:function(){
		 			var that = this;
		 			$.post('/collections/create',{betaKey:this.betaKeyNode.value},function(data){
		 				that.handleResponse(data);
		 			},'json');
		 		},
		 		handleResponse:function(data){
					if(data.outcome == 'error'){
		 				alert(data.error);
		 				return;
		 			}else if(data.outcome == 'success'){
						this.showSuccess(data);
		 			}else{
		 				alert('An unknown error has occurred, please try again.');
		 			};
		 		},
		 		showSuccess:function(data){
		 			var that = this;
		 			$(this.wrapper).fadeOut(200,function(){
			 			that.wrapper.innerHTML = '<a class="ctaResponse" href="/'+data.content.collectionName+'">http://s-n-d.me/<span style="color:#ea311f;">'+data.content.collectionName+'<span></a>';
		 				$(that.wrapper).fadeIn(200);
		 			});
		 		},
		 		showError:function(){
		 			
		 		},
		 		showLoading:function(){
		 			
		 		},
		 		hideLoading:function(){
		 			
		 		}
		 		
		 	}
		 	
		//..creator
	 	})();
	 	
	 	
	 	snd.betaKeyForm = (function(){
		 	
			//private variables here
		 	
		 	return {
		 		
		 		init:function(){
		 			var that = this;
		 			this.loading = false;
		 			this.container = $('#betaRequest')[0];
		 			this.wrapper = $('.wrapper',this.container)[0];
		 			this.emailAddressNode = $('input[type=text]',this.container)[0];
		 			this.form = $('form',this.container)[0];
		 			this.cta = $('input[type=submit]',this.container)[0];
		 			$(this.form).bind('submit',function(){
		 				that.callHome();
		 			});
		 		},
		 		callHome:function(){
		 			var that = this;
		 			$.get('/betaKeys/add',{email:this.emailAddressNode.value},function(data){
		 				that.handleResponse(data);
		 			},'json');
		 		},
		 		handleResponse:function(data){
		 			if(data.outcome == 'error'){
		 				alert(data.error);
		 				return;
		 			}else if(data.outcome == 'success'){
						this.showSuccess(data);
		 			}else{
		 				alert('An unknown error has occurred, please try again.');
		 			};
		 		},
		 		showSuccess:function(data){
		 			var that = this;
		 			$(this.wrapper).fadeOut(200,function(){
			 			that.wrapper.innerHTML = '<div style="font-size:18px; background:white;">Thank you.</div>'+data.content.message;
		 				$(that.wrapper).fadeIn(200);
		 			});
		 		},
		 		showError:function(){
		 			
		 		},
		 		showLoading:function(){
		 			
		 		},
		 		hideLoading:function(){
		 			
		 		}
		 		
		 	}
		 	
		//..betaKeyForm
		
	 	})();
	 
	 //..anon
	 })();
	 
	 $(document).ready(function(){
	 	snd.creator.init();
	 	snd.betaKeyForm.init();
	 });
	 
	 showBetaKeyRequestForm = function(){
	 	$('#noKey').fadeOut(200,function(){
		 	$('#betaRequest').fadeIn(200,null);
	 	});
	 }