// Share friend
var addthis_config={services_exclude:'amazonwishlist,kaboodle,print,stylehive,thisnext,tipd,facebook,twitter'}
var addthis_share={url:'http://awomanisnotapreexistingcondition.com/',title:'Being a woman is not a pre-existing condition',content:"Health care isn't fair. Women pay more for the same coverage. Yet we've been left out of the debate on reform. It's time to make our voices heard. Watch the video and tell Congress to make affordable, accessible and comprehensive health care a reality this year.",templates:'',email_template:"NWLC_pec_template"}

// jQuery Functions
$( function () {
	
	// Scrolling
	$('a[href="#sec_a"]').click(function() {
		$.scrollTo($('#sec_a'),1000);
		return false;
	});
	$('a[href="#sec_b"]').click(function() {
		$.scrollTo($('#sec_b'),1000);
		return false;
	});
	$('a[href="#sec_c"]').click(function() {
		$.scrollTo($('#sec_c'),1000);
		return false;
	});
	$('a[href="#sec_d"]').click(function() {
		$.scrollTo($('#sec_d'),1000);
		return false;
	});
	$('a[href="#sec_d1"]').click(function() {
		$('#sec_d1').parent().attr('class','main active');
		$('#sec_d1a').toggle(true);
		$.scrollTo($('#sec_d1'),1000);
		return false;
	});
	$('a[href="#sec_e"]').click(function() {
		$.scrollTo($('#sec_e'),1000);
		return false;
	});
	$('a[href="#sec_f"]').click(function() {
		$.scrollTo($('#sec_f'),1000);
		return false;
	});
	$('a[href="#sec_g"]').click(function() {
		$.scrollTo($('#sec_g'),1000);
		return false;
	});
	$('a[href="#sec_q"]').click(function() {
		$.scrollTo($('#sec_q'),1000);
		return false;
	});
	
	// Return to Top
	$('a.top').click(function() {
		$.scrollTo('0px',1000);
		return false;
	});
	
	// Hide Sub-Lists
	$('ul.secondary').css('display','none');
	
	// Add Toggle to Links
	$('li.main a').click (function() {
		var li = $(this).parent();
		
		// Toggle Class
		if (li.attr('class') == 'main') {
			li.attr('class','main active');
		} else {
			li.attr('class','main');
		}
		
		// Toggle Sub List
		$('ul.secondary',li).toggle();
		return false;
	});
	
	// Select All Embed Code
	$('textarea#embed_code').click(function() {
		$(this).select();
	});
	$('input#vidEmbedCode_Txt').click(function() {
		$(this).select();
	});
	
	// Quiz Start
	$('input#start_quiz').click(function() {
		$('li.first').toggle();
		$(this).parent().toggle();
	});
	
	// Quiz
	$('ol#quiz li').each( function() {
		
		$('input.next',this).click(function (){
			
			var li = $(this).parent()
			
			// Require an Answer
			var answered = false;
			$('[type=radio]',li).each(function(){
				if (this.checked) answered = true;
			});
			
			if (!answered) {
				alert('You must choose an answer before proceeding to the next question.');
				return false;
			}
			
			// Next Question
			if (li.attr('class') != 'last') {
				li.next().toggle();
			
			// Last Question
			} else {
				
				var sum = 0;
				$('[type=radio]').each( function() {
					if (this.checked) {
						sum += ($(this).val() / 1);
					}
				});
				
				// Result A
				if (sum > 2) {
					$('#result_a').toggle();
				
				// Result B
				} else if (sum > -2) {
					$('#result_b').toggle();
				
				// Result C
				} else {
					$('#result_c').toggle();
				}
			}
			li.toggle();
		});
		
	});
	
	// Hint for Text Area
	$('textarea#message_message').each(function() {
		var default_value = '(Please personalize your message here)';
		
		if ($(this).val() == '') $(this).val(default_value);
		
		$(this).focus(function() {
			if(this.value == default_value) {
				this.value = '';
			}
		});
		$(this).blur(function() {
			if(this.value == '') {
				this.value = default_value;
			}
		});
	});

});

// Form Checking
function checkform(f) {
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	
	// Message
	if (f.id == 'form_message') {
	
		// Title
		if (f.message_title.value == '') {
			alert('A title is required. (e.x. Mrs. or Mr.)');
			f.message_title.focus();
			return false;
		}

		// First Name
		if (f.message_name_first.value == '') {
			alert('A first name is required.');
			f.message_name_first.focus();
			return false;
		}

		// Last Name
		if (f.message_name_last.value == '') {
			alert('A last name is required.');
			f.message_name_last.focus();
			return false;
		}
		
		// E-Mail
		if (f.message_email.value == '' || !f.message_email.value.match(emailExp)) {
			alert('A valid e-mail address is required.');
			f.message_email.focus();
			return false;
		}
		
		// Address Line 1
		if (f.message_addr_line_1.value == '') {
			alert('A address is required.');
			f.message_addr_line_1.focus();
			return false;
		}
		
		// City
		if (f.message_city.value == '') {
			alert('A city is required.');
			f.message_city.focus();
			return false;
		}
		
		// State
		if (f.message_state.value == '') {
			alert('A state is required.');
			f.message_state.focus();
			return false;
		}
		
		// Zip
		if (f.message_zip.value == '') {
			alert('A zip code is required.');
			f.message_zip.focus();
			return false;
		}
	
	}
	
	return true;
}

// create more videos list
$(document).ready(function(){
	$.ajax({
		type:"GET",
		url:"videoPlayer/videoPlaylist.xml",
		dataType:"xml",
		success:function(xml){
			$('<ul id="videoThumbList"></ul>').insertAfter("#vidEmbedCode");
			$('<h3 class="copy">More Videos</h3>').insertAfter("#vidEmbedCode");
			
			// embed first track from XML
			var firstVid = $(xml).find("track:first");
			embedVideo(firstVid.children("location").text(), firstVid.children("thumbnail").text(), 'true')
			
			// create thumbnail list for all videos
			$(xml).find("track").each(function(){
				$("<li></li>")
					.html('<a href="'+subdir+"/videoPlayer/"+$(this).children("location").text()+'"><img width="89" height="50" src="'+subdir+"/"+$(this).children("thumbnail").text()+'" title="'+$(this).children("title").text()+'" alt="'+$(this).children("annotation").text()+'"></a>')
					.appendTo("#videoThumbList");
			});
			
			// set now playing state
			$('<span class="nowplaying"><span class="inner">Now Playing</span></span>').appendTo("#videoThumbList li:first a");
			
			// set thumbnail listeners
			$("#videoThumbList a").click(function(e){
				embedVideo($(this).attr("href"), $(this).children("img").attr("src"), 'true');
				$(".nowplaying").remove().appendTo($(this));
				e.preventDefault();
			});
		}
	});		
});

swfobject.embedSWF("http://awomanisnotapreexistingcondition.com/widget/nwlc_not_a_preexisting_condition_Widget.swf", "flash_widget",'380','400',"9", subdir+"/swf/expressInstall.swf",{autoPlayFlashVar:'false',CID:'microsite',gig_lt:'1255965504897',gig_pt:'1255965507047',gig_g:'2'},{wmode:'transparent',allowScriptAccess:'always'});

function embedVideo(video, previewImg, autoplay)
{
	previewImg=previewImg.replace("small_", "");
	swfobject.embedSWF(subdir+"/videoPlayer/player.swf", "flash_video",'457','276',"9", subdir+"/videoPlayer/expressInstall.swf",{autostart:autoplay,file:video,image:previewImg},{wmode:'transparent',allowfullscreen:'true'});
}
