$(document).ready(function(){

	$('.comments-scroll').jScrollPane({showArrows:false});

	//$('.full').css({'display':'none'});



	$('.top a').click(function(){
		$(window).scrollTo({ top:parseInt($(this).parent().parent().parent().find('.title').offset().top), left:'0px'}, 500, {axis:'xy'});
		return false;
	});
/*
if($('.post').size()==1){
	$('.post').find('.opener-closer a').html('Close<br />post');
	$('.post').addClass('opened');
	$('.post').removeClass('closed');
	$('.post').find('.full').css({'display':'block'});
}
	$('.close-post a').click(function(){
		$(this).parent().parent().parent().find('.dorin2').animate({'height':'show'},500,function(){
			});
		$(this).parent().parent().parent().find('.full').animate({'height':'hide'},500,function(){
			$(this).parent().removeClass('opened');
			$(this).parent().addClass('closed');
			$(this).parent().find('.opener-closer a').html('Open<br />post');
		});
		$(window).scrollTo({ top:parseInt($(this).parent().parent().parent().find('.title').offset().top), left:'0px'}, 500, {axis:'xy'});
		return false;
	});


	$('.picture-open-post').click(function(){
		if($(this).parent().parent().parent().hasClass('closed')){

			var current_node = $(this).parent().parent().parent();
			var focused = 0;

			$('.opened').find('.opener-closer a').html('Open<br />post');
			$('.opened').find('.full').hide();
			$('.opened').addClass('closed');
			$('.opened').removeClass('opened');

			/*$('.opened').find('.full').animate({'height':'hide'},50,function(){
				$(this).parent().find('.opener-closer a').html('Open<br />post');
				$(this).parent().addClass('closed');
				$(this).parent().removeClass('opened');
				$(window).scrollTo({ top:parseInt(current_node.find('.title').offset().top), left:'0px'}, 500, {axis:'xy'});
				focused = 1;
			});* /

			if(focused != 1){
				$(window).scrollTo({ top:parseInt(current_node.find('.title').offset().top), left:'0px'}, 500, {axis:'xy'});
			}
           $(this).parent().parent().parent().find('.dorin2').animate({'height':'hide'},500,function(){
			});
			$(this).parent().parent().parent().find('.full').animate({'height':'show'},500,function(){
				$(this).parent().addClass('opened');
				$(this).parent().removeClass('closed');
				$(this).parent().find('.opener-closer a').html('Close<br />post');
			});

		}else{
			$(this).parent().parent().parent().find('.dorin2').animate({'height':'show'},500,function(){
			});
			$(this).parent().parent().parent().find('.full').animate({'height':'hide'},500,function(){
				$(this).parent().removeClass('opened');
				$(this).parent().addClass('closed');
				$(this).parent().find('.opener-closer a').html('Open<br />post');
			});
			$(window).scrollTo({ top:parseInt($(this).parent().parent().parent().find('.title').offset().top), left:'0px'}, 500, {axis:'xy'});
		}
		return false;
	});
*/
	$('.dorin').click(function(){
		if($(this).parent().parent().parent().hasClass('closed')){

			var current_node = $(this).parent().parent().parent();
			var focused = 0;

			$('.opened').find('.opener-closer a').html('Open<br />post');
			$('.opened').find('.full').hide();
			$('.opened').addClass('closed');
			$('.opened').removeClass('opened');
			
			$('.opened').find('.dorin2').hide();

			/*$('.opened').find('.full').animate({'height':'hide'},50,function(){
				$(this).parent().find('.opener-closer a').html('Open<br />post');
				$(this).parent().addClass('closed');
				$(this).parent().removeClass('opened');
				$(window).scrollTo({ top:parseInt(current_node.find('.title').offset().top), left:'0px'}, 500, {axis:'xy'});
				focused = 1;
			});*/

			if(focused != 1){
				$(window).scrollTo({ top:parseInt(current_node.find('.title').offset().top), left:'0px'}, 500, {axis:'xy'});
			}
             
			$(this).parent().parent().parent().find('.dorin2').animate({'height':'hide'},500,function(){
			});

			$(this).parent().parent().parent().find('.full').animate({'height':'show'},500,function(){
				$(this).parent().addClass('opened');
				$(this).parent().removeClass('closed');
				$(this).parent().find('.opener-closer a').html('Close<br />post');
			});

		}else{
			$(this).parent().parent().parent().find('.dorin2').animate({'height':'show'},500,function(){
			});
			$(this).parent().parent().parent().find('.full').animate({'height':'hide'},500,function(){
				$(this).parent().removeClass('opened');
				$(this).parent().addClass('closed');
				$(this).parent().find('.opener-closer a').html('Open<br />post');
			});
			$(window).scrollTo({ top:parseInt($(this).parent().parent().parent().find('.title').offset().top), left:'0px'}, 500, {axis:'xy'});
		}
		return false;
	});
/*
	$('.opener-closer a').click(function(){
		if($(this).parent().parent().hasClass('closed')){

			var current_node = $(this).parent().parent();
			var focused = 0;

			$('.opened').find('.opener-closer a').html('Open<br />post');
			$('.opened').find('.full').hide();
			$('.opened').addClass('closed');
			$('.opened').removeClass('opened');

			/*$('.opened').find('.full').animate({'height':'hide'},50,function(){
				$(this).parent().find('.opener-closer a').html('Open<br />post');
				$(this).parent().addClass('closed');
				$(this).parent().removeClass('opened');
				$(window).scrollTo({ top:parseInt(current_node.find('.title').offset().top), left:'0px'}, 500, {axis:'xy'});
				focused = 1;
			});* /

			if(focused != 1){
				$(window).scrollTo({ top:parseInt(current_node.find('.title').offset().top), left:'0px'}, 500, {axis:'xy'});
			}
            $(this).parent().parent().parent().find('.dorin2').animate({'height':'hide'},500,function(){
			});
			$(this).parent().parent().find('.full').animate({'height':'show'},500,function(){
				$(this).parent().addClass('opened');
				$(this).parent().removeClass('closed');
				$(this).parent().find('.opener-closer a').html('Close<br />post');
			});

		}else{
			$(this).parent().parent().parent().find('.dorin2').animate({'height':'show'},500,function(){
			});
			$(this).parent().parent().find('.full').animate({'height':'hide'},500,function(){
				$(this).parent().removeClass('opened');
				$(this).parent().addClass('closed');
				$(this).parent().find('.opener-closer a').html('Open<br />post');
			});
			$(window).scrollTo({ top:parseInt($(this).parent().parent().find('.title').offset().top), left:'0px'}, 500, {axis:'xy'});
		}
		return false;
	});
*/
	$('.add-comment-link a').click(function(){
		var node = $(this).parent().parent().parent().find('.add-comment');
		// if(node.hasClass('opened-comments')){
		// 			node.animate({'height':'hide'},500,function(){
		// 				node.removeClass('opened-comments');
		// 			});
		// 		}else{
		// 			node.animate({'height':'show'},500,function(){
		// 				node.addClass('opened-comments');
		// 			});
		// 		}
		$(window).scrollTo({ top:parseInt($(this).parent().parent().parent().find('.add-comment').offset().top), left:'0px'}, 500, {axis:'xy'});
		return false;
	});
	
	$('.send-to-friend a').click(function(){
		var node = $(this).parent().parent().parent().find('.send-to-friend-form');
		if(node.hasClass('opened-comments')){
			node.animate({'height':'hide'},500,function(){
				node.removeClass('opened-comments');
			});
		}else{
			node.animate({'height':'show'},500,function(){
				node.addClass('opened-comments');
			});
		}
		$(window).scrollTo({ top:parseInt($(this).parent().parent().parent().find('.send-to-friend-form').offset().top), left:'0px'}, 500, {axis:'xy'});
		return false;
	});


/*	$('.comments-scroll').jScrollPane({showArrows:false});

	$('.add-comment').each(function(){
		var full_height = $(this).height();
		$(this).attr({'rel':full_height});
		$(this).css({'height':'0px','display':'none'});
	});

	$('.full').each(function(){
		var full_height = $(this).height();
		$(this).css({'height':'hide'});
	});

	$('.opener-closer a').click(function(){
		if($(this).parent().parent().hasClass('closed')){
			var full_height = parseInt($(this).parent().parent().find('.full').attr('rel'));
			$(this).parent().parent().find('.full').css({'display':'block'});
			$(this).parent().parent().find('.full').animate({'height':'show'},500,function(){
				$(this).parent().addClass('opened');
				$(this).parent().removeClass('closed');
			});
			$(window).scrollTo({ top:parseInt($(this).parent().parent().find('.title').offset().top), left:'0px'}, 500, {axis:'xy'});
		}else{
			$(this).parent().parent().find('.full').animate({'height':'hide'},500,function(){
				$(this).parent().removeClass('opened');
				$(this).parent().addClass('closed');
				$(this).css({'display':'none'});
				$(this).parent().find('.add-comment').css({'display':'none'});
			});
			$(window).scrollTo({ top:parseInt($(this).parent().parent().find('.title').offset().top), left:'0px'}, 500, {axis:'xy'});
		}
		return false;
	});

	$('.add-comment-link a').click(function(){
		if($(this).parent().parent().parent().find('.add-comment').css('display')=='none'){
			var full_height = parseInt($(this).parent().parent().parent().find('.add-comment').attr('rel'));
			$(this).parent().parent().parent().find('.add-comment').css({'display':'block'});
			$(this).parent().parent().parent().parent().parent().find('.full').animate({'height':(parseInt($(this).parent().parent().parent().parent().parent().find('.full').attr('rel')) + 228) + 'px'},500,function(){ });
			$(this).parent().parent().parent().find('.add-comment').animate({'height':208 + 'px'},500,function(){
			});
			$(window).scrollTo({ top:parseInt($(this).parent().parent().parent().find('.add-comment').offset().top), left:'0px'}, 500, {axis:'xy'});
		}else{
			$(this).parent().parent().parent().parent().parent().find('.full').animate({'height':parseInt($(this).parent().parent().parent().parent().parent().find('.full').attr('rel')) + 'px'},500,function(){ });
			$(this).parent().parent().parent().find('.add-comment').animate({'height':0 + 'px'},500,function(){
				$(this).parent().parent().parent().find('.add-comment').css({'display':'none'});
			});
			$(window).scrollTo({ top:parseInt($(this).parent().parent().parent().find('.add-comment').offset().top), left:'0px'}, 500, {axis:'xy'});
		}
		return false;
	});*/


	/*$('.close-post a').click(function(){
		$('.post').removeClass('opened');
		$('.post').addClass('closed');
		return false;
	});

	$('.opener-closer a.opener').click(function(){
		$('.post').removeClass('opened');
		$('.post').addClass('closed');
		$(this).parent().parent().addClass('opened');
		$(this).parent().parent().removeClass('closed');
		$('.comments-scroll').jScrollPane({showArrows:false});
		return false;
	});

	$('.opener-closer a.closer').click(function(){
		$(this).parent().parent().addClass('closed');
		$(this).parent().parent().removeClass('opened');
		return false;
	});

	$('.add-comment-link a').click(function(){
		if($(this).parent().parent().parent().find('.add-comment').css('display') == 'block'){
			$(this).parent().parent().parent().find('.add-comment').css({'display':'none'});
		}else{
			$(this).parent().parent().parent().find('.add-comment').css({'display':'block'});
		}
		return false;
	});*/

});
