//////////////////////////
///////// CUFON //////////
//////////////////////////

////////// HEADER FOOTER //////////
Cufon.replace('.footer-nav a');
Cufon.replace('#main-navigation a', {hover: true});
Cufon.replace('#footer .links span', {fontFamily: 'coconotBold'});
Cufon.replace('#strapline, p.author, p.num_comments, div.date p , #footer .links a' , {fontFamily: 'coconotLight'});
//Cufon.replace('#footer .links a', {fontFamily: 'coconotLight'});

////////// HEADERS //////////
Cufon.replace('.our-products h2');
Cufon.replace('#home-modules h2', {hover: true});
Cufon.replace('h1', {textShadow: '#22447E 0px 3px'});
Cufon.replace('.error-page h1', {textShadow: 'none'});
Cufon.replace('.h1-description , .from-our-blog h2 , body#products #column-right h2 , body#products #column-right .case-study span', {fontFamily: 'coconotLight'});
//Cufon.replace('.h1-description', {fontFamily: 'coconotLight'});
//Cufon.replace('.from-our-blog h2', {fontFamily: 'coconotLight'});
//Cufon.replace('body#products #column-right h2', {fontFamily: 'coconotLight'});
//Cufon.replace('body#products #column-right .case-study span' ,{fontFamily: 'coconotLight'});

////////// LINKS AND OTHERS //////////
Cufon.replace('body#products #column-right .modules h2');
Cufon.replace('.reasons .title span', {fontFamily: 'coconotBold'});
Cufon.replace('.home-quote', {textShadow: '#22447E 0px 1px',fontFamily: 'coconotLight'});
Cufon.replace('.main-features-list a , #column-left .quote p , .about-overview .intro , .approach-overview .intro, body#products #column-right .product-clc .features li , .approach-overview .quotes ul', {fontFamily: 'coconotLight'});
Cufon.replace('.contact-us p , .product-parental-engagement-contact-us p , .product-clc-contact-us , .our-products a , #column-left span , #column-left .life a , #button-list .download , #button-list .register , .approach-overview .contact-us , body#products #column-right #award-list h2 span , .principles p , .book-now');
//Cufon.replace('.our-products a');
//Cufon.replace('#column-left span');
//Cufon.replace('#column-left .life a');
//Cufon.replace('#button-list .download');
//Cufon.replace('#button-list .register');
//Cufon.replace('.approach-overview .contact-us');
//Cufon.replace('body#products #column-right #award-list h2 span');
//Cufon.replace('#column-left .quote p', {fontFamily: 'coconotLight'});
//Cufon.replace('.about-overview .intro', {fontFamily: 'coconotLight'});
//Cufon.replace('.approach-overview .intro', {fontFamily: 'coconotLight'});

