$(document).ready( function() {
	//Showoff checkbox
	$('#sendMe').addClass('Disappear');
	$('#sendMeLabel').addClass('CheckReplace');		
	
	//Handler my checkbox
	if ($('#sendMe').attr('checked') == true)  $('#sendMeLabel').addClass('CheckReplaceActive');
	$('#sendMeLabel').click(checkMe);
	
	//Handler my radio
	$('#personalize li input[@name=personalize]').each(function(){
		if($(this).attr('checked') == true) {
			$('#personalize li label[@for='+this.id+']').addClass('RadioReplaceActive');
			changePreview(this.id);
		}
	});
	$('#personalize li input').addClass('Disappear');
	$('#personalize li label').addClass('RadioReplace');	
	
	$('#personalize li label').click(function(){
		unChooseAll();
		$(this).addClass('RadioReplaceActive');
		changePreview($(this).attr('for'))
	});
	
	//Handler reset button
	$('#reset').click(function(){
        unChooseAll()
		$('#personalize li input#family').attr('checked',true);
		$('#personalize li label[@for=family]').addClass('RadioReplaceActive');
		
		$('#yourNameError').removeClass('Error')
		$('#yourName').val('');
		$('#yourName').focus();
		
		$('#yourEmailError').removeClass('Error')
		$('#yourEmail').val('');
		
		$('#friendNameError').removeClass('Error')
		$('#friendName').val('');
		
		$('#friendEmailError').removeClass('Error')
		$('#friendEmail').val('');
		
		if ($('#sendMe').attr('checked') != true) {
			checkMe();
			$('#sendMe').attr('checked',true);
		}
		
		return false;
	});
	
	//Lets validate
	$('#mailfriendForm').submit(function(){
		
		if($('#yourName').val().length < 2) {
			$('#yourNameError').addClass('Error');
			$('#yourName').focus();
			return false;
		} else {
			$('#yourNameError').removeClass('Error');
		}
		
		if(! $('#yourEmail').val().match(/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i)) {
			$('#yourEmailError').addClass('Error');
			$('#yourEmail').focus();
			return false;
		} else {
			$('#yourEmailError').removeClass('Error');
		}
		
		if($('#friendName').val().length < 2) {
			$('#friendNameError').addClass('Error');
			$('#friendName').focus();
			return false;
		} else {
			$('#friendNameError').removeClass('Error');
		}
		
		if(! $('#friendEmail').val().match(/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i)) {
			$('#friendEmailError').addClass('Error');
			$('#friendEmail').focus();
			return false;
		} else {
			$('#friendEmailError').removeClass('Error');
		}
		
	});
	
	$('#yourName').bind('blur',function(){
		if($('#yourName').val().length < 2) {
			$('#yourNameError').addClass('Error');
		} else {
			$('#yourNameError').removeClass('Error');
		}								
	});
	$('#yourEmail').bind('blur',function(){
		if(! $('#yourEmail').val().match(/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i)) {
			$('#yourEmailError').addClass('Error');
		} else {
			$('#yourEmailError').removeClass('Error');
		}									
	});
	$('#friendName').bind('blur',function(){
		if($('#friendName').val().length < 2) {
			$('#friendNameError').addClass('Error');
		} else {
			$('#friendNameError').removeClass('Error');
		}	
	});
	$('#friendEmail').bind('blur',function(){
		if(! $('#friendEmail').val().match(/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i)) {
			$('#friendEmailError').addClass('Error');
		} else {
			$('#friendEmailError').removeClass('Error');
		}	
	});
	
	
});

function unChooseAll() {
	$('#personalize li label').removeClass('RadioReplaceActive');
}

function checkMe() {
	$('#sendMeLabel').toggleClass('CheckReplaceActive');
}

function changePreview(ID) {
	img = $('.EmailPreview img');
	title = $('.EmailPreview dt').next();
	desc = title.next();
	
	switch (ID) {
		case 'family':
			title.text('Kristi Yamaguchi - National Spokesperson');
			desc.text('Olympic Gold Medalist Kristi Yamaguchi takes her career as a figure skater seriously. In addition, since her victories on "Dancing with the Stars" and experience as an American role model, she has taken on an even more serious role in life—her family.');
			img.attr('src','/images/thumbs/15.jpg');
			img.attr('alt','Kristi Yamaguchi—National Spokesperson');
		break;
		case 'adult':
			title.text('Kristi Yamaguchi - National Spokesperson');
			desc.text('Olympic Gold Medalist Kristi Yamaguchi takes her career as a figure skater seriously. In addition, since her victories on "Dancing with the Stars" and experience as an American role model, she has taken on an even more serious role in life—her family.');
			img.attr('src','/images/thumbs/15.jpg');
			img.attr('alt','Kristi Yamaguchi—National Spokesperson');
		break;
		case 'old':
			title.text('Dr. Joyce Brothers - Long-time Family Psychologist and Advice Columnist');
			desc.text('Dr. Brothers firmly believes that flu shots are critical for families, because they help keep parents at work and kids at school.');
			img.attr('src','/images/thumbs/21.jpg');
			img.attr('alt','Dr. Joyce Brothers');
		break;
		case 'illness':
			title.text('Dean Cain - Actor, Father, and Asthmatic');
			desc.text('Actor Dean Cain has asthma.  While he may have been a great football player and appeared as Superman on the popular television series "Lois and Clark," he knows he’s no real-life superhero.  He fears getting the flu.');
			img.attr('src','/images/thumbs/23.jpg');
			img.attr('alt','Dean Cain');
		break;
	}
}