/**
 * Javascript for the Journey for Control Site
 *
 * @author	The Healthy Interactions Team
 */
$(document).ready( function(){
	// Hide the more info sections
	$('.info').hide();
});


$( function(){
	// Login form submission
	$('#login').submit( function(e){
		e.preventDefault();

		var data = {
			Email: this.Email.value,
			Password: this.Password.value
		};

		$.post( '/login/facilitation', data, function(response){
			response = jsonParse(response);

			// Sdnd message if things are messed up, if not, let the form submit
			if( ! response.success ){
				$('#login-message').hide().html( response.message ).addClass('error').fadeIn();
			} else {
				window.location = '/jfc/resources';
			}

		} );

	} );


	// Disclosure Arrows
	$('.disclosure').click( function(){
		if( $(this).hasClass('open') ){
			// Shut em down
			$(this).removeClass( 'open' );
			$(this).siblings('.info').hide();
		} else {
			// Open it up
			$(this).addClass( 'open' );
			$(this).siblings('.info').show();
		}
	});

	// Popup windows
	$('a[rel^=popup]').click( function(e){
		// Cancel link
		e.preventDefault();

		var args = this.rel.split('_');

		window.open( $(this).attr('href') , 'popup', 'width='+args[1]+',height='+args[2]);
	});

} );

/**
 * Zebra Striping Plugin
 *
 * @author 		Dave Widmer
 * @version		v1.3		2008-12-03
 * @url			http://www.davewidmer.net
 *
 * @usage		Add .stripe() to your jQuery chain
 */
(function($){
	/**
	* The zebra striping function
	*
	* @param options	Options for the zebra striping
	*/
	$.fn.stripe = function(options){
		// First element is an empty object so it won't override the defaults object
		options = $.extend( {}, $.fn.stripe.defaults, options );
		// Add in some properties
		options.stripes = options.classes.length;
		options.css = options.classes.join( ' ' );

		return this.each(function(){
			$(options.selector,this).each(function(i){
				$(this).removeClass( options.css );
				$(this).addClass( options.classes[ i % options.stripes ] );
			});
		});
	};

	$.fn.stripe.defaults = {
		selector: 'tr:visible',
		classes: ['odd','even']
	};

})(jQuery);