$(document).ready(function() {
	//$("#twitter_status").load("http://patrickarlt.com/home/TwitterStatus", null, null);

		//$("#flickr_photos").load("http://patrickarlt.com/home/GetFlickr");

	//$("#blog_feed").load("http://patrickarlt.com/home/BlogFeedItems");

	//Setup Contact form AJAX and Validation
	var AJAXoptions = { 
			target: 'span.status',
			success: function() { 
				$('span.status').html("Thank you for your feedback. I'll get back to your as soon as possible.	").removeClass('Error').addClass("Success"); 
			}
	};
	
	//Validate the Contact Form
	$('#Form_ContactForm').validate({
		errorClass:"message",
		errorElement: "span",
		submitHandler: function() {
			$('#Form_ContactForm').ajaxSubmit(AJAXoptions).resetForm();
			return false;
		},
		rules: {
			Email: {
			   required: true,
			   email: true
			 },
			 Name: {
				required: true
			 },
			 Subject: {
				required: true
			 }
		},
		messages: {
			Email: {
			   required: "Your email is required",
			   email: "A valid email is required"
			 },
			 Name: {
				required: "Your name is required"
			 },
			 Subject: {
				required: "Please enter a subject"
			 }
		}
	}); 
	
	$.localScroll({
		duration:'4000',
		axis:'y',
		queue:true //one axis at a time
	});
	
	//Some Common Greybox Functions
	$('a.greybox-close').click(function() {
		$('.greybox-content').empty();
		$('#greybox').hide();
		$('#mask').hide();
		return false;
	});

	$('#mask').click(function() {
		$('.greybox-content').empty();
		$('#greybox').hide();
		$('#mask').hide();
		return false;
	});

	//Flickr Greyboxes
	$("a.flickr_image").click(function() {
			
			var offTop = $(window).scrollTop();
			var offTopPlus = (offTop + 20);

		$(window).scroll(function(){
			var Top = $(window).scrollTop();
			$("#mask").css('top', (Top + "px"));
		});
		var original_photo = '<img src="' + $(this).attr('href') +'" alt="" id="open_flickr_image" />';
		$('.greybox-content').append(original_photo);
		$('#greybox').show();
		$('#mask').show();
			
			$('.greybox-border').css('top', (offTopPlus + "px"));
		$('#mask').css('top', (offTop + "px"));

			return false;
	});
	
	//Portfolio Greybox
	$(".portfolio_thumbs a").click(function(){
		var offTop = $(window).scrollTop();
			var offTopPlus = (offTop + 20);

		$(window).scroll(function(){
			var Top = $(window).scrollTop();
			$("#mask").css('top', (Top + "px"));
		});
		$(".greybox-content").load($(this).attr('rel'), null, function(){
			$('#portfolio_slideshow').cycle({ 
				fx:     'scrollDown', 
				timeout: 0, 
				speed: 1000,
				next:   'a#next',
					prev:   'a#prev'
			 });
			 
			 $('#portfolio_desc ul li a').click(function(){
				$('#portfolio_desc ul li a.active').removeClass('active');		 	
				var indexNum = $(this).parent('li').index();
				$('#portfolio_slideshow').cycle(indexNum);
				$(this).addClass('active');
				return false;
			 });
			 
		});
		$('.greybox-border').css('top', (offTopPlus + "px"));
		$('#mask').css('top', (offTop + "px"));
		
		$('#greybox').show();
		$('#mask').show();
		
		return false;
	});
	
});