$(document).ready(function() {
						   
	setFancyBox();
	
	$("#comment_text").resizable({
		handles: "s"
	});
	$("#comment_form").validate();
	
	
	$(".screenshots li a").live("mouseover" , function () {
		$(this).stop().animate( { opacity: 0.7 } , 300 , 'easeOutSine' );
	});
	
	$(".screenshots li a").live("mouseout" , function () {
		$(this).stop().animate( { opacity: 1 } , 300 , 'easeOutSine' );
	});
	
	$(".blog_list li .image_outer a").live("mouseover" , function () {
		$(this).children("img").stop().animate( { opacity: 0.7 } , 300 , 'easeOutSine' );
	});
	
	$(".blog_list li .image_outer a").live("mouseout" , function () {
		$(this).children("img").stop().animate( { opacity: 1 } , 300 , 'easeOutSine' );
	});
	
	$("#recent_projects .photo div").live("mouseover" , function () {
		$(this).children("a").stop().animate( { opacity: 0.85 , height: '25px' } , 500 , 'easeOutSine' );
	});
	
	$("#recent_projects .photo div").live("mouseout" , function () {
		$(this).children("a").stop().animate( { opacity: 0 , height: '0px' } , 500 , 'easeInSine' );
	});
	
	$("#numbers li a").live("click" , function () {
		change_photo($(this).attr('rel'));
	});
	
	var project_id = jQuery.url.attr("anchor");
	if ( project_id ) {
		change_project ( project_id )
	}
	
	$(".proj_list a, .foot_list a").live("click" , function () {
		var project_id = $(this).attr('rel');	
		change_project( project_id);
	});
	
	$("#motto").vAlign();
	
	function change_photo ( id ) {
		$("#numbers li a").removeClass("active");
		$("a[rel^="+id+"]").addClass("active");
		$("#recent_projects .photo div").stop().animate( { opacity: 0 } , 600 , 'easeOutSine' , function () {
			$("#recent_projects .photo div").hide();																								 
			$("#recent_projects .photo #"+id).stop().show().animate( { opacity: 1 } , 600 , 'easeInSine' , function () {
		
			});
		});
	}
	
	function change_project ( id ) {

			$("a[rel^="+id+"]").parent().children(".loader").show();
			$(".proj_list li a").removeClass('active');
			$(".proj_list li a").children('.arrow_1').show();
			$(".proj_list li a").children('.arrow_2').hide();
			
			$('#portfolio_text').animate( { opacity: 0 } , 500 , 'easeOutSine' , function () {
				$.post("ajax/", { project_id: id },
					function(data){
						$('#portfolio_text').empty();
						$('#portfolio_text').append(data);
						
						Cufon.replace('.cufon' , {hover: true} );
						setFancyBox();
						
						$(".proj_list li a").removeClass('active');
						$("a[rel^="+id+"]").parent().children(".loader").hide();
						$("a[rel^="+id+"]").addClass('active');
						$("a[rel^="+id+"]").children('.arrow_1').hide();
						$("a[rel^="+id+"]").children('.arrow_2').show();
						
						$('#portfolio_text').animate( { opacity: 1 } , 500 , 'easeOutSine' );
				});
				
			});	

	}
	
	function setFancyBox() {
		$("a[rel^=fancybox]").fancybox({
			'transitionIn'	:	'elastic',
			'transitionOut'	:	'elastic',
			'speedIn'		:	800, 
			'speedOut'		:	800,
			'easingIn'      :   'easeOutExpo',
			'easingOut'     :   'easeInExpo',
			'titlePosition'	:	'inside',
			'padding:'		: 	'9',
		});
	}
	
});

(function ($) {
	$.fn.vAlign = function(container) {
		return this.each(function(i){
			if(container == null) {
				container = 'div';
			}
			$(this).html("<" + container + ">" + $(this).html() + "</" + container + ">");
			var el = $(this).children(container + ":first");
			var elh = $(el).height(); //new element height
			var ph = $(this).height(); //parent height
			var nh = (ph - elh) / 2; //new height to apply
			$(el).css('margin-top', nh);
		});
	};
})(jQuery);
