$(document).ready(function() {
	if($.browser.msie && $.browser.version.substr(0) < "7"){window.location = "http://idontsupportie6.com";}

	// Animate post items
	$("li.post").hover(function() {
		$(this).find("div.info").fadeIn("slow");		
		$(this).animate( { borderLeftColor:'#a15fa0'}, 500);
	});
   	$("li.post").mouseleave(function() {
		$(this).find("div.info").fadeOut("slow");
		$(this).animate( { borderLeftColor:'#494949'}, 500);
   	});
   	
   	// Animate body links
   	$("#content h2 a, #content ul li a, #content ol li a, #footer a, #content dl a, #content p a, div.quote a, div.caption a").hover(function() {$(this).animate( {color:'#a15fa0',borderBottomColor:'#a15fa0'}, 200);});
   	$("#content h2 a, #content ul li a, #content ol li a, #content dl a, #content p a, div.quote a, div.caption a").mouseleave(function() {$(this).animate( {color:'#fff',borderBottomColor:'#fff'}, 200);});
   	$("#footer a").mouseleave(function() {$(this).animate( {color:'#777',borderBottomColor:'#777'}, 300);});
   	
   	
   	// Animate Main Navigation
   	$("#header").hover(function() {$("#nav").slideDown("fast");});
   	$("#header").mouseleave(function() {$("#nav").slideUp("fast");});
   	$("#nav a").hover(function() {
   		$(this).animate( {backgroundColor:'#502f50'}, 200);
   	});
	$("#nav a").mouseleave(function() {
		$(this).animate( {backgroundColor:'#a15fa0'}, 200);
	});
   	
   	// Animate Logo
   	$("#logo").hover(function() {
   		$(this).animate({top:"-=5px"},100).animate({top:"+=5px"},100).animate({top:"-=3px"},100).animate({top:"+=3px"},100);
   	});
  	$("#logo").click(function() {
  		$(this).animate({top:"-=200px"},100);
  	});
  	
	initPortfolio();
	initContactForms();
});

function initPortfolio() {
	if(document.body.id == "portfolio") {
		//jQuery('ul.screenshots').jcarousel();
		
		$("ul.screenshots").each(function(){
			if($("a",this).length > 1)$(this).jcarousel();
		});
		
		$("li.item").hover(function() {
			$(".jcarousel-next,.jcarousel-prev",this).animate({width:"53px"},300);
	   	});
		$("li.item").mouseleave(function() {
			$(".jcarousel-next,.jcarousel-prev",this).animate({width:"0px"},300);
	   	});
		$("ul.screenshots li a").fancybox();
	}
}

function initContactForms() {
	if(document.body.id == "contact") {
		// Uniform Selects
	  	$("select").uniform();

		$("input[type=text]").focus(function(){
			if($(this).val() == $(this).get(0).defaultValue) $(this).val("");
			if($('p.error').is(':hidden'))$('p.error').fadeOut("fast");
		});
		$("input[type=text]").blur(function(){
			if($(this).val() == "") $(this).val($(this).get(0).defaultValue);
		});
		
		// Text Areas
		$("#form-work textarea").focus(function(){
			if($(this).val() == "A little about the project...") $(this).val("");
			if($('p.error').is(':hidden'))$('p.error').fadeOut("fast");
		});
		$("#form-hello textarea").focus(function(){
			if($('p.error').is(':hidden'))$('p.error').fadeOut("fast");
		});
		$("#form-work textarea").blur(function(){
			if($(this).val() == "") $(this).val("A little about the project...");
		});
		
  		// Contact Form Switch
	 	$("#form-switch select").change(function() {
			if($(this).val() == "Say Hello") {
				$("#form-work").hide();
				$("#form-hello").slideDown("slow");
			} else {
				$("#form-hello").hide();
				$("#form-work").slideDown("slow");			
			}
	  	});  
  	
	  	// Setup Hello Form
	  	$('#form-hello').ajaxForm(function(data) {
	        if (data==1){
	        	$("#form-hello-send-success").fadeIn("fast");
				$("#form-hello-send").animate({left:"+=364px"},500);
	            $('#form-hello').resetForm();
	        }
	        else if (data==2){
	            $('#form-hello-error-server').fadeIn("slow");
	            $("#form-hello-send button").animate({left:"+=5px"},100).animate({left:"-=5px"},100).animate({left:"+=5px"},100).animate({left:"-=5px"},100);
	        }
	        else if (data==3)
	        {
	            $('#form-hello-error-email').fadeIn("slow");
	            $("#form-hello-send button").animate({left:"+=5px"},100).animate({left:"-=5px"},100).animate({left:"+=5px"},100).animate({left:"-=5px"},100);
	        }
	    });
    
    
	    // Setup Work Form
	  	$('#form-work').ajaxForm(function(data) {
	        if (data==1){
	        	$("#form-work-send-success").fadeIn("fast");
				$("#form-work-send").animate({left:"+=364px"},500);
	            $('#form-work').resetForm();
	        }
	        else if (data==2){
	            $('#form-work-error-server').fadeIn("slow");
	            $("#form-work-send button").animate({left:"+=5px"},100).animate({left:"-=5px"},100).animate({left:"+=5px"},100).animate({left:"-=5px"},100);
	        }
	        else if (data==3)
	        {
	            $('#form-work-error-email').fadeIn("slow");
	            $("#form-work-send button").animate({left:"+=5px"},100).animate({left:"-=5px"},100).animate({left:"+=5px"},100).animate({left:"-=5px"},100);
	        }
	    });
	}	
}