YAHOO.util.Event.onDOMReady(function(){

    var els = YAHOO.util.Selector.query('input[type=checkbox]');	
	for(var i = 0; i < els.length; i++){
		if (els[i].id=='quicklist_chk'||els[i].id=='add_box'){
			YAHOO.util.Event.addListener(els[i],'click',function(event){
				if (this.checked == true){
			       YAHOO.util.Dom.addClass(this.parentNode.parentNode,'grid_selected');
				}else{
					YAHOO.util.Dom.removeClass(this.parentNode.parentNode,'grid_selected');
				}
			});
		}
	}
	
	var els = YAHOO.util.Selector.query('td.grid_filter > input.input_p');
	for(var i = 0; i < els.length; i++){
		/*
		els[i].value = 'Search...';
		YAHOO.util.Event.addListener(els[i],'focus',function(event){
			YAHOO.util.Event.preventDefault(event);			
			this.value='';
		});
		YAHOO.util.Event.addListener(els[i],'blur',function(){
			if (this.value == ''){
			//	this.value='Search...';
			}
		});
		
		
		YAHOO.util.Event.addListener(els[i],'change',function(event){			
			YAHOO.util.Event.preventDefault(event);
			if (this.value!='Search...'&&this.value!=''){
				this.onchange();			
			}
		});
		*/
	}
	
	var lastRadio;
	
	YAHOO.util.Event.on("chooseFundType", "focusout", function(e) {
	
	});
	
	/* Listen for header rollovers
	 * Last Modified: Ross 4:38pm 8/9/10
	 */
	var allHeaderRollovers = $nav('.headerRollover');
	var newTooltip = new CreateTooltip();
	var eventId;
	YAHOO.util.Event.addListener(allHeaderRollovers,'mouseover',function(event){
		
		if (navigator.userAgent.indexOf('Firefox') !=-1){
			eventId = event.target.id;
		}
		else{
			eventId = event.srcElement.id;
		}
		if (eventId == 'manageHeader'){
			/* /charity/contacts header*/
			newTooltip.showHTML('manageHeader',0,0,"This is the place to manage your contacts. To view additional info about a specific contact, click on their email address.");
		}
		else if (eventId == 'contactHeader'){
			newTooltip.showHTML('contactHeader',0,0,"This is the place to manage your contact lists by creating, editing, or messaging specific lists.");
		}
	});
	
	YAHOO.util.Event.addListener(allHeaderRollovers,'mouseout',function(event){
		var tooltipClass = $nav('.questionTooltip');
		if (tooltipClass[0]){
			tooltipClass[0].parentNode.removeChild(tooltipClass[0]);
		}
	});
	
	/* Listen for question mark rollovers (inlineHelp)
	 * Last Modified: Ross 3:00pm 8/3/10
	 */
	var allWithinClass = $('.inlineHelp');
	var createdAlready = false;
	//var newTooltip = new CreateTooltip();
	YAHOO.util.Event.addListener(allWithinClass,'mouseover',function(event){
		
		if (navigator.userAgent.indexOf('Firefox') !=-1){
			eventId = event.target.id;
		}
		/*else if (navigator.userAgent.indexOf('IE') != -1){
			alert("IE");
		}*/
		else{
			eventId = event.srcElement.id;
		}
		if (eventId == 'questionStep2'){
			if (!createdAlready){
				newTooltip.showHTML('questionStep2',205,468,"All events posted on StayClassy must have a charity beneficiary attached. Pick your favorite charity to support, or let us recommend one for you!");
			}
		}
		else if (eventId == 'questionStep3'){
			if (!createdAlready){
				newTooltip.showHTML('questionStep3',320,379,"Requiring an admission fee or fundraising minimum for admission to your event is a great way to raise money for your favorite charity.  Choose the ticketing option that works best for you!");
			}
		}
		else if (eventId == 'questionStep3Reg'){
			if (!createdAlready){
				newTooltip.showHTML('questionStep3Reg',390,255,"All events posted on StayClassy must have a charity beneficiary attached. Pick your favorite charity to support, or let us recommend one for you!");
			}
		}
		else if (eventId == 'questionStep3Fund'){
			if (!createdAlready){
				newTooltip.showHTML('questionStep3Fund',425,300,"All events posted on StayClassy must have a charity beneficiary attached. Pick your favorite charity to support, or let us recommend one for you!");
			}
		}
		else if (eventId == 'questionStep8FundBar'){
			if (!createdAlready){
				newTooltip.showHTML('questionStep8FundBar',2018,331,"Show your guests how much money they're raising for charity.  Watch your fundraising bar grow higher as donations and ticket sales come rolling in!");
			}
		}
		else if (eventId == 'questionStep8FundGoal'){
			if (!createdAlready){
				newTooltip.showHTML('questionStep8FundGoal',2082,566,"How much money can you raise for charity?  You can even hide the fundraising bar until you've raised a certain percentage of your goal.");
			}
		}
		else if (eventId == 'questionStep8GuestList'){
			if (!createdAlready){
				newTooltip.showHTML('questionStep8GuestList',2172,335,"Let your guests see who else is coming, or keep the attendance information private.  You can even choose to hide the list until a certain number of people have replied.");
			}
		}
		else if (eventId == 'questionStep8Private'){
			if (!createdAlready){
				newTooltip.showHTML('questionStep8Private',2173,321,"Want to limit attendance to just your family and friends?  Check this box, and limit attendance only to the guests you've invited.  If this option is selected, your event won't show up on the beneficiary's charity profile or our events channels.");
			}
		}
		else if (eventId == 'questionStep8Tshirt'){
			if (!createdAlready){
				newTooltip.showHTML('questionStep8Tshirt',2219,348,"Providing a t-shirt is a great way to give something back to your guests, and raise awareness for the charity beneficiary.  Clicking this option will allow you to post an image of the t-shirt and let guests enter their preferred t-shirt size.");
			}
		}
	});

	
	YAHOO.util.Event.addListener(allWithinClass,'mouseout',function(event){
		var tooltipClass = $('.questionTooltip');
		
		if (tooltipClass[0]){
			tooltipClass[0].parentNode.removeChild(tooltipClass[0]);
			createdAlready = false;
		}
	});
	/*End of inlineHelp tooltip windows*/

	YAHOO.util.Event.addListener(YAHOO.util.Selector.query('fieldset > .option > label input[type="checkbox"]'),'click',function(event){
		if(this.checked === true){
			YAHOO.util.Dom.getAncestorBy(this,function(el){
				if(YAHOO.util.Dom.hasClass(el,'option')){
					YAHOO.util.Dom.getElementsByClassName('more','div',el,function(m){
						m.style.display = "block";
					});
				}
			});
		} else {
			YAHOO.util.Dom.getAncestorBy(this,function(el){
				if(YAHOO.util.Dom.hasClass(el,'option')){
					YAHOO.util.Dom.getElementsByClassName('more','div',el,function(m){
						m.style.display = "none";
					});
				}
			});
		}
	});
	
	/**Radio Select**/
	YAHOO.util.Event.addListener(YAHOO.util.Selector.query('fieldset > .option > label input[type="radio"]'),'click',function(event){
		if (lastRadio != null){
			YAHOO.util.Dom.getAncestorBy(lastRadio,function(el){
				if(YAHOO.util.Dom.hasClass(el,'option')){
					YAHOO.util.Dom.getElementsByClassName('more','div',el,function(m){
						m.style.display = "none";
						//alert("Left Radio");
						
					});
				}
			});
		}
		if(this.checked === true){
			YAHOO.util.Dom.getAncestorBy(this,function(el){
				if(YAHOO.util.Dom.hasClass(el,'option')){
					YAHOO.util.Dom.getElementsByClassName('more','div',el,function(m){
						m.style.display = "block";
						//alert("testing");
						
					});
				}
			});
		} else {
			YAHOO.util.Dom.getAncestorBy(last,function(el){
				if(YAHOO.util.Dom.hasClass(el,'option')){
					YAHOO.util.Dom.getElementsByClassName('more','div',el,function(m){
						m.style.display = "none";
					});
				}
			});
		}
		lastRadio = this;
		
	});
	/**End of Radio Select**/
	
	YAHOO.util.Dom.getElementsByClassName('tier2','ul','admin_left_navigation',function(e){
		if(YAHOO.util.Dom.getElementsByClassName('tier1','a',e.parentNode).length > 0){
			//e.style.display = "none";
		}
	});
	YAHOO.util.Event.addListener(YAHOO.util.Selector.query('#admin_left_navigation a#nav_invite_promote'),'click',function(event){
		if(this.parentNode.getElementsByTagName('ul').length > 0){
			YAHOO.util.Event.preventDefault(event);
			var secNav = this.parentNode.getElementsByTagName('ul')[0];
			if(secNav.style.display != "none"){
				secNav.style.display = "none";
				document.getElementById("nav_invite_promote").style.backgroundImage = "url(/images/admin_left_navigation_tier1.png)";
				
			} else {
				secNav.style.display = "block";
				document.getElementById("nav_invite_promote").style.backgroundImage = "url(/images/admin_left_navigation_tier1_close.png)";
			
			}
		}
	});
	
	YAHOO.util.Event.addListener(YAHOO.util.Selector.query('#admin_left_navigation a#nav_customer_service'),'click',function(event){
		if(this.parentNode.getElementsByTagName('ul').length > 0){
			YAHOO.util.Event.preventDefault(event);
			var secNav = this.parentNode.getElementsByTagName('ul')[0];
			if(secNav.style.display != "none"){
				secNav.style.display = "none";
				document.getElementById("nav_customer_service").style.backgroundImage = "url(/images/admin_left_navigation_tier1.png)";
				
			} else {
				secNav.style.display = "block";
				document.getElementById("nav_customer_service").style.backgroundImage = "url(/images/admin_left_navigation_tier1_close.png)";
			
			}
		}
	});
	
	YAHOO.util.Event.addListener(YAHOO.util.Selector.query('#admin_left_navigation a#nav_fundraising'),'click',function(event){
		if(this.parentNode.getElementsByTagName('ul').length > 0){
			YAHOO.util.Event.preventDefault(event);
			var secNav = this.parentNode.getElementsByTagName('ul')[0];
			if(secNav.style.display != "none"){
				secNav.style.display = "none";
				document.getElementById("nav_fundraising").style.backgroundImage = "url(/images/admin_left_navigation_tier1.png)";
				
			} else {
				secNav.style.display = "block";
				document.getElementById("nav_fundraising").style.backgroundImage = "url(/images/admin_left_navigation_tier1_close.png)";
			
			}
		}
	});
	
	
	if(YAHOO.util.Selector.query('fieldset#my_interests').length){
		var visibleInterests = YAHOO.util.Selector.query('#interests_right')[0];
		var interestGroupsA = YAHOO.util.Selector.query('#interests_left li a');
		var interestGroupsLi = YAHOO.util.Selector.query('#interests_left li');
		var interestGroupsList = YAHOO.util.Selector.query('#interests_left ul')[0];
		var interestGroups = YAHOO.util.Selector.query('#interests_right .interest_group');
		var groupIndex;
		var clickedLi;

		for (var i=0; i<interestGroupsA.length; i++) {
			YAHOO.util.Event.addListener(interestGroupsA[i], 'click', function(event){
				YAHOO.util.Event.preventDefault(event);
				
				// deactivate the others
				for (var i=0; i<interestGroupsLi.length; i++) {
					YAHOO.util.Dom.removeClass(interestGroupsLi[i], 'active');
				};
				
				// activify it!
				clickedLi = this.parentNode;
				if(this.parentNode.nodeName != 'LI'){
					clickedLi = this.parentNode.parentNode;
				}
				YAHOO.util.Dom.addClass(clickedLi, 'active');
								
				// figure out which index to display
				for (var k=0; k<interestGroupsLi.length; k++) {
					if(interestGroupsLi[k] == clickedLi){
						groupIndex = k;
					}
				};
				
				// hide the groups
				for (var i=0; i<interestGroups.length; i++) {
					YAHOO.util.Dom.addClass(interestGroups[i], 'hidden');
				};
				
				// show the new group
				YAHOO.util.Dom.removeClass(interestGroups[groupIndex], 'hidden');
				
				var rightParentOffset = YAHOO.util.Dom.getRegion(YAHOO.util.Selector.query('#my_interests')[0]).top;
				var leftHeight = YAHOO.util.Dom.getRegion(interestGroupsList).height;
				var rightHeight = YAHOO.util.Dom.getRegion(interestGroups[groupIndex]).height;
				var listPosition = parseFloat((groupIndex)/(interestGroupsLi.length - 1));
				var listTopOffset = (YAHOO.util.Dom.getRegion(clickedLi).top - rightParentOffset)
				
				
				var rightSideCenter = Math.round(rightHeight/2);
				var rightSideTop = 10;
				var rightSideBottom = rightHeight - 30;
				var verticalOffset = 0;			
				
				listTopOffset = listTopOffset - 90;
					
				if(listPosition < 0.5){
					verticalOffset = rightSideTop;
				}if(listPosition == 0.5){
					verticalOffset = rightSideCenter;
				}if(listPosition > 0.5){
					verticalOffset = rightSideBottom;
				}
				
				var calculatedOffset = listTopOffset - verticalOffset;
								
				if((calculatedOffset >= 0) && (leftHeight >= rightHeight)){
					visibleInterests.style.marginTop = calculatedOffset + 'px';
				}else{
					visibleInterests.style.marginTop = '-5px';
				}		
			});
		};
	}
});