jQuery(document).ready(function(){
	
	// hide mailform and respond div's
	if(jQuery.url.attr("anchor") != 'mc_signup_form'){
		jQuery('.slider').hide();
	}
	
	jQuery("[class|='respond']").hide();


	var anchor = jQuery.url.attr("anchor");

	if(anchor != null && anchor.indexOf("respond") != -1){
		//console.log("document anchor = " + anchor);
		jQuery('.' + anchor).show();
	}

	jQuery('li#recentComments a').click(function(){

			var linkAnchor = jQuery(this).attr('href');
			var hashPosition = linkAnchor.indexOf('#');
			
			linkAnchor = linkAnchor.slice(hashPosition+1);
									
			//console.log("click anchor = " + linkAnchor);
			jQuery('.' + linkAnchor).show();
		
	});
	
	// mailinglist inline label behaviour
	var Garp = {};
	Garp.inlineLabels = {
		/**
		 * Find correct labels on the page and display 'em 'inline'
		 * @param Mixed jQueryelements Optional elements, if none, "label.inline" will be used.
		 */
		init: function(elements) {
			var self = this;
			elements = elements || 'label.inline';
			jQuery(elements).each(function() {
				var thisLabel = jQuery(this);
				var input = jQuery('#'+thisLabel.attr('for'));
				input.focus(function() {
					self.focus.call(input, thisLabel);
				}).blur(function() {
					self.blur.call(input, thisLabel);
				});
				// 'cause browsers remember certain form values, there needs to be one manual check.
				setTimeout(function() {
					if (jQuery(input).val()) {
						self.focus.call(input, thisLabel);
					}
				}, 1000);
			});
		},
		/**
		 * Focus event handler on inputs
		 */
		focus: function(theLabel) {
			theLabel.addClass('hidden');
		},
		/**
		 * Blur event handler on inputs
		 */
		blur: function(theLabel) {
			if (!this.val()) {
				theLabel.removeClass('hidden');
			}
		}
	};
	Garp.inlineLabels.init(jQuery('#mc_signup_form label'));

	// if reaction link is clicked, slide up/down respond div
	var slideComment = function() {
		
		var n = this.className.slice(9);
							
		jQuery('.respond-' + n).slideToggle('slow');
		return false;
	};
	
	// if mailinglist link is clicked, slide down mailform
	jQuery('a.mailinglist').click(function() {
		jQuery('.slider').slideToggle('normal');
		return false;
	});

	// if respond link is clicked, slide down form and comments				
	jQuery("a[class|='comments']").click(slideComment);

	// scroll to top link in footer
	jQuery('a.top').click(function() {
		jQuery.scrollTo(0, 1000);
	});
});
