﻿$(document).ready(function(){

//$('#navcontainer').hide();


$("#at").focus();


		  
$('textarea.contact').autogrow();		


$('.nav').livequery('click', function(){
$('#navcontainer').slideToggle('fast');

});

$('.nav').livequery('mouseover', function(){
$(this).css({ cursor:'hand'}).css({ cursor:'pointer'}); 
});





/*paypall script*/

// the minimum required value to be entered.
	// in this case PayPal takes $0.35 from a $1
	// donation, hence we ask for at least $1.35
	var minimum_value = 1.35;
 
	// attach this script to the form's submit action
	jQuery('#form_paypal').submit(function()
	{
		// check if there is an amount entered
		if (jQuery('#input_amount').val() > null)
		{
			// is the amount equal to or higher than the minimum_value?
			if (jQuery('#input_amount').val() < minimum_value)
			{
				// need more amount
				// hide messages, show more amount error
				jQuery('#msg_noamount').hide();
				jQuery('#msg_moreamount').fadeIn();
				return false; // prevent the form from submitting
			}
			else
			{
				// amount is more than minimum_value
				// hide messages, show activity
				jQuery('#msg_moreamount').hide();
				jQuery('#msg_noamount').hide();
				jQuery('#msg_activity').fadeIn();
				return true; // submit the form
			}
		}
		else
		{
			// no amount entered at all
			// hide messages, show no amount error
			jQuery('#msg_moreamount').hide();
			jQuery('#msg_noamount').fadeIn();
			return false; // prevent the form from submitting
		}
	});





 






//----inspiratieknop
 $("#muze").livequery('click', function(){
var at= $("#at").val();
if(at == '@'){
var to='';
}
if(at != '@'){
var to=at+": ";

}
if(at == ''){
var to=at+"";

}

$.ajax({
		type: "POST",
		dataType: "html",
		url: "ajax_insp.php",
		data: {
		to:to,
		at:at
		},
		success: function(response){
		var resplength=response.length;
		$("#lovetwit_content").val(response);
		$(".charsLeft").text(140-resplength);
	
		}
	});

	
});
























//contact
$("#stuur").livequery('click', function(){
	var name=$("#name").val(); 
	var email=$("#email").val(); 
	var mess=$("#mess").val(); 
$.ajax({
		type: "POST",
		dataType: "html",
		url: "ajax_contact.php",
		data: {
		name:name,
		email:email,
		mess:mess,
		},
		success: function(response){
		//alert (response);
		if(response=='a'){// aspam error
				$("#name").css('border','1px solid red');
				}
		if(response=='b'){// text error
				$("#email").css('border','1px solid red');
				}
		if(response=='ab'){// aspam en text error
				$("#name").css('border','1px solid red');
				$("#email").css('border','1px solid red');
				}
		if(response=='c'){// aspam en text error
				$("#mess").css('border','1px solid red');
				}
		if(response=='ac'){// aspam en text error
				$("#name").css('border','1px solid red');
				$("#mess").css('border','1px solid red');
				}
		if(response=='cb'){// aspam en text error
				$("#email").css('border','1px solid red');
				$("#mess").css('border','1px solid red');
				}
		if(response=='abc'){// aspam en text error
				$("#name").css('border','1px solid red');
				$("#email").css('border','1px solid red');
				$("#mess").css('border','1px solid red');
			}
		if(response!='abc' && response!='ab' && response!='a' && response!='b' && response!='ac' && response!='bc' && response=='x')
			{
			//alert(response);
			$("#contact").fadeOut('fast');
			$("#response").html('Your message has been sent. Thanks for that!<br/><br/>');
			}

		}
		
	});

});










//reset charsleft after clearing form
$("#clear").click(function() {
$(".charsLeft").text(140)
});













// check op bestemmeling. zo ja, neem die over en zet in contentbox
 $("#lovetwit_content").focus(function() {
 if($("#lovetwit_content").val()==''){
	 var at= $("#at").val();
	 if(at!='@'){
	 var atlength=at.length;
	 $(".charsLeft").text(140-atlength-2);//lengte charleft aanpassen
	 $("#lovetwit_content").val(at+": ");//content textarea aanpassen
	 }
	 if(at==''){
	 var atlength=at.length;
	 $(".charsLeft").text(140-atlength);//lengte charleft aanpassen
	 $("#lovetwit_content").val(at+"");//content textarea aanpassen
	 }
	 
	 
	}
});








//----mousovers op laatste lovetwits

$('.twit').livequery('mouseover', function(){
$(this).css({ backgroundColor:"#fef9f9"}); 
});
$('.twit').livequery('mouseout', function(){ 
$(this).css({ backgroundColor:"fef9f9"}); 
});
$('.firsttwit').livequery('mouseover', function(){ 
$(this).css({ backgroundColor:"#fef9f9"}); 
});
$('.firsttwit').livequery('mouseout', function(){ 
$(this).css({ backgroundColor:"fef9f9"}); 
});









//how many characters left?
 $('textarea.twittext').maxlength({
    'feedback' : '.charsLeft',
    'useInput' : true
  });










//send_lovetwit
$("#send_lovetwit").livequery('click', function(){
var at=$("#at").val();
var twit=$("#lovetwit_content").val();
var tags=$("#tagfield").val();
var aspam=$("#aspam").val();
var key=$("#key").val();//alert(key);

$.ajax({
		type: "POST",
		dataType: "html",
		url: "ajax_tweet.php",
		data: {
		text:twit,
		at:at,
		tags:tags,
		aspam:aspam,
		key:key
		},
		success: function(response){
			//alert(response);
			if(response=='a'){// aspam error
				$("#aspam").css('border','1px solid red');
				}
			if(response=='b'){// text error
				$("#lovetwit_content").css('border','1px solid red');
				}
			if(response=='ab'){// aspam en text error
				$("#aspam").css('border','1px solid red');
				$("#lovetwit_content").css('border','1px solid red');
				}
				
			if(response=='x' && response !='a' && response!='b' && response!='ab' && response!='abx'){
			//$("#sendtwit").load('incs/makepic.php');
			$("#sendtwitimg").attr('src','grafix/hasbeen.png');
			$("#lovetwit_content").val('');
			$("#at").val('@');
			$("#tagfield").val('');
			$(".charsLeft").text(140);
			$(".statusresponse").html('<a href="http://www.twitter.com/lovetwits/status/'+response+'" target="_blank">Status</a>' );
			$("#at").focus();
			//$("#sendtwit").fadeOut('fast');
			$("#aspam").css('border','1px solid pink').val('');
			$("#lovetwit_content").css('border','1px solid pink');
			$("#latesttwits").load('ajax_latesttwits.php',function(){
			$(".firsttwit").hide().fadeIn('slow'); 
			});
			$("#smallcloud").load('incs/smallcloud.php',function(){
			$("#smallcloud").hide().fadeIn('slow'); 
			});
			}
			
			if(response==2){
			
			}
		}
	});

});
















//send_comment
$("#sendcomment").livequery('click', function(){
var name=$("#name").val();
var email=$("#email").val();
var url=$("#url").val();
var aspam=$("#aspam").val();
var key=$("#key").val();
var comment=$("#commentarea").val();
var twitid=$("#twitid").val();

$.ajax({
		type: "POST",
		dataType: "html",
		url: "ajax_comment.php",
		data: {
		name:name,
		email:email,
		url:url,
		aspam:aspam,
		key:key,
		comment:comment,
		twitid:twitid
		},
		success: function(response){
			//alert(response);
					
			if(response=='abc'){//error
				$("#aspam").css('border','1px solid red');
				$("#commentarea").css('border','1px solid red');
				$("#name").css('border','1px solid red');
				}
			if(response=='ab'){//error
				$("#aspam").css('border','1px solid red');
				$("#commentarea").css('border','1px solid red');
				$("#name").css('border','1px solid pink');
				}
			if(response=='a'){//error
				$("#aspam").css('border','1px solid red');
				$("#commentarea").css('border','1px solid pink');
				$("#name").css('border','1px solid pink');
				}
			if(response=='b'){//error
				$("#aspam").css('border','1px solid pink');
				$("#commentarea").css('border','1px solid red');
				$("#name").css('border','1px solid pink');
				}
			if(response=='ac'){//error
				$("#aspam").css('border','1px solid red');
				$("#commentarea").css('border','1px solid pink');
				$("#name").css('border','1px solid red');
				}
			if(response=='bc'){//error
				$("#aspam").css('border','1px solid pink');
				$("#commentarea").css('border','1px solid red');
				$("#name").css('border','1px solid red');
				}
	
			if(response!='abc' && response!='ab' && response!='a' && response!='b' && response!='ac' && response!='bc'){
			//alert(response);
			$("#form").fadeOut('fast');
			$("#commentimg").attr('src','grafix/commenthasbeen.png');
			$(".comments").hide().fadeIn('slow');
			$("#comcon").load('ajax_latestcomments.php',{id: twitid},function(){
			$(".latestcomment").hide().fadeIn('slow'); 
			});
			//
			
			
			//$("#sendtwit").load('incs/makepic.php');
			/*
			$("#lovetwit_content").val('');
			$("#at").val('@');
			$("#tagfield").val('');
			$(".charsLeft").text(140);
			$(".statusresponse").html('<a href="http://www.twitter.com/lovetwits/status/'+response+'" target="_blank">Status</a>' );
			$("#at").focus();
			//$("#sendtwit").fadeOut('fast');
			
			$("#latesttwits").load('ajax_latesttwits.php',function(){
			$(".firsttwit").hide().fadeIn('slow'); 
			});
			$("#smallcloud").load('incs/smallcloud.php',function(){
			$("#smallcloud").hide().fadeIn('slow'); 
			
			});*/
			}
			
			if(response==2){
			
			}
		}
	});

});








});//--end documentready
