$(document).ready(function(){

	////////////////////////////////
	//nav
	
	$('.mainnav li a')
	.css( {backgroundPosition: "0px 0px"} )
	.mouseover(function(){
		if ($(this).hasClass('active')){
			//do nothing
		} else {
			$(this).stop().animate({backgroundPosition:"(0px -15px)"}, {duration:150, easing: "easeOutQuad"})
		}
		
	})
	.mouseout(function(){
		if ($(this).hasClass('active')){
			$(this).stop().animate({backgroundPosition:"(0px -30px)"}, {duration:150, easing: "easeOutQuad"})
		} else {
			$(this).stop().animate({backgroundPosition:"(0px 0px)"}, { duration:150, easing: "easeOutQuad"})
		}
	})
	
	$('.active').animate({backgroundPosition:"(0px -30px)"}, {duration:400, easing: "easeOutQuad"})
	
	$('.socialnav li a')
	.css( {backgroundPosition: "0px 0px"} )
	.mouseover(function(){
		if ($(this).hasClass('active')){
			//do nothing
		} else {
			$(this).stop().animate({backgroundPosition:"(0px -18px)"}, {duration:150, easing: "easeOutQuad"})
		}
		
	})
	.mouseout(function(){
		if ($(this).hasClass('active')){
			$(this).stop().animate({backgroundPosition:"(0px -30px)"}, {duration:150, easing: "easeOutQuad"})
		} else {
			$(this).stop().animate({backgroundPosition:"(0px 0px)"}, { duration:150, easing: "easeOutQuad"})
		}
	})
	
	////////////////////////////////
	//feature animation
	
	$('.feature_details')
	.mouseenter(function() {
	  $('.feature_details').stop(true,true).animate({ paddingRight: 120 }, 300, "easeOutExpo");
	})
	.mouseleave(function() {
	  $('.feature_details').stop(true,true).animate({ paddingRight: 80 }, 300, "easeOutExpo");
	})
	
	////////////////////////////////
	//project animation
	
	$('.thumb')
	.css( {backgroundPosition: "0px 0px"} )
	.mouseover(function(){
		$(this).stop().animate({backgroundPosition:"(0px -115px)"}, {duration:400, easing: "easeOutExpo"})
	})
	.mouseout(function(){
		$(this).stop().animate({backgroundPosition:"(0px 0px)"}, { duration:400, easing: "easeOutExpo"})
	})
	
	
	
	////////////////////////////////
	//sticky menu
	
	var position = $("#icons").offset();
	
	if(position){
		var positionTop = position.top;
	}
	
	
	$(window).scroll(function () { 
		
		var scrollTop = $(this).scrollTop();
		
		if(scrollTop >= positionTop){
			//alert("attach menu");
			$("#icons").css("position", "fixed");
			$("#icons").css("top", "2px");
		} else {
			$("#icons").css("position", "relative");
			$("#icons").css("top", "-42px");
		}
		
	});
	
	////////////////////////////////
	//tooltips
	if($('#icons a').length){
		$('#icons a').tooltip({ 
		    track: true,
		    delay: 350,
		    showURL: false,
		    extraClass: "right",
			positionLeft: true,
			fade: 150
		});
	}
	
	
	////////////////////////////////
	//hide show info on project page
	
	$('#info').click(function() {
	  	$(".project_info").slideToggle("400", "easeOutExpo");
		return false;
	});
	
	////////////////////////////////
	//newsletter
	
	$('input#name').focus(function () { 
		if($(this).val() == 'Your Name'){
			$(this).val('');
		}
    });
	$('input#name').blur(function () { 
		if($(this).val() == ''){
			$(this).val('Your Name');
		}
    });

	$('input#kydtjt-kydtjt').focus(function () { 
		if($(this).val() == 'Email Address'){
			$(this).val('');
		}
    });
	$('input#kydtjt-kydtjt').blur(function () { 
		if($(this).val() == ''){
			$(this).val('Email Address');
		}
    });

	////////////////////////////////
	//contact
	
	$('input#fullname').focus(function () { 
		if($(this).val() == 'Your Name'){
			$(this).val('');
			$(this).css('background-color', '#cccccc');
			$(this).css('color', '#ffffff');
		}
    });
	$('input#fullname').blur(function () { 
		if($(this).val() == ''){
			$(this).val('Your Name');
			$(this).css('background-color', '#ededed');
			$(this).css('color', '#999999');
		} else {
			$(this).css('background-color', '#ededed');
			$(this).css('color', '#999999');
		}
    });

	$('input#email').focus(function () { 
		if($(this).val() == 'Email Address'){
			$(this).val('');
			$(this).css('background-color', '#cccccc');
			$(this).css('color', '#ffffff');
		}
    });
	$('input#email').blur(function () { 
		if($(this).val() == ''){
			$(this).val('Email Address');
			$(this).css('background-color', '#ededed');
			$(this).css('color', '#999999');
		} else {
			$(this).css('background-color', '#ededed');
			$(this).css('color', '#999999');
		}
    });

	$('input#phone').focus(function () { 
		if($(this).val() == 'Phone Number'){
			$(this).val('');
			$(this).css('background-color', '#cccccc');
			$(this).css('color', '#ffffff');
		}
    });
	$('input#phone').blur(function () { 
		if($(this).val() == ''){
			$(this).val('Phone Number');
			$(this).css('background-color', '#ededed');
			$(this).css('color', '#999999');
		} else {
			$(this).css('background-color', '#ededed');
			$(this).css('color', '#999999');
		}
    });

	$('textarea#message').focus(function () { 
		if($(this).val() == 'Your Message'){
			$(this).val('');
			$(this).css('background-color', '#cccccc');
			$(this).css('color', '#ffffff');
		}
    });
	$('textarea#message').blur(function () { 
		if($(this).val() == ''){
			$(this).val('Your Message');
			$(this).css('background-color', '#ededed');
			$(this).css('color', '#999999');
		} else {
			$(this).css('background-color', '#ededed');
			$(this).css('color', '#999999');
		}
    });
	
	////////////////////////////////
	//about hover
	
	$('#about_1, #about_2, #about_3')
	.css( {backgroundPosition: "0px -690px"} )
	.mouseover(function(){
		if ($(this).hasClass('aboutActive')){
			//do nothing
		} else {
			$(this).stop().animate({backgroundPosition:"(0px -345px)"}, {duration:400, easing: "easeOutExpo"})
		}
	})
	.mouseout(function(){
		if ($(this).hasClass('aboutActive')){
			//do nothing
		} else {
			$(this).stop().animate({backgroundPosition:"(0px -690px)"}, { duration:400, easing: "easeOutExpo"})
		}
	})
	.click(function(){
		$('#about_1, #about_2, #about_3').removeClass('aboutActive');
		$('#about_1, #about_2, #about_3').stop().animate({backgroundPosition:"(0px -690px)"}, { duration:1, easing: "easeOutExpo"})
		$(this).stop().animate({backgroundPosition:"(0px -345px)"}, { duration:700, easing: "easeOutExpo"})
		$(this).addClass('aboutActive');
		window.location.hash = "#"+$(this).attr('name');
		
		$('#about_1 img, #about_2 img, #about_3 img').fadeOut('fast');
		$('.aboutActive img').fadeIn("fast");
		
		if($(this).attr('id')=='about_1'){
			$('#about_2_content').hide();
			$('#about_3_content').hide();
			$('#about_1_content').fadeIn('slow', function() {
	        	// Animation complete
	      	});
		} else if ($(this).attr('id')=='about_2'){
			$('#about_1_content').hide();
			$('#about_3_content').hide();
			$('#about_2_content').fadeIn('slow', function() {
	        	// Animation complete
	      	});
		} else {
			$('#about_1_content').hide();
			$('#about_2_content').hide();
			$('#about_3_content').fadeIn('slow', function() {
	        	// Animation complete
	      	});
		}
		
	})
	
	$('.aboutActive').stop().animate({backgroundPosition:"(0px -345px)"}, {duration:1, easing: "easeOutExpo"})
	$('.aboutActive img').fadeIn('fast');
	
	////////////////////////////////
	//colorbox
	
	$("a[rel='footerFlickr']").colorbox({transition:"none", width:"85%", height:"85%", opacity:1, maxWidth:"850px"});
	$("a[rel='studio']").colorbox({transition:"none", width:"85%", height:"85%", opacity:1, maxWidth:"850px"});
	
	////////////////////////////////
	//newsletter
		
	$("#subForm input:image").click(function() {	

		// First, disable the form from submitting
		$('form#subForm').submit(function() { return false; });

		// Grab form action
		formAction = $("form#subForm").attr("action");

		// Hacking together id for email field
		// Replace the xxxxx below:
		// If your form action were http://mysiteaddress.createsend.com/t/r/s/abcde/, then you'd enter "abcde" below
		emailId = "kydtjt";
		emailId = emailId.replace("/", "");
		emailId = emailId + "-" + emailId;

		// Validate email address with regex
		if (!checkEmail(emailId)) {
			alert("Please enter a valid email address");
			return;
		} else {
			$('#subForm').hide();
			$('#sub_load').fadeIn('fast');
		}

		// Serialize form values to be submitted with POST
		var str = $("form#subForm").serialize();

		// Add form action to end of serialized data
		final = str + "&action=" + formAction;

		// Submit the form via ajax
		$.ajax({
			url: "_includes/proxy.php",
			type: "POST",
			data: final,
			success: function(html){
				$('#sub_load').hide();
				$('#sub_success').fadeIn('fast');
			}
		});
	});
		
	function checkEmail(email) {	
		var pattern = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		var emailVal = $("#" + email).val();
		return pattern.test(emailVal);
	}
	
	//name
   	$('#btidj-btidj').focus(function () { 
		if($(this).val() == 'Newsletter Subscribe'){
			$(this).val('');
		}
    });
	$('#btidj-btidj').blur(function () { 
		if($(this).val() == ''){
			$(this).val('Newsletter Subscribe');
		}
    });
	
});
