// JavaScript Document

/*

KYWA Effects Handler

Requires: mooTools 1.1 or later.

*/
//var kywaFx;

window.addEvent('domready',initKYWA);

/* This is verboten, but I'm doing it for now anyway. */
var myFormHelper;
var baseUrl = "http://kentuckywireless.org/"
/* Create the class for KYWAFX Tag Handler. 

    KYWAFX Tag Handler, this class handles all tagging/untagging of articles
    via AJAX.
    
    variables: tagBoxList, a class wide variable that contains all the Element classes
    that are draggable (aka, the form containers).
    
    You have to initialize the tagHandler everytime you create it BEFORE you call initAjax
    or else it will break.
    
*/
/* Small class that makes certain fields visible/invisible based on select list items. */
var formHelper = new Class({
	initialize: function(){
	
		select_item = $('event_dropdown');
		
		/** select_item will not be present on a page that is the sponsor's own. In this case, just return. **/
		if(select_item == null){
			return;		
		}
		
		toggled_form = $$('div#event_name_title', 'div#event_name_input');
		
		/** Check to make sure the option isn't already selected. **/
		if(select_item.value == '3'){
			toggled_form.setStyles({
				'opacity':1,
				'height':'auto',
				'display':'block'
			});
		}
		
		/* Create the event listeners. */
		select_item.addEvent('change', function(e){
				e = new Event(e);
		
				if(e.target.value == '3'){
					toggled_form.setStyles({
						'opacity':1,
						'height':'auto',
						'display':'block'
					});
				
				}
				else{
					toggled_form.setStyles({
						'opacity':0,
						'height':'0px',
						'display':'none'
					});
				}
		});	
	}
});

function initKYWA(){
	
	url = location;
	firePreloader();
	
	/** Initialize needed form helpers **/
	if( $('event_explorer') || $('view_event') || $('manage_gallery')){
		var lightBox = new Lightbox();
	}
	
	if( $('welcome') || $('sign_up')){
	
		var shadowOptions = {
			type:				'html',
			keysClose:			['c',27]
		}
	
		Shadowbox.init(shadowOptions);
	}
	
	if( $('become_a_sponsor') || $('edit_sponsorship')){
		
		myFormHelper = new formHelper();
		myFormHelper.initialize();
	}
	
 	if($('event_description')){
		window.onload = function (){
		
			tinyMCE.init({
			  	mode : "none",
			  	theme : "advanced",
				theme_advanced_buttons1 : "bold,italic,underline,link,unlink,bullist,blockquote,undo,formatselect", 
				theme_advanced_buttons2 : "", 
				theme_advanced_buttons3 : "",
                //valid_elements :"h1,h2,h3,h4,h5,h6", 
				auto_reset_designmode : true,
			   	content_css: "/public/css/kywa_stripped.css"
			});
			
			tinyMCE.execCommand("mceAddControl", true, "event_description");
			tinyMCE.execCommand("mceAddControl", true, "event_errata");
		}
	}
	
	if($('edit_static_content')){
	
		window.onload = function (){
			
			$('loading_editor').remove();
			
			tinyMCE.init({
			  	mode : "none",
			  	theme : "advanced",
				theme_advanced_buttons1 : "bold,italic,underline,link,unlink,bullist,blockquote,undo,formatselect", 
				theme_advanced_buttons2 : "", 
				theme_advanced_buttons3 : "",
				width:900,
                //valid_elements :"h1,h2,h3,h4,h5,h6", 
				auto_reset_designmode : true,
			   	content_css: "/public/css/kywa_stripped.css"
			});
			
			tinyMCE.execCommand("mceAddControl", true, "edit_static_content");
			
			$('content_holder').setStyles({
				'visibility' : 'visible',
				'overflow' : 'auto'
			});
		}
	
	}
	
	if($('article_wysiwyg')){
	
		window.onload = function (){
			
			$('loading_editor').remove();
			
			tinyMCE.init({
			  	mode : "none",
			  	theme : "advanced",
				theme_advanced_buttons1 : "bold,italic,underline,link,unlink,bullist,blockquote,undo,formatselect", 
				theme_advanced_buttons2 : "", 
				theme_advanced_buttons3 : "",
				width:775,
                //valid_elements :"h1,h2,h3,h4,h5,h6", 
				auto_reset_designmode : true,
			   	content_css: "/public/css/kywa_stripped.css"
			});
			
			tinyMCE.execCommand("mceAddControl", true, "article_wysiwyg");
			
			$('content_holder').setStyles({
				'visibility' : 'visible',
				'overflow' : 'auto'
			});
		}
	
	}
	
	if($('edit_sponsorship')){
		
		window.onload = function (){
			
			$('loading_editor').remove();
			
			tinyMCE.init({
			  	mode : "none",
			  	theme : "advanced",
				theme_advanced_buttons1 : "bold,italic,underline,link,unlink,bullist,blockquote,undo,formatselect", 
				theme_advanced_buttons2 : "", 
				theme_advanced_buttons3 : "",
				width:900,
                //valid_elements :"h1,h2,h3,h4,h5,h6", 
				auto_reset_designmode : true,
			   	content_css: "/public/css/kywa_stripped.css"
			});
			
			tinyMCE.execCommand("mceAddControl", true, "edit_sponsor_page");
			
			
			$('content_holder').setStyles({
				'visibility' : 'visible',
				'overflow' : 'auto',
				'width':'900px'
			});
			
		}
	
	}
	
	if($('confirm_approve_sponsor')){
		
		var thisCalendar = new Calendar({
			sponsor_expiration_date:"Y-m-d",
			navigation:2
		});
		
	}
	
	if($('add_event') || $('edit_event')){
	
		var thisCalendar = new Calendar({
			event_date:"Y-m-d",
			navigation:2
		});
	}
	
	var ad = $('ad');
	if (ad){
		
		ad.setStyle('cursor','pointer');
		ad.addEvent('click', function() {
			window.open('http://thewirelessworkforce.com','wnd');
		});

	}
	
	return;
}

function confirmDeleteUser(){
	
	var proceed = confirm("Do you really want to remove this user from the database permanently?");
	if(!proceed){
		return;
	}
	else{
		
	}
}