$(document).ready(function(){
	$('.iframe').each(function(){
	var re = /href="(http:\/\/)?.+?\/(.+?)(t=.+?)?"/ig;
	var str = $(this).html();
	var matches = re.exec(str);
	var link = matches[2];
	var t = matches[3];
	var re2 = /t=([0-9]{0,2})m([0-9]{0,2})s/i
	var matches2 = re2.exec(t);
	if(matches2!=null){
		var t = matches2[1]*60 + Number(matches2[2]);
		var t = 'start=' + t;
		var frame = '<div class="video"><iframe width="474" height="295" src="http://www.youtube.com/embed/' + link + t + '" frameborder="0" allowfullscreen></iframe></div>'
	} else {
		var frame = '<div class="video"><iframe width="474" height="295" src="http://www.youtube.com/embed/' + link + '" frameborder="0" allowfullscreen></iframe></div>'
	}
	$(this).html(frame);
	});
	$('.post:even').addClass('zebra');
	$('.drop-down, .drop-down2').hide();
	$('#window').css({height: '0px'});
	$('.biography').click(function(){
		$(this).parent().parent().children('.drop-down').toggle('slow');
		return false;
	});
	$('.biography2').click(function(){
		$('.drop-down2').toggle('slow');
		return false;
	});
	$('.more').click(function(){
		if($('#window').height() == 0)
		{
			$('#window').animate({height: '185px'}, function(){
				$('.more').text('Read Less');
			});
		}
		else
		{
			$('#window').animate({height: '0'}, function(){
				$('.more').text('Read More');
			});
		}
		return false;
	});
	$('#modules div').click(function(){
		if($(this).attr('class') == 'down'){
			$(this).removeClass('down');
			module = $(this).text();
			text = $('textarea').text();
			text = text.replace(module + ';\n', '');
			$('textarea').text(text);
		} else {
			$(this).addClass('down');
			$('#build-ur-course').children('.drop-down').show('slow');
			text = $('textarea').text() + $(this).text() + ';\n';
			$('textarea').text(text);
		}
	});
	$('#send').click(function(){
		var regex = /^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$/i
		if (regex.test($(this).parent().siblings().children('#email').val())){
			return true;
		} else {
			$(this).parent().siblings().children('#email').addClass('error');
			$('.error').next('span').show();
			return false;
		}
	});
	$('#email, #message').focus(function(){
		$(this).removeClass('error').next('span').hide();
	});
});