//////////////////////////////
///////// CUFON END //////////
//////////////////////////////
$(document).ready(function() {
	
	$('#column-left div.facebook').click(function(){
		window.open('http://www.facebook.com/Lifeisabout');
	});
	
	$("#contact-form").submit(function() {
		var return_val = true;
		
		if($("#name").val().length<1) {
			if ($('#name').prev('span').length == 0)
			{
				$("<span class=\"error\">Please enter your name</span>").insertBefore("#name");
			}
			return_val = false;
		} else {
			if ($('#name').prev('span').length > 0) {
				$('#name').prev('span').remove();
			}
		}
		if($("#email").val().length<1) {
			if ($('#email').prev('span').length == 0)
			{
			  $("<span class=\"error\">Please enter your email address</span>").insertBefore("#email");
			}
			return_val = false;
		} else {
			if ($('#email').prev('span').length > 0) {
				$('#email').prev('span').remove();
			}
		}
		if($("#nature_enquiry").val().length<1) {
			if ($('#nature_enquiry').prev('span').length == 0)
			{
				$("<span class=\"error\">How can we help?</span>").insertBefore("#nature_enquiry");
			}
			return_val = false;
		} else {
			if ($('#nature_enquiry').prev('span').length > 0) {
				$('#nature_enquiry').prev('span').remove();
			}
		}
		if($("#message").val().length<1) {
			if ($('#message').prev('span').length == 0)
			{
				$("<span class=\"error\">Please enter a message</span>").insertBefore("#message");
			}
			return_val = false;
		} else {
			if ($('#message').prev('span').length > 0) {
				$('#message').prev('span').remove();
			}
		}
		
		if(return_val==true) {
		  $("#name").attr('disabled','true');
		  $("#email").attr('disabled','true');
		  $("#telephone").attr('disabled','true');
		  $("#nature_enquiry").attr('disabled','true');
		  $("#message").attr('disabled','true');
		  $("#send").attr('disabled','true');
				
			$.ajax({
				url: '/ajax/contact',
				type: 'post',
				data: 'name=' + $("#name").val() + '&email=' + $("#email").val() + '&telephone=' + $("#telephone").val() + '&nature_enquiry=' + $("#nature_enquiry").val() + '&message=' + $("#message").val(),
				success: function(data) {
					
					$("#contact_title").remove();
					$("#contact-form").remove();
					$(".contact-area").prepend("<div id=\"msg_sent\"><h2>Thank you for getting in touch</h2><p>We'll get back to you shortly.</p></div>");
					Cufon.replace('h2');
				}
			});
		}
		return false;
		
	});
var twid = 'uniservity';
if($("#twitter_post").hasClass('lifeisabout')) {
	twid = 'lifeisabout';
}
$.ajax({
	url: '/twitter_controller',
	type: 'post',
	data: 'twitter_id=' + twid,
	success: handle_twitter
});
function handle_twitter(data) {
	if(data.length>1) {
		$("#twitter_post").html(data);
	}
}

$("#comment_form").submit(function() {
	var name = $("#com_name").val();
	var email = $("#com_email").val();
	var website = $("#com_website").val();
	var message = $("#com_message").val();
	var notify = $("#notify_c:checked").val();
	
	var id = $("#post_id").val();
	
	var errors = false;
	if(name.length<1) {
		$("<span class=\"error\">Please enter your name</span>").insertBefore("#com_name");
		errors = true;
	}
	if(email.length<1) {
		$("<span class=\"error\">Please enter your email address</span>").insertBefore("#com_email");
		errors = true;
	}
	if(message.length<1) {
		$("<span class=\"error\">Please enter a message</span>").insertBefore("#com_message");
		errors = true;
	}
	
	if(notify!=undefined) {
		notify = "true";
	} else {
		notify = "false";
	}
	
	if(errors == false) {
		$("#com_name").attr('disabled','true');
		$("#com_email").attr('disabled','true');
		$("#com_website").attr('disabled','true');
		$("#com_message").attr('disabled','true');
		$("#comment_post_btn").attr('disabled','true');
		
		$.ajax({
		url: '/blog/submit_comment',
		type: 'post',
		dataType: "json",
		data: 'post_id=' + id + "&name=" + name + "&email=" + email + "&website=" + website + "&message=" + message + "&notify=" + notify,
		success: function(data) {
			$("#com_name").removeAttr('disabled');
			$("#com_email").removeAttr('disabled');
			$("#com_website").removeAttr('disabled');
			$("#com_message").removeAttr('disabled');
			$("#comment_post_btn").removeAttr('disabled');
		
			if(data.status=="success") {
				$("#com_name").val('');
				$("#com_email").val('');
				$("#com_website").val('');
				$("#com_message").val('');
				
				$("#comment_num").html(data.comNum + " comments to this post");
				$("#alt_comm_num").html(data.comNum);
				Cufon.replace("#comment_num, #alt_comm_num");
				
				
				$(window).scrollTop(300 + $(".post").height());
				
				$("#comment_list").prepend("<li><div class=\"comm_details\"><img height=\"69\" width=\"68\" alt=\"\" src=\"/_images/_icons/commenter.png\"><div class=\"poster_details\">" + data.name + "<span class=\"poster_date\">" + data.cdate + "</span></div></div><div class=\"comm\"><p>" + data.message + "</p></div></li>");
				$.alerts.okButton = 'OK';
				jAlert('<p class="small">Your comment has been added.</p>','Thanks for posting'); 
			}
		}
		});
	}
	
	return false;
});

});
