$(document).ready(function() {
	
	$('a.newtab').click(function(e)
	{
		e.preventDefault();window.open($(this).attr('href'));
	});

	/* Portfolio */
	$("#portfolio-scroller").carouFredSel({
		padding: 5,
		items: {
			visible: 1,
			width:"variable",
			height:"variable"
		},
		scroll: {
			easing: "easeInOutExpo",
			duration: 1500,
			onBefore: function( oldItems, newItems, newSizes, duration ) {
				$(newItems).find(".slideshow-images").cycle({
					pager: $(newItems).find(".pager")
				});
			},
			onAfter: function( oldItems, newItems, newSizes, duration ) {
				$(oldItems).find(".slideshow-images").cycle("destroy");
			}
		},
		auto: false,
		prev: "#portfolio-controls > #port-left",
		next: "#portfolio-controls > #port-right"
	});

	$(".slideshow-images:first").cycle({
		pager: $.find(".pager:first")
	});
	/* End of Portfolio */

	/* Navigation */

	$(".menu-item").bind("click", function(e)
	{
		if($("#"+$(this).attr("rel")+"-a").length>0)
		{
			e.preventDefault();
			$.scrollTo("#"+$(this).attr("rel")+"-a", 1500, {easing:"easeInOutExpo"});
		}
		else
		{
			window.location = "/#"+$(this).attr("rel")+"-a";
		}
	});

	/* End of Navigation */

	/* Blog */
	$("#blog-scroller").carouFredSel({
		padding: 0,
		items: 1,
		scroll: {
			easing: "easeInOutExpo",
			duration: 1500,
		},
		auto: false,
		prev: "#blog-controls > #left",
		next: "#blog-controls > #right"
	});
	/* End of Blog */

	/* Footer */
	$('.lastfm-thumb').each(function()
	{
		$(this).qtip({
			style: {
				padding: 2,
				name: 'dark'
			},
			position: {
				corner: {
					target: 'topRight',
					tooltip: 'bottomLeft'
				}
			},
			content: {
				text:  "<p class=\"caption\"><img style=\"width:220px;\" src=\""+$(this).attr("rel")+"\" /><br />"+$(this).attr("alt")+"</p>",
			},
		});
	});
	
	$("input, textarea").each(function(){
		if(!$(this).data('default'))
		{
			$(this).data('default', $(this).val());
		}
	});

	
	$("input, textarea").bind('click, focus', function(){
	
		if($(this).data('default')==$(this).val())
		{
			$(this).val('');
		}
		
	});
	
	$("input, textarea").bind('blur', function(){
		
		if($(this).data('default')!=$(this).val()&&$(this).val()=='')
		{
			$(this).val($(this).data('default'));
		}
				
	});
		
	$('#contact-form #contact-form-message #contact-form-send').bind('click', function(){
	
		var error = "";
		
	
		if($("#contact-form #name").val() === $("#contact-form #name").data('default'))		
		{
			
			error = error + "Your Name\r\n";
		}
		
		if($("#contact-form #email").val() === $("#contact-form #email").data('default'))		
		{
			error = error + "Your Email\r\n";
		}
		
		if($("#contact-form #message").val() === $("#contact-form #message").data('default'))		
		{
			error = error + "Your Message\r\n";
		}
		
		if(error.length>0)
		{
			error = "Please enter the following:\r\n\r\n"+error;
			alert(error);
		}
		else
		{
			if($("#contact-form-send").data('sent')!==true)
			{
				$.ajax({
				   type: "POST",
				   url: "/ajax/contact",
				   data: $("input, textarea").serialize(),
				   success: function(msg){
				     $("#contact-form-send").html("Message sent! Thanks for getting in touch.");
					 $("#contact-form-send").data('sent', true);
				   }
				 });
			}
			
			
		}
		
	});
	
	$('#comment-form-send').bind('click', function(){
	
		var error = "";
		
	
		if($("#comment-form #comment-name").val() === $("#comment-form #comment-name").data('default'))		
		{
			
			error = error + "Your Name\r\n";
		}
		
		if($("#comment-form #comment-email").val() === $("#comment-form #comment-email").data('default'))		
		{
			error = error + "Your Email\r\n";
		}
		
		if($("#comment-form #comment-subject").val() === $("#comment-form #comment-subject").data('default'))		
		{
			error = error + "Comment Subject\r\n";
		}
		
		if($("#comment-form #comment-text").val() === $("#comment-form #comment-text").data('default'))		
		{
			error = error + "Your Comment\r\n";
		}
		
		if(error.length>0)
		{
			error = "Please enter the following:\r\n\r\n"+error;
			alert(error);
		}
		else
		{
			if($("#comment-form-send").data('sent')!==true)
			{
				$.ajax({
				   type: "POST",
				   url: "/ajax/comment",
				   data: $("input, textarea").serialize(),
				   success: function(msg){
				     $("#comment-form-send").html("Comment sent for moderation! Thanks for your input.");
					 $("#comment-form-send").data('sent', true);
				   }
				 });
			}
			
			
		}
		
	});
	
});

/* End of Footer */
