$(document).ready(function() {
  
  	$('a.button1').mousedown( function() {			
		$(this).css('background','url("/img/button1-hov.png") no-repeat center');  
 	});
	$('a.button1').mouseup( function() {			
		$(this).css('background','url("/img/button1.png") no-repeat center');  
 	});
	$('a.button1').mouseout( function() {			
		$(this).css('background','url("/img/button1.png") no-repeat center');  
 	});
	
	$('a.button2').mousedown( function() {			
		$(this).css('background','url("/img/button2-hov.png") no-repeat center');  
 	});
	$('a.button2').mouseup( function() {			
		$(this).css('background','url("/img/button2.png") no-repeat center');  
 	});
	$('a.button2').mouseout( function() {			
		$(this).css('background','url("/img/button2.png") no-repeat center');  
 	});
	
	
	$('a.button3').mousedown( function() {			
		$(this).css('background','url("/img/button3-hov.png") no-repeat center');  
 	});
	$('a.button3').mouseup( function() {			
		$(this).css('background','url("/img/button3.png") no-repeat center');  
 	});
	$('a.button3').mouseout( function() {			
		$(this).css('background','url("/img/button3.png") no-repeat center');  
 	});
	
	$('a.button3').click( function() {			
		contactForm();
 	});
	
	$('.homeSection a, a.contactButton').attr('href','javascript:void(0)');
	$('.homeSection a, a.contactButton').click( function(){			
		var tmp = $(this).attr('data');
		
		var tmp3 = $(document).scrollTop();
		$('#fix').css('height','1400px');
		$('.pageItem').css('display','none');	
		window.location.hash = tmp;
		$(document).scrollTop(tmp3);
		$('#'+tmp).css('display','block');
		$(document).scrollTop(tmp3);
		$('#fix').css('height','0px');
		fixBump(tmp3);
	});
	
	$('.menu1 a').attr('href','javascript:void(0)');
	$('a.button3').attr('href','javascript:void(0)');	
	$('.menu1 a').click( function(){
		$('.menu1 a').removeClass('active');		
		var tmp2 = this;		
		var tmp = $(this).attr('data');
		var th = 20 + (36* (tmp-1));	
		$('.ribbon1').animate({top:th+'px'}, 180, function() { $(tmp2).addClass('active'); });
		$('.portfolio .right').css('min-height','1500px');			
		$('.portItem').hide();
		$('#port-'+tmp).fadeIn(400);
		$('.portfolio .right').css('min-height','450px');	
	});  
	
	rdy();
	
	$('.formRow input, .formRow textarea').each( function() {		
		$(this).attr('data-start',$(this).val() );
		
		$(this).click( function() {
			if( $(this).val()== $(this).attr('data-start'))
				$(this).val('');
		});
	});
	
	$('input, textarea').blur( function() {
		
		$(this).css('color','#000');
		if( $(this).val()=='' )
			$(this).val( $(this).attr('data-start') );
	});
	
	$('input, textarea').focus( function() {
		
		$(this).css('color','#151515');
	});
	
	
	var username='masswerks'; // set user name
var format='json'; // set format, you really don't have an option on this one
var url='http://api.twitter.com/1/statuses/user_timeline/'+username+'.'+format+'?callback=?'; // make the url

	$.getJSON(url,function(tweet){ // get the tweets
		$("#last-tweet").html(tweet[0].text); // get the first tweet in the response and place it inside the div.
		var ttmp = tweet[0].created_at;
		ttmp = ttmp.substr(0,10);
		$("#tweet-date").html(ttmp);
	});
  
});


function fixBump(scrollPos)
{
	var tmp2 = $(window).height();
	var tmp3 = $('#site').height();
	$('#site').css('min-height',(tmp2+230) +'px');
	$(document).scrollTop(scrollPos); scrollerUp();
}

function scrollerUp() { setTimeout('doScrollerUp()',5); }
function doScrollerUp()
{
	//$(document).scrollTop(430);
	$('html').animate({scrollTop: 230}, 150);	
	$('body').animate({scrollTop: 230}, 150);	
}

function rdy()
{
	var hash = window.location.hash.replace("#", "");
	if (hash) {
		$('#'+hash).show();
		$('html').animate({scrollTop: 230}, 150);	
		$('body').animate({scrollTop: 230}, 150);	
	}
}

function contactForm()
{
	var fail = false;
	
	
	$('.formRow input, .formRow textarea').each( function() {
			if( $(this).val()== $(this).attr('data-start'))
				$(this).val('');
	});
	
	
	var tmp = $('#f1i').val();
	if( tmp.length <3)
	{
		$('#f1e').html('Required'); fail = true;
	}
	else { $('#f1e').html(''); }
	
	var tmp = $('#f2i').val();
	if( tmp.length <3)
	{
		$('#f2e').html('Required'); fail = true;
	}
	else { $('#f2e').html(''); }
	
	var tmp = $('#f3i').val();
	if( tmp.length <3)
	{
		$('#f3e').html('Required'); fail = true;
	}
	else { $('#f3e').html(''); }
	
	var tmp = $('#f4i').val();
	if( tmp.length <3)
	{
		$('#f4e').html('Required'); fail = true;
	}
	else { $('#f4e').html(''); }
	
	var tmp = $('#f8i').val();
	if( tmp.length <20)
	{
		$('#f8e').html('Required'); fail = true;
	}
	else { $('#f4e').html(''); }
	
	
	if( ! fail)
	{
		 $.ajax({
		  url: "email.php",
		  type: "POST",
		  data: {first : $('#f1i').val(), last: $('#f2i').val(), email: $('#f3i').val(), company: $('#f4i').val(), phone: $('#f5i').val(), type: $('#f6i').val(), budget: $('#f7i').val(), about: $('#f8i').val(), },
		  dataType: "html"
		});

		$('#cform').html('Thank you for your message. We will be in touch soon.');	
	}


	
}
