//Search Field
function searchInput(text){
	$(document).ready(function(){
		$("#input_search").val(text).css({"color":"#eee"});
			$("#input_search").one("focus",function(){
				$(this).val("").css({"color":"#ffff"});
			});
		$("#searchform label").hide();
	});
};

jQuery.fn.WindowScrollEffect = function(){
	var $window = $(window);
	
	return this.each(function() {
		
		function change_opacity(){
			var o = ($('.page').offset().top / $('h1').offset().top);
			$("h1").fadeTo("fast", o-0.27);
	   		$("h2").fadeTo("fast", o-0.27);
		}
   
		$window.scroll(function() {
	   		if ($window.scrollTop() > 0) {
	   			change_opacity();
	   		}
		});
	});
};

$(document).ready(function(){
	
	//$("#about").WindowScrollEffect();
	$("#about h1").css("opacity", 0.02);
	$("#about h2").css("opacity", 0.05);
	
	searchInput('Search');
	
	var fm = new FeedMenu();
	fm.write('#feed_menu');
	
	//Hide Trackbacks
	$("ol.trackback").hide();
	$("a.show_trackbacks").click( function (){
		$("ol.trackback").slideToggle('fast');
		return false;
	});
	
	$(".nav .next").click(function(){
		project = $(this).parents(".project").eq(0);
		currentImg = project.find(".photos li.current");
		nextImg = currentImg.next();
		firstImg = project.find(".photos li:first");
		currentImg.removeClass("current");
		if (nextImg.is("li")) nextImg.addClass("current");
		else firstImg.addClass("current");
		return false;
	});
	$(".nav .prev").click(function(){
		project = $(this).parents().filter(".project").eq(0);
		currentImg = project.find(".photos li.current");
		prevImg = currentImg.prev();
		lastImg = project.find(".photos li:last");
		currentImg.removeClass("current");
		if (prevImg.is("li")) prevImg.addClass("current");
		else lastImg.addClass("current");
		return false;
	});
	
	// 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
	$('#form_paypal').submit(function()
	{
		// check if there is an amount entered
		if ($('#input_amount').val() > null)
		{
			// is the amount equal to or higher than the minimum_value?
			if ($('#input_amount').val() < minimum_value)
			{
				// need more amount
				// hide messages, show more amount error
				$('#msg_noamount').hide();
				$('#msg_moreamount').fadeIn();
				return false; // prevent the form from submitting
			}
			else
			{
				// amount is more than minimum_value
				// hide messages, show activity
				$('#msg_moreamount').hide();
				$('#msg_noamount').hide();
				$('#msg_activity').fadeIn();
				return true; // submit the form
			}
		}
		else
		{
			// no amount entered at all
			// hide messages, show no amount error
			$('#msg_moreamount').hide();
			$('#msg_noamount').fadeIn();
			return false; // prevent the form from submitting
		}
	});

});
