jQuery( function($) {

	/********************************************/
	/********** Main menu hover effect **********/
	/********************************************/
	$("#mainMenu li a").hover(
		function() {
			$(this).animate( { fontSize: "20px" }, 200 ).css( 'font-size', 20 );
		},
		function() {
			$(this).stop( true ).animate( { fontSize: "15px" }, 100 );
		}
	);
	
	/********************************************/
	/*********** Flag hover effect **************/
	/********************************************/
	$('#languageSelect .flagContainer').hover(
		function() {
			$(this).find('a').animate( { top: 2 }, 200, 'swing' );
			$(this).find('.reflection').animate( 
				{ 
					bottom: 2,
					opacity: 0.5
				},
				100, 'swing' );
		},
		function() {
			$(this).find('a').stop().animate( { top: '5px' }, 200, 'swing' );
			$(this).find('.reflection').animate( 
				{
					bottom: 5,
					opacity: 1
				},
				100, 'swing' );
		}
	);	
	
	/********************************************/
	/********** Sitemap slide down effect *******/
	/********************************************/
	var originalHeight = $('#sitemap').height();
	var newHeight = $('#sitemap .element').height();
	$('#sitemap').hoverIntent( 
		function() {
			$(this).animate( { height: newHeight }, 250 );
		},
		function() {
			$(this).stop().animate( { height: originalHeight }, 250 );
		}
	);
	
	/********************************************/
	/********** Left menu accordion effect ******/
	/********************************************/
	$("#findClinic #accordion").tabs("#accordion .pane", {tabs: 'h3', effect: 'slide', initialIndex: null});
	$("#findClinic #accordion h3").hover(
		function() {
			$(this).animate( { 
				fontSize: "18px",
				paddingLeft: "3px"
			}, 100 );
		},
		function() {
			$(this).stop( true ).animate( { 
				fontSize: "15px",
				paddingLeft: "0"
			}, 100 );
		}
	);
	
	/********************************************/
	/********** Tell a friend drop down effect **/
	/********************************************/
	$(".tellAFriend").click( 
		function() {
			$("#tellAFriendContainer").animate(	{height: 150, marginTop: 20, padding: 10 }, 250, "swing" ).animate( {opacity: 1}, 250 );
		}
	);
	$(".minimize").click( 
		function() {
			$("#tellAFriendContainer").animate( {opacity: 0}, 250 ).animate( {height: 0, marginTop: 0, padding: 0}, 250, "swing" );
		}
	);
	
	/********************************************/
	/************** Form validation *************/
	/********************************************/
	/* Todo: automatically find forms in page   */
	/* and apply valdiation rules               */
	$('#formTip').submit( 
		function() {
			var valid = true;
			$('#formTip .reqd').each( 
				function(index) {
					console.log( this.value );
					if( this.value == '' ) {
						$('#formTip .submitError').css('display','inline');
						$(this).addClass('error');
						valid = false;
					}
					else $(this).removeClass('error');
				}
			);
			return valid;						   
		}
	);
	
	$('#contactUsForm').submit( 
		function() {
			var valid = true;
			$('#contactUsForm .reqd').each( 
				function(index) {
					console.log( this.value );
					if( this.value == '' ) {
						$('#contactUsForm .submitError').css('display','inline');
						$(this).addClass('error');
						valid = false;
					}
					else $(this).removeClass('error');
				}
			);
			return valid;						   
		}
	);
	
	$('#clinicContact').submit( 
		function() {
			var valid = true;
			$('#clinicContact .reqd').each( 
				function(index) {
					console.log( this.value );
					if( this.value == '' ) {
						$('#clinicContact .submitError').css('display','inline');
						$(this).addClass('error');
						valid = false;
					}
					else $(this).removeClass('error');
				}
			);
			return valid;						   
		}
	);
	
	$('#potentialForm').submit( 
		function() {
			var valid = true;
			$('#potentialForm .reqd').each( 
				function(index) {
					console.log( this.value );
					if( this.value == '' ) {
						$('#potentialForm .submitError').css('display','inline');
						$(this).addClass('error');
						valid = false;
					}
					else $(this).removeClass('error');
				}
			);
			return valid;						   
		}
	);
	
	$('#registrationForm').submit( 
		function() {
			var valid = true;
			$('#registrationForm .reqd').each( 
				function(index) {
					if( this.value == '' ) {
						$('#registrationForm .submitError').css('display','inline');
						$(this).addClass('error');
						valid = false;
					}
					else $(this).removeClass('error');
				}
			);
			return valid;						   
		}
	);
	
	/********************************************/
	/************ Toggle radio button ***********/
	/********************************************/
	$('.radioBtn').toggle(
		function() {
    		$(this).addClass("selected");
  		},
		function () {
			$(this).removeClass("selected");
		}
	);

	/********************************************/
	/******* Expand disclaimer on reg. page *****/
	/********************************************/
	$('#regDisclaimer a').click( function() {
		if( !$('#conditions').hasClass('expanded') ) {
			var startHeight = $('#conditions').height();
			console.log(startHeight);
			$('#conditions').css( 'height', 0 ).css( 'display', 'block' ).addClass('expanded');
			$('#conditions').animate( { height: startHeight }, 250, 'swing' );
		}
	});
	
	$('#regDisclaimer .radioBtn').click( function() {
		if( $('#conditions').hasClass('expanded') ) {
			var startHeight = $('#conditions').outerHeight(true);
			$('#conditions').animate( { height: 0 }, 150, 'swing', 
				function() {
					$('#conditions').css('display','none').css('height',startHeight+'px').removeClass('expanded');
				}
			);
		}
	});

}); //jQuery end
