// <![CDATA[

/*	DOM-READY FUNCTION
-------------------------------------------------------------- */
$(function() {
	
	//alert("hold on a sec, Jeremy is working on something. Be back in 5min.")
	
	//Adds a class to the body based on the time. Removed this responsibility from PHP as cached pages were not getting the hour class always.
	var now = new Date();
	var hour = now.getHours();
	$('body').addClass('jhour' + hour)
	
	
	//Add Facebox class to linked images
	$('.entry-content a:has(img)').attr('rel', 'facebox');
	
	
	$('a:not([rel=facebox],[href^=mailto])').click(function(){
		//This could have been done in the selectors I guess.
		var destination = $(this).attr('href');
		if ((destination == "#") || (destination == "#comments")) {
			//return false;
		} 
		else {
			$('#wrapper-outer').animate({ opacity: 0 }, 500, 'swing', function(){location.href = destination})
			return false;
		}
	});
	
	
	//Jump back link
	$('.jump-back').click(function(){
		history.go(-1);
		return false;
	})
	
	//Lazy Loader
	//$('.entry-content img').lazyload({ threshold : 200, effect : "fadeIn" });
	
	//Insert the birdy
	$('div.p1.post').append('<img id="birdy" src="http://static.theangulos.com/layout/img/layout/bird.png" />').append('<img id="funny-tweet" style="display:none" src="http://static.theangulos.com/layout/img/layout/funny-tweet.png" />');
	$('#birdy').hover(function() {
            $('#funny-tweet').fadeIn('fast')
        }, function() {
            $('#funny-tweet').fadeOut('fast')
	});
	
	//Activate Facebox
	$('a[rel*=facebox]').facebox();
	
	// --- CLOUD SET 1 ---
	//STARTING POINT (Number between 400 and 1 PLUS 400. So really 401 to 801)
	var startingPoint = Math.floor((200-1)*Math.random()) + 100;
		//Let's make that a string.
		var strStartingPoint = startingPoint.toString() + 'px';
	
	// --- CLOUD SET 2 ---
	//STARTING POINT (Add something between 30 and 110.)
	var startingPointOffset2 = startingPoint + (Math.floor((200-1)*Math.random()) + 100);
		//Let's make that a string.
		var strEndPoint2 = (startingPointOffset2 - 30).toString() + 'px';
		var strEndPoint2end = (startingPointOffset2 - 60).toString() + 'px';
		var strStartingPoint2 = startingPointOffset2.toString() + 'px';

	// --- CLOUD SET 1 ---
	$('#c1').css({marginLeft: startingPoint})

	// --- CLOUD SET 2 ---
	function clouds() {
	$('#c2').css({marginLeft: strStartingPoint2, opacity: 0})
		//.animate({ marginLeft: strEndPoint2}, 1000, "linear", function(){clouds();})
		.animate({ marginLeft: strEndPoint2, opacity: 1}, 5000, "linear")
		.animate({ marginLeft: strEndPoint2end, opacity: 0}, 5000, "linear")
	}
	function cloudsIE7() {
	$('#c2').css({marginLeft: strStartingPoint2})
		//.animate({ marginLeft: strEndPoint2}, 1000, "linear", function(){clouds();})
		.animate({ marginLeft: strEndPoint2}, 5000, "linear")
		.animate({ marginLeft: strEndPoint2end}, 5000, "linear")
	}
	
	//Initial launch of the clouds - Launch these for Grade A Browsers
	if ($('body').hasClass('ie6')) {
		$('#c2').css({display: 'none'});
	} else if ($('body').hasClass('ie7')) {
		cloudsIE7();
	} else {
		clouds();
	}
	
    $('#josh').hover(function() {
            $('#josh-t').stop().animate({opacity: 1, left: '-200px'}, 200)
        }, function() {
            $('#josh-t').stop().animate({opacity: 1}, 900).animate({opacity: 0, left: '-203px'}, 200, function(){$(this).css({left: '-198px'});})
	});

    $('#casey').hover(function() {
            $('#casey-t').stop().animate({opacity: 1, top: '-30px'}, 200)
        }, function() {
            $('#casey-t').stop().animate({opacity: 1}, 900).animate({opacity: 0, top: '-33px'}, 200, function(){$(this).css({top: '-28px'});})
	});
	
	$('#caleb').hover(function() {
            $('#funny-caleb').fadeIn('fast')
        }, function() {
            $('#funny-caleb').fadeOut('fast')
	});
	
	//Email Subscribe input
	$("#email-sub-input").focus(function () {
     if ($(this).attr('value') == 'posts by email') {
      $(this).attr('value', '');
     }
  });
  $("#email-sub-input").blur(function () {
    if ($(this).attr('value') == '') {
      $(this).attr('value', 'posts by email');
    }
  });

	//Elastic Textarea
	$('div.form-textarea #comment').growfield(); 
	
	//SUPER SIMPLE FORM VALIDATION (only checks that inputs have something in them).

	//Hijack the Form Submission
	$("#commentform").submit(function() {
		//Assume everything is good and valid at first
		var valid = true;
		//get the inputs and text areas with the .required class and loop through them. First, setting all the borders back.
		$("input.required,textarea.required").css('border', '1px solid #999').each(function (i) {
			//if the value is left blank...
			if ($(this).val() == "") {
				//highlight the input...
				$(this).css('border', '2px solid red');
				//and tell the script that something is not valid.
				valid = false;
			} 
		});
		//This is the same as "return = true" which will submit the form.
		return valid;
	});
		


});


// ]]>