jQuery().ready( function() {
	// We remove the title tags from the images of these tooltiped items
	jQuery('#main a[title] img').attr('title', '');
	var Glossary = new Tips($$('acronym, input[title],#main a[title]'), {
		initialize:function(){
			this.fx = new Fx.Style(this.toolTip, 'opacity', {duration: 500, wait: false}).set(0);
		},
		onShow: function(toolTip) {
			this.fx.start(1);
		},
		onHide: function(toolTip) {
			this.fx.start(0);
		}
	});

	/*$$('#main a[title]').each(function(tip){

		var imgSrc = tip.retrieve('tip:text');

		var imgAlt = tip.retrieve('tip:title');

		tip.store('tip:text', new Element('img',{'src':imgSrc,'alt':imgAlt}));

	});*/
	
	// Detect if this is the feedback page
	if (jQuery('#feedback_speakerForm').length) {
		// set it so when a user clicks on a checkbox, it checks for all no's
		jQuery('#feedback_speakerForm input').bind('click', function() {
			checkForNos();
		});
		// Run it just in case we are loading it from the database...
		checkForNos();
	}
	
	// Create a flash like master navy thing on the home page
	PFTF.funcs.masterNav();
});


function checkForNos() {
	var flagMe = 0;
	
	jQuery('#feedback_speakerForm input:checked').each(function() {
		// Anytime we get a YES, set a flag
		if (jQuery(this).val() == '5') flagMe++;
	});
	
	if (flagMe > 3) {
		jQuery('#feedback_speakerAllnosRow span').css('display','block').hide().fadeIn(0);
	}
	
	return true;
}

var PFTF = { 
	defaults: {
		fadeSpeed: 250,
		/** 
		 * Is the home page mast currently doing stuff
		 * @var boolean
		 */
		mastInTransition: false
	}
};
PFTF.funcs = {
	masterNav: function() {
		jQuery('#mastlinks ul li a').bind('click', function() {
			// No point doing this if its the same one
			if (this.className == 'onlink') { return false; }
			// If we're doing something already, dont do anything...
			if (PFTF.mastInTransition == true) { return false; }
			
			// Track that we are doing stuff
			PFTF.mastInTransition = true;
			
			var me = this;
			jQuery('#mastlinks .mastdesc:visible').fadeOut(PFTF.defaults.fadeSpeed,function() { 
				//jQuery(this).hide();
				var hash = me.getAttribute('href').split('#');
				jQuery('#'+hash[1]).fadeIn(PFTF.defaults.fadeSpeed, function() { 
					PFTF.mastInTransition = false;
				});
			});
			
			//console.log(this.getAttribute('href'));
			jQuery('#mastlinks ul li a[class]').removeClass('onlink');
			jQuery(this).addClass('onlink');
			return false;
		});
	}	
};