$(document).ready(function(){
	
	Cufon.replace('.block h2, #about h2, footer h2');
	
	init_swap_text_boxes();
	
	$('.carousel').anythingSlider({
	   easing: "swing",                // Anything other than "linear" or "swing" requires the easing plugin
	   autoPlay: false,                // This turns off the entire FUNCTIONALITY, not just if it starts running or not
	   startStopped: false,            // If autoPlay is on, this can force it to start stopped
	   delay: 3000,                    // How long between slide transitions in AutoPlay mode
	   animationTime: 600,             // How long the slide transition takes
	   hashTags: false,                 // Should links change the hashtag in the URL?
	   buildNavigation: false,          // If true, builds and list of anchor links to link to each slide
	   pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
	   startText: "Start",             // Start text
	   stopText: "Stop",               // Stop text
	   navigationFormatter: null       // Advanced Use: details below
	});
	
	/* PROJECT IMAGES */
	$('#project-overview .project img:nth-child(3)').mouseenter(function(){
		$(this).fadeOut();
	});
	
	$('#project-overview .project').mouseleave(function(){
		$(this).find('img:nth-child(3)').fadeIn();
	});
	
	/* FAN ART */
	$('.block a.fanart').mouseenter(function(){
		$(this).find('.bw').fadeOut();
	});
	
	$('.block a.fanart').mouseleave(function(){
		$(this).find('.bw').fadeIn();
	});
	
	$('.block a.fanart').click(function(){
		$(this).find('.bw').fadeIn();
	});
	
	$(".block a.fanart").fancybox({});

	
	/* VALIDATION */
	$("#contactform").validate({
		rules: {
			name: "required",
			email: {
				required: true,
				email: true
			},
			message: {
				required: true
			}
		},
		messages: {
			name: "Empty field",
			email: "Invalid e-mailaddress",
			message: "Empty field"
		},
		submitHandler: function(form) {
			
			
			/* CALLBACK */
			$("form .submit").click(function(){  	
					
				var dataString = 'name='+ $("input#name").val() + '&email=' + $('input#email').val() + '&message=' + $('#message').val();
				
				$.ajax({  
					type: "POST",  
				  	url: "sendcallback.php",  
				  	data: dataString,  
				  	success: function(){  
						$('.row').fadeOut('1000').delay('1000');
						$('.thanks').fadeIn('1000');
				  	}
		  		});
		  		
		  		return false;
			  		
			});
			
		  
		}
	});
	
	/* SCROLLER */
	$('a.about-btn').click(function(){
		$.scrollTo($('#about'),800);
	});
	
	$('a.inner-footer-btn').click(function(){
		$.scrollTo($('#inner-footer'),800);
	});
	
	$('a.project-overview-btn').click(function(){
		$.scrollTo($('#project-viewer'),800);
	});
	
	$('a.top').click(function(){
		$.scrollTo($('#top'),800);
	});
	
	/* PROJECTS */
	$('#project-viewer .project').hide();
	
	$('#project-overview .project').click(function(){
		var childNumber = $(this).index() + 1;
		$('#project-viewer .project').slideUp().delay(500);
		$('#project-viewer .project:nth-child('+childNumber+')').slideDown();
					

		$.scrollTo($('#project-viewer'),800);
	});
	
	$('#project-viewer .project a.close').click(function(){
		$(this).parent().parent().slideUp();
	});
});

var swap_text_boxes = [];
			
function init_swap_text_boxes(){
  //Store the default value for each box
  $('input[type=text][value].swaptextbox').each(function() {
    swap_text_boxes[$(this).attr('id')] = $(this).attr('value');
  });
  //Add focus and blur events to set or clear the value
  $('input[type=text][value].swaptextbox').bind('focus', function() {
    if($(this).val() == swap_text_boxes[$(this).attr('id')]) {
      $(this).val('');
    }
  });
  $('input[type=text][value].swaptextbox').bind('blur', function() {
    if($(this).val() == '') {
      $(this).val(swap_text_boxes[$(this).attr('id')]);
    }
  });
}
