$(function(){
	initPage();
	initTabs();
	initModules();
	initBtnSupp()
	//calculateWallHeight();
})


function calculateWallHeight()
{

}
/*

	var maxHeight = "0";
	for(var i = 0 ; i < $(".drop").length ; i++)
	{
		var div = $(".drop")[i];
		var val = $(div).css("height").split("px");
		if(maxHeight < val[0])
		{
			maxHeight = val[0];
		}
	}
	val = $(".mur").css("height").split("px");
	val = $(".mur").css("height").split("px");
	$(".mur").css('height')
	if(val[0] < maxHeight)
	{
		maxHeight = maxHeight * 100;
		$(".mur").css('height',maxHeight + "px")
	}

}*/

function initBtnSupp(){
	$('.btn-supprime-comment').live('click',function(e){
	e.preventDefault();
		confirm_supp = confirm("Ce message sera définitivement supprimé. Voulez-vous continuer?");
		if (confirm_supp==true) {
			id_post = $(this).parent().children('.id_post').val();
			id_parent =$(this).parent().children('.id_parent').val();
			post_type = $(this).parent().children('.post_type').val();
			$('.loading-gif').show();
			$.post($(location).attr('href'), { POST_ID:id_post ,supp_post: 1 ,POST_TYPE:post_type},
  			function(data) {
  				$('.comment-'+id_parent).html('');
  				$('.comment-'+id_parent).append($('.comment-'+id_parent, data).html());
  				$('.btn-more-post').html('');
 				$('.btn-more-post').append($('.btn-more-post', data).html());
				clearFormFields({
					clearInputs: true,
					clearTextareas: true,
					passwordFieldText: false,
					addClassFocus: "focus",
					filterClass: "default"
				});
  				$('.loading-gif').hide();calculateWallHeight();
   			});
  		}
	});
	
	// Suppression document
	$('.btn-supprime-doc').live('click',function(e){
	e.preventDefault();

		confirm_supp = confirm("Cette information sera définitivement supprimée. Voulez-vous continuer?");		
		if (confirm_supp==true) {
			file_id = $(this).parent().children('.file_id').val();
			file_type = $(this).parent().children('.file_type').val();
			$('.loading-gif').show();
			$.post($(location).attr('href'), { FILE_ID:file_id, FILE_TYPE:file_type, supp_doc:1},
  			function(data) {
  				$('.mur').html('');
  				$('.mur').append($('.mur', data).html());
  				$('.btn-more-viewgroup').html('');
 				$('.btn-more-viewgroup').append($('.btn-more-viewgroup', data).html());
				clearFormFields({
					clearInputs: true,
					clearTextareas: true,
					passwordFieldText: false,
					addClassFocus: "focus",
					filterClass: "default"
				});
  				$('.loading-gif').hide();calculateWallHeight();
   			});
  		}
  		
  		
	});
	
	
	$('.btn-supprime').live('click',function(e){
	e.preventDefault();

		confirm_supp = confirm("Ce message sera définitivement supprimé. Voulez-vous continuer?");		
		if (confirm_supp==true) {
			id_post = $(this).parent().children('.id_post').val();
			post_type = $(this).parent().children('.post_type').val();
			$('.loading-gif').show();
			$.post($(location).attr('href'), { POST_ID:id_post ,supp_post: 1,POST_TYPE:post_type},
  			function(data) {
  				$('.mur').html('');
  				$('.mur').append($('.mur', data).html());
  				$('.btn-more-post').html('');
 				$('.btn-more-post').append($('.btn-more-post', data).html());
				clearFormFields({
					clearInputs: true,
					clearTextareas: true,
					passwordFieldText: false,
					addClassFocus: "focus",
					filterClass: "default"
				});
  				$('.loading-gif').hide();calculateWallHeight();
   			});
  		}
	});
	
	$('.btn-supprime-event').live('click',function(e){
	e.preventDefault();

		confirm_supp = confirm("Ce message sera définitivement supprimé. Voulez-vous continuer?\n Attention l'évènement restera dans votre agenda");
		if (confirm_supp==true) {
			id_post = $(this).parent().children('.id_post').val();
			post_type = $(this).parent().children('.post_type').val();
			$('.loading-gif').show();
			$.post($(location).attr('href'), { POST_ID:id_post ,supp_post: 1,POST_TYPE:post_type},
  			function(data) {
  				$('.mur').html('');
  				$('.mur').append($('.mur', data).html());
  				$('.btn-more-post').html('');
 				$('.btn-more-post').append($('.btn-more-post', data).html());
				clearFormFields({
					clearInputs: true,
					clearTextareas: true,
					passwordFieldText: false,
					addClassFocus: "focus",
					filterClass: "default"
				});
  				$('.loading-gif').hide();calculateWallHeight();
   			});
  		}
	});
	
	
	$('.btn-participe').live('click',function(e){

		e.preventDefault();
		id_event = $(this).parent().children('.id_event').val();
		$('.loading-gif').show();
		$.post($(location).attr('href'), {PARTICIPE:id_event},
		function(data) {
			location.reload();
			clearFormFields({
				clearInputs: true,
				clearTextareas: true,
				passwordFieldText: false,
				addClassFocus: "focus",
				filterClass: "default"
			});
			$('.loading-gif').hide();calculateWallHeight();
		});
	});
	$('.btn-participe-plus').live('click',function(e){
		e.preventDefault();
		id_event = $(this).parent().children('.id_event').val();
		$('.loading-gif').show();
		$.post($(location).attr('href'), {PARTICIPE_PLUS:id_event},
		function(data) {
			location.reload();
			clearFormFields({
				clearInputs: true,
				clearTextareas: true,
				passwordFieldText: false,
				addClassFocus: "focus",
				filterClass: "default"
			});
			$('.loading-gif').hide();calculateWallHeight();
		});
	});
	
	$('.accept-contact-invit').live('click',function(e){
		e.preventDefault();
		invit_contact_id = $(this).parent().children('.invit-contact-id').val();
		$('.loading-gif').show();
		$.post($(location).attr('href'), {ID_INVIT_CONTACT:invit_contact_id ,ACCEPT: 1},
		function(data) {
			location.reload();
			clearFormFields({
				clearInputs: true,
				clearTextareas: true,
				passwordFieldText: false,
				addClassFocus: "focus",
				filterClass: "default"
			});
			$('.loading-gif').hide();calculateWallHeight();
		});
	});
	
	
	
	
	$('.delete-contact-invit').live('click',function(e){
	e.preventDefault();
		confirm_supp = confirm("Cette invitation sera définitivement supprimée. Voulez-vous continuer?");
		if (confirm_supp==true) {
			invit_contact_id = $(this).parent().children('.invit-contact-id').val();
		$('.loading-gif').show();
		$.post($(location).attr('href'), {ID_INVIT_CONTACT:invit_contact_id ,DELETE: 1},
		function(data) {
			location.reload();
			clearFormFields({
				clearInputs: true,
				clearTextareas: true,
				passwordFieldText: false,
				addClassFocus: "focus",
				filterClass: "default"
			});
			$('.loading-gif').hide();calculateWallHeight();
		});
  		}
	});
	
	
	$('.btn-join-group').live('click',function(e){
	
		e.preventDefault();
		id_group = $('.id_group').val();
		id_user = $('.id_user').val();
	
		$.post($(location).attr('href'), {ID_GROUP:id_group , ID_USER:id_user,JOIN: 1},
		function(data) {
			location.reload();
		});
	});
	
	$('.btn-quit-group').live('click',function(e){
		e.preventDefault();
		id_group = $('.id_group').val();
		id_user = $('.id_user').val();
		$.post($(location).attr('href'), {ID_GROUP:id_group , ID_USER:id_user,QUIT: 1},
		function(data) {
			location.reload();
		});
	});
	
	$('.accept-event-invit').live('click',function(e){
		e.preventDefault();
		invit_event_id = $(this).parent().children('.invit-event-id').val();
		$('.loading-gif').show();
		$.post($(location).attr('href'), {ID_INVITE_EVENT:invit_event_id ,ACCEPT: 1},
		function(data) {
			location.reload();
			clearFormFields({
				clearInputs: true,
				clearTextareas: true,
				passwordFieldText: false,
				addClassFocus: "focus",
				filterClass: "default"
			});
			$('.loading-gif').hide();calculateWallHeight();
		});
	});
	
	$('.delete-event-invit').live('click',function(e){
	e.preventDefault();
		confirm_supp = confirm("Cette invitation sera définitivement supprimée. Voulez-vous continuer?");
		if (confirm_supp==true) {
			invit_event_id = $(this).parent().children('.invit-event-id').val();
		$('.loading-gif').show();
		$.post($(location).attr('href'), {ID_INVITE_EVENT:invit_event_id ,DELETE: 1},
		function(data) {
			location.reload();
			clearFormFields({
				clearInputs: true,
				clearTextareas: true,
				passwordFieldText: false,
				addClassFocus: "focus",
				filterClass: "default"
			});
			$('.loading-gif').hide();calculateWallHeight();
		});
  		}
	});
	
	$('.accept-group-invit').live('click',function(e){
		e.preventDefault();
		invit_group_id = $(this).parent().children('.invit-group-id').val();
		group_id = $(this).parent().children('.group-id').val();
		$('.loading-gif').show();
		$.post($(location).attr('href'), {ID_INVIT_GROUP:invit_group_id,ID_GROUP:group_id ,ACCEPT: 1},
		function(data) {
			location.reload();
			clearFormFields({
				clearInputs: true,
				clearTextareas: true,
				passwordFieldText: false,
				addClassFocus: "focus",
				filterClass: "default"
			});
			$('.loading-gif').hide();calculateWallHeight();
		});
	});
	
	$('.add-event-navbar').live('click',function(e){
		e.preventDefault();
		$('a.tab[href="#tab6"]').trigger('click');
	});
	
	$('.delete-group-invit').live('click',function(e){
	e.preventDefault();
		confirm_supp = confirm("Cette invitation sera définitivement supprimée. Voulez-vous continuer?");
		if (confirm_supp==true) {
			invit_group_id = $(this).parent().children('.invit-group-id').val();
		$('.loading-gif').show();
		$.post($(location).attr('href'), {ID_INVIT_GROUP:invit_group_id,DELETE: 1},
		function(data) {
			location.reload();
			clearFormFields({
				clearInputs: true,
				clearTextareas: true,
				passwordFieldText: false,
				addClassFocus: "focus",
				filterClass: "default"
			});
			$('.loading-gif').hide();calculateWallHeight();
		});
  		}
	});
	
	$('.post').live('mouseover',function(){
		$(this).children('form').show();
	});
	
	$('.post').live('mouseout',function(){
		$(this).children('form').hide();
	});
	
	$('.comment').live('mouseover',function(){
		$(this).children('form').show();
	});
	
	$('.comment').live('mouseout',function(){
		$(this).children('form').hide();
	});
	
	
	$('.btn-add-contact').live('click',function(e){
		e.preventDefault();
		id_user = $(this).parent().children('.id_user').val();
		id_user_affiche = $(this).parent().children('.id_user_affiche').val();
		$('.loading-gif').show();
		$.post($(location).attr('href'), {USER_ID:id_user ,USER_ID_AFFICHE:id_user_affiche ,ADD: 1},
		function(data) {
			location.reload();
			clearFormFields({
				clearInputs: true,
				clearTextareas: true,
				passwordFieldText: false,
				addClassFocus: "focus",
				filterClass: "default"
			});
			$('.loading-gif').hide();calculateWallHeight();
		});
	});
	
	$('.btn-add-contact-know').live('click',function(e){
		e.preventDefault();
		id_user = $(this).parent().children('.id_user_affiche').val();
		id_user_affiche = $(this).parent().children('.id_user').val();
		$('.loading-gif').show();
		$.post($(location).attr('href'), {USER_ID:id_user ,USER_ID_AFFICHE:id_user_affiche ,ADD_KNOWN: 1},
		function(data) {
			location.reload();
			clearFormFields({
				clearInputs: true,
				clearTextareas: true,
				passwordFieldText: false,
				addClassFocus: "focus",
				filterClass: "default"
			});
			$('.loading-gif').hide();calculateWallHeight();
		});
	});
	
	$('.btn-remove-contact-know').live('click',function(e){
		e.preventDefault();
		id_user = $(this).parent().children('.id_user').val();
		id_user_affiche = $(this).parent().children('.id_user_affiche').val();
		$('.loading-gif').show();
		$.post($(location).attr('href'), {},
		function(data) {
			$('.connaissez_vous').html('');
  				$('.connaissez_vous').append($('.connaissez_vous', data).html());
			clearFormFields({
				clearInputs: true,
				clearTextareas: true,
				passwordFieldText: false,
				addClassFocus: "focus",
				filterClass: "default"
			});
			$('.loading-gif').hide();calculateWallHeight();
		});
	});
	
	$('.btn-remove-contact').live('click',function(e){
		e.preventDefault();
		id_user = $(this).parent().children('.id_user').val();
		id_user_affiche = $(this).parent().children('.id_user_affiche').val();
		$('.loading-gif').show();
		$.post($(location).attr('href'), {USER_ID:id_user ,USER_ID_AFFICHE:id_user_affiche ,REMOVE: 1},
		function(data) {
			location.reload();
			clearFormFields({
				clearInputs: true,
				clearTextareas: true,
				passwordFieldText: false,
				addClassFocus: "focus",
				filterClass: "default"
			});
			$('.loading-gif').hide();calculateWallHeight();
		});
	});
	
	$('.select-categorie-user').live('change',function(e){
		$('.group_categorie_user').val($(this).val());
		categorie_user = $('.group_categorie_user').val();
		sort_user = $('.group_sort_user').val();
		categorie_all = $('.group_categorie_all').val();
		sort_all = $('.group_sort_all').val();
		$.post($(location).attr('href'), {
		group_categorie_user:categorie_user,
		group_sort_user:sort_user,
		group_categorie_all:categorie_all,
		group_sort_all:sort_all},
		function(data) {
			$('.user_products').html('');
			$('.user_products').append($('.user_products', data).html());
		});
	});
	
	$('.select-sort-user').live('change',function(e){
		$('.group_sort_user').val($(this).val());
		categorie_user = $('.group_categorie_user').val();
		sort_user = $('.group_sort_user').val();
		categorie_all = $('.group_categorie_all').val();
		sort_all = $('.group_sort_all').val();
		$.post($(location).attr('href'), {
		group_categorie_user:categorie_user,
		group_sort_user:sort_user,
		group_categorie_all:categorie_all,
		group_sort_all:sort_all},
		function(data) {
			$('.user_products').html('');
			$('.user_products').append($('.user_products', data).html());
		});
	});
	
	$('.select-categorie-all').live('change',function(e){
		$('.group_categorie_all').val($(this).val());
		categorie_user = $('.group_categorie_user').val();
		sort_user = $('.group_sort_user').val();
		categorie_all = $('.group_categorie_all').val();
		sort_all = $('.group_sort_all').val();
		$.post($(location).attr('href'), {
		group_categorie_user:categorie_user,
		group_sort_user:sort_user,
		group_categorie_all:categorie_all,
		group_sort_all:sort_all},
		function(data) {
			$('.all_products').html('');
			$('.all_products').append($('.all_products', data).html());
			$('.btn-more-viewdocs').html('');
 			$('.btn-more-viewdocs').append($('.btn-more-viewdocs', data).html());
			$('.btn-more-viewgroup').html('');
 			$('.btn-more-viewgroup').append($('.btn-more-viewgroup', data).html());
		});
	});
	
	$('.select-sort-all').live('change',function(e){
		$('.group_sort_all').val($(this).val());
		categorie_user = $('.group_categorie_user').val();
		sort_user = $('.group_sort_user').val();
		categorie_all = $('.group_categorie_all').val();
		sort_all = $('.group_sort_all').val();
		$.post($(location).attr('href'), {
		group_categorie_user:categorie_user,
		group_sort_user:sort_user,
		group_categorie_all:categorie_all,
		group_sort_all:sort_all},
		function(data) {
			$('.all_products').html('');
			$('.all_products').append($('.all_products', data).html());
			$('.btn-more-viewdocs').html('');
 			$('.btn-more-viewdocs').append($('.btn-more-viewdocs', data).html());
			$('.btn-more-viewgroup').html('');
 			$('.btn-more-viewgroup').append($('.btn-more-viewgroup', data).html());
		});
	});

	$('.btn-more-post').live('click',function(e){
		e.preventDefault();
		num_page = $('.page').val();
		in_print_tous = $('.print_tous').val();
		in_print_contacts = $('.print_contacts').val();
		in_print_groups = $('.print_groups').val();
		in_print_events = $('.print_events').val();
		in_print_audio = $('.print_audio').val();
		in_print_video = $('.print_video').val();
		in_print_document = $('.print_document').val();
		in_print_photo = $('.print_photo').val();
		$.post($(location).attr('href'), {
		print_tous:in_print_tous,
		print_contacts:in_print_contacts,
		print_events:in_print_events,
		print_groups:in_print_groups,
		print_audio:in_print_audio,
		print_video:in_print_video,
		print_document:in_print_document,
		print_photo:in_print_photo,
		page:num_page},
		function(data) {
			$('.mur').append($('.mur', data).html());
			$('.btn-more-post').html('');
 			$('.btn-more-post').append($('.btn-more-post', data).html());
		});
	});
	
	$('.btn-more-viewgroup').live('click',function(e){
		e.preventDefault();
		num_page = $('.page').val();
		in_print_tous = $('.print_tous').val();
		in_print_contacts = $('.print_contacts').val();
		in_print_groups = $('.print_groups').val();
		in_print_events = $('.print_events').val();
		categorie_user = $('.group_categorie_user').val();
		sort_user = $('.group_sort_user').val();
		categorie_all = $('.group_categorie_all').val();
		sort_all = $('.group_sort_all').val();
		$.post($(location).attr('href'), {print_tous:in_print_tous,
		print_contacts:in_print_contacts,
		print_events:in_print_events,
		print_groups:in_print_groups,
		group_categorie_user:categorie_user,
		group_sort_user:sort_user,
		group_categorie_all:categorie_all,
		group_sort_all:sort_all,
		page:num_page},
		function(data) {
			$('.all_products').append($('.all_products', data).html());
			$('.btn-more-viewgroup').html('');
 			$('.btn-more-viewgroup').append($('.btn-more-viewgroup', data).html());
		});
	});
	
	/*$('.btn-more-viewdocs').live('click',function(e){
		e.preventDefault();
		num_page = $('.page').val();
		in_print_tous = $('.print_tous').val();
		in_print_audio = $('.print_audio').val();
		in_print_video = $('.print_video').val();
		in_print_document = $('.print_document').val();
		in_print_photo = $('.print_photo').val();
		categorie_user = $('.group_categorie_user').val();
		sort_user = $('.group_sort_user').val();
		categorie_all = $('.group_categorie_all').val();
		sort_all = $('.group_sort_all').val();
		$.post($(location).attr('href'), {print_tous:in_print_tous,
		print_audio:in_print_audio,
		print_video:in_print_video,
		print_document:in_print_document,
		print_photo:in_print_photo,
		group_categorie_user:categorie_user,
		group_sort_user:sort_user,
		group_categorie_all:categorie_all,
		group_sort_all:sort_all,
		page:num_page},
		function(data) {
			$('.all_products').append($('.all_products', data).html());
			$('.btn-more-viewdocs').html('');
 			$('.btn-more-viewdocs').append($('.btn-more-viewdocs', data).html());
		});
	});*/
	
	
	$('.select-document-all').live('change',function(e){
		$('.document_categorie_all').val($(this).val());
		categorie_user = $('.document_categorie_user').val();
		sort_user = $('.document_sort_user').val();
		categorie_all = $('.document_categorie_all').val();
		sort_all = $('.document_sort_all').val();
		$.post($(location).attr('href'), {
		document_categorie_user:categorie_user,
		document_sort_user:sort_user,
		document_categorie_all:categorie_all,
		document_sort_all:sort_all},
		function(data) {
			$('.all_products').html('');
			$('.all_products').append($('.all_products', data).html());
			$('.btn-more-viewdocs').html('');
 			$('.btn-more-viewdocs').append($('.btn-more-viewdocs', data).html());
			$('.btn-more-viewgroup').html('');
 			$('.btn-more-viewgroup').append($('.btn-more-viewgroup', data).html());
		});
	});
	
}


function initTabs(){
	//Validation entrer commentaires
	$('.comment-textarea').live('keypress',function(e){
		$(this).parent().children('.message').val($(this).val());
		id_post= $(this).parent().children('.id_post').val();
		id_user= $(this).parent().children('.id_user').val();
		post_type= $(this).parent().children('.post_type').val();
		message= $(this).parent().children('.message').val();	
		
		var code = (e.keyCode ? e.keyCode : e.which);
 		if(code == 13 && !e.shiftKey) {
 		$('.loading-gif').show();
 		e.preventDefault();
 			$(this).val($(this).text())
  			$.post($(location).attr('href'), { POST_ID: id_post, USER_ID: id_user,POST_TYPE:post_type,TEXT: message,add_commentaire: 1 },
  			function(data) {
  				$('.comment-'+id_post).html('');
  				$('.comment-'+id_post).append($('.comment-'+id_post, data).html());
  				$('.btn-more-post').html('');
 				$('.btn-more-post').append($('.btn-more-post', data).html());
				clearFormFields({
					clearInputs: true,
					clearTextareas: true,
					passwordFieldText: false,
					addClassFocus: "focus",
					filterClass: "default"
				});
				$('.loading-gif').hide();calculateWallHeight();
   			});
 		}
	});


	//Validation entrer statut
	$('.status-update').live('keypress',function(e){
	
	
		post_type = $('.post-type').val();
		post_user_id = $('.post-user-id').val();
		post_user_id_affiche = $('.post-user-id-affiche').val();
		post_group_id = $('.post-group-id').val();
		post_event_id = $('.post-event-id').val();
		message= $(this).val();
		var code = (e.keyCode ? e.keyCode : e.which);
		
		expReg = /(http:\/\/|www)[a-z0-9.%\/]*/g;
		lienSite = message.match(expReg);
		repereHttp = message.indexOf("http://", 0);
		repereWww = message.indexOf("www.", 0);
		
		if(repereHttp == -1){
			messageSansLien = message.substring(0, repereWww);
		}
		if(repereWww == -1){
			messageSansLien = message.substring(0, repereHttp);
		}
			
		if(code == 32){
			if(lienSite == null){
				
			}else{
				
				$("#tab_lien").trigger('click');
				$("#lien-url-url").val(lienSite);
				$(".status-update-lien-url").val(messageSansLien);
		
			}
		}

 		if(code == 13 && !e.shiftKey) {
			if(lienSite == null){
				$('.loading-gif').show();
				e.preventDefault();
				$(this).val($(this).text())
				switch (post_type)
				{
					case "home":
						$.post($(location).attr('href'), { USER_ID: post_user_id,TEXT: message,add_post: 1},
						function(data) {
							$('.mur').html('');
							$('.mur').append($('.mur', data).html());
							$('.btn-more-post').html('');
					$('.btn-more-post').append($('.btn-more-post', data).html());
							clearFormFields({
								clearInputs: true,
								clearTextareas: true,
								passwordFieldText: false,
								addClassFocus: "focus",
								filterClass: "default"
							});
							$('.loading-gif').hide();calculateWallHeight();
						});
						break;
					case "profil":
						$.post($(location).attr('href'), { USER_ID_AFFICHE:post_user_id_affiche,USER_ID: post_user_id,TEXT: message,add_post: 1},
						function(data) {
							$('.mur').html('');
							$('.mur').append($('.mur', data).html());
							$('.btn-more-post').html('');
							$('.btn-more-post').append($('.btn-more-post', data).html());
							clearFormFields({
								clearInputs: true,
								clearTextareas: true,
								passwordFieldText: false,
								addClassFocus: "focus",
								filterClass: "default"
							});
							$('.loading-gif').hide();calculateWallHeight();
						});
						break;
					
					case "event":
						$.post($(location).attr('href'), { EID:post_event_id,USER_ID: post_user_id,TEXT: message,add_post: 1},
						function(data) {
							$('.mur').html('');
							$('.mur').append($('.mur', data).html());
							$('.btn-more-post').html('');
							$('.btn-more-post').append($('.btn-more-post', data).html());
							clearFormFields({
								clearInputs: true,
								clearTextareas: true,
								passwordFieldText: false,
								addClassFocus: "focus",
								filterClass: "default"
							});
							$('.loading-gif').hide();calculateWallHeight();
						});
						break;
					case "group":
						$.post($(location).attr('href'), { GID:post_group_id,USER_ID: post_user_id,TEXT: message,add_post: 1},
						function(data) {
							$('.mur').html('');
							$('.mur').append($('.mur', data).html());
							$('.btn-more-post').html('');
							$('.btn-more-post').append($('.btn-more-post', data).html());
							clearFormFields({
								clearInputs: true,
								clearTextareas: true,
								passwordFieldText: false,
								addClassFocus: "focus",
								filterClass: "default"
							});
							$('.loading-gif').hide();calculateWallHeight();
						});
						break;
				}
			}else{
				
				$("#tab_lien").trigger('click');
				$("#lien-url-url").val(lienSite);
				$(".status-update-lien-url").val(messageSansLien);
		
			}
			
		}
	});

	//Validation entrer statut
	$('.status-update-video-embeded').live('keypress',function(e){
		
		post_type = $('.post-type').val();
		post_user_id= $('.post-user-id').val();
		post_user_id_affiche= $('.post-user-id-affiche').val();
		post_group_id= $('.post-group-id').val();
		message= $(this).val();
		embeded = $('#video-embed-embed').val();
		file = $('#file-embed-embed').val();
		titre = $('#video-embed-titre').val();
		description = $('#video-embed-description').val();
		mots = $('#video-embed-mots').val();
		category = $('#video-embed-category').val();
		var code = (e.keyCode ? e.keyCode : e.which);
 		if(code == 13 && !e.shiftKey) {
			$('.loading-gif').show();
			e.preventDefault();
			$(this).val($(this).text())
			switch (post_type)
			{
				case "home":
					$.post($(location).attr('href'), { USER_ID: post_user_id,TEXT: message,add_post: 1,FILE : file ,EMBEDED: embeded,DESCRIPTION:description,MOTS:mots,CATEGORY:category,TITRE:titre},
					//$.file($(location).attr('href'), { FILE : file }
					function(data) {
						$('.mur').html('');
						$('.mur').append($('.mur', data).html());
						$('.btn-more-post').html('');
 				$('.btn-more-post').append($('.btn-more-post', data).html());
						clearFormFields({
							clearInputs: true,
							clearTextareas: true,
							passwordFieldText: false,
							addClassFocus: "focus",
							filterClass: "default"
						});
						$('.loading-gif').hide();calculateWallHeight();
					});
					break;
				case "profil":
					$.post($(location).attr('href'), { USER_ID_AFFICHE:post_user_id_affiche,USER_ID: post_user_id,TEXT: message,add_post: 1,EMBEDED: embeded,DESCRIPTION:description,MOTS:mots,CATEGORY:category,TITRE:titre},
					function(data) {
						$('.mur').html('');
						$('.mur').append($('.mur', data).html());
						$('.btn-more-post').html('');
 						$('.btn-more-post').append($('.btn-more-post', data).html());
						clearFormFields({
							clearInputs: true,
							clearTextareas: true,
							passwordFieldText: false,
							addClassFocus: "focus",
							filterClass: "default"
						});
						$('.loading-gif').hide();calculateWallHeight();
					});
					break;
				case "group":
					$.post($(location).attr('href'), { GID:post_group_id,USER_ID: post_user_id,TEXT: message,add_post: 1,EMBEDED: embeded,DESCRIPTION:description,MOTS:mots,CATEGORY:category,TITRE:titre},
					function(data) {
						$('.mur').html('');
						$('.mur').append($('.mur', data).html());
						$('.btn-more-post').html('');
 						$('.btn-more-post').append($('.btn-more-post', data).html());
						clearFormFields({
							clearInputs: true,
							clearTextareas: true,
							passwordFieldText: false,
							addClassFocus: "focus",
							filterClass: "default"
						});
						$('.loading-gif').hide();calculateWallHeight();
					});
					break;
			}
		}
	});
	
	$('.status-update-video-lien').live('keypress',function(e){
		
		post_type = $('.post-type').val();
		post_user_id= $('.post-user-id').val();
		post_user_id_affiche= $('.post-user-id-affiche').val();
		post_group_id= $('.post-group-id').val();
		message= $(this).val();
		lien = $('#video-lien-lien').val();
		file = $('#file-embed-embed').val();
		titre = $('#video-lien-titre').val();
		description = $('#video-lien-description').val();
		mots = $('#video-lien-mots').val();
		category = $('#video-lien-category').val();
		var code = (e.keyCode ? e.keyCode : e.which);
 		if(code == 13 && !e.shiftKey) {
			$('.loading-gif').show();
			e.preventDefault();
			$(this).val($(this).text())
			switch (post_type)
			{
				case "home":
					$.post($(location).attr('href'), { USER_ID: post_user_id,TEXT: message,add_post: 1,FILE : file ,LIENVID: lien,DESCRIPTION:description,MOTS:mots,CATEGORY:category,TITRE:titre},
					function(data) {
						$('.mur').html('');
						$('.mur').append($('.mur', data).html());
						$('.btn-more-post').html('');
 				$('.btn-more-post').append($('.btn-more-post', data).html());
						clearFormFields({
							clearInputs: true,
							clearTextareas: true,
							passwordFieldText: false,
							addClassFocus: "focus",
							filterClass: "default"
						});
						$('.loading-gif').hide();calculateWallHeight();
					});
					break;
				case "profil":
					$.post($(location).attr('href'), { USER_ID_AFFICHE:post_user_id_affiche,USER_ID: post_user_id,TEXT: message,add_post: 1,LIENVID: lien,DESCRIPTION:description,MOTS:mots,CATEGORY:category,TITRE:titre},
					function(data) {
						$('.mur').html('');
						$('.mur').append($('.mur', data).html());
						$('.btn-more-post').html('');
 						$('.btn-more-post').append($('.btn-more-post', data).html());
						clearFormFields({
							clearInputs: true,
							clearTextareas: true,
							passwordFieldText: false,
							addClassFocus: "focus",
							filterClass: "default"
						});
						$('.loading-gif').hide();calculateWallHeight();
					});
					break;
				case "group":
					$.post($(location).attr('href'), { GID:post_group_id,USER_ID: post_user_id,TEXT: message,add_post: 1,LIENVID: lien,DESCRIPTION:description,MOTS:mots,CATEGORY:category,TITRE:titre},
					function(data) {
						$('.mur').html('');
						$('.mur').append($('.mur', data).html());
						$('.btn-more-post').html('');
 						$('.btn-more-post').append($('.btn-more-post', data).html());
						clearFormFields({
							clearInputs: true,
							clearTextareas: true,
							passwordFieldText: false,
							addClassFocus: "focus",
							filterClass: "default"
						});
						$('.loading-gif').hide();calculateWallHeight();
					});
					break;
			}
		}
	});
	
	
	//document rédigé
	$('.status-update-doc-redac').live('keypress',function(e){
		
		post_type = $('.post-type').val();
		post_user_id= $('.doc-redac-user-id').val();
		post_user_id_affiche= $('.doc-redac-user-id-affiche').val();
		post_group_id= $('.doc-redac-group-id').val();
		message= $(this).val();
		titre = $('#doc-redac-titre').val();
		description = $('#doc-redac-description').val();
		mots = $('#doc-redac-mots').val();
		category = $('#doc-redac-category').val();
		//alert(post_type+':'+post_user_id+':'+post_user_id_affiche+':'+post_group_id+':'+message+':'+titre+':'+description+':'+mots+':'+category);
		var code = (e.keyCode ? e.keyCode : e.which);
 		if(code == 13 && !e.shiftKey) {
			$('.loading-gif').show();
			e.preventDefault();
			$(this).val($(this).text())
			switch (post_type)
			{
				case "home":
					$.post($(location).attr('href'), { USER_ID: post_user_id,TEXT: message,add_post: 1,DESCRIPTION:description,MOTS:mots,CATEGORY:category,TITRE:titre},
					function(data) {
						$('.mur').html('');
						$('.mur').append($('.mur', data).html());
						$('.btn-more-post').html('');
 				$('.btn-more-post').append($('.btn-more-post', data).html());
						clearFormFields({
							clearInputs: true,
							clearTextareas: true,
							passwordFieldText: false,
							addClassFocus: "focus",
							filterClass: "default"
						});
						$('.loading-gif').hide();calculateWallHeight();
					});
					break;
				case "profil":
					$.post($(location).attr('href'), { USER_ID_AFFICHE:post_user_id_affiche,USER_ID: post_user_id,TEXT: message,add_post: 1,DESCRIPTION:description,MOTS:mots,CATEGORY:category,TITRE:titre},
					function(data) {
						$('.mur').html('');
						$('.mur').append($('.mur', data).html());
						$('.btn-more-post').html('');
 						$('.btn-more-post').append($('.btn-more-post', data).html());
						clearFormFields({
							clearInputs: true,
							clearTextareas: true,
							passwordFieldText: false,
							addClassFocus: "focus",
							filterClass: "default"
						});
						$('.loading-gif').hide();calculateWallHeight();
					});
					break;
				case "group":
					
					$.post($(location).attr('href'), { GID:post_group_id,USER_ID: post_user_id,TEXT: message,add_post: "doc-redac",DESCRIPTION:description,MOTS:mots,CATEGORY:category,TITRE:titre},
					function(data) {
						$('.mur').html('');
						$('.mur').append($('.mur', data).html());
						$('.btn-more-post').html('');
 						$('.btn-more-post').append($('.btn-more-post', data).html());
						clearFormFields({
							clearInputs: true,
							clearTextareas: true,
							passwordFieldText: false,
							addClassFocus: "focus",
							filterClass: "default"
						});
						$('.loading-gif').hide();calculateWallHeight();
					});
					break;
			}
		}
	});
	
	//création event
	$('.status-update-event').live('keypress',function(e){
		
		post_type = $('.post-type').val();
		post_user_id= $('.event-user-id').val();
		post_user_id_affiche= $('.event-user-id-affiche').val();
		post_group_id= $('.event-group-id').val();
		message= $(this).val();
		titre = $('#event-titre').val();
		description = $('#event-description').val();
		mots = $('#event-mots').val();
		category = $('#event-category').val();
		lieu = $('#event-lieu').val();
		datedeb = $('#event-datepicker').val();
		datefin = $('#event-datepicker2').val();
		
		var code = (e.keyCode ? e.keyCode : e.which);
 		if(code == 13 && !e.shiftKey) {
			$('.loading-gif').show();
			e.preventDefault();
			$(this).val($(this).text())
			switch (post_type)
			{
				case "home":
			//	alert('DATEFIN:'+datefin);
					$.post($(location).attr('href'), { USER_ID: post_user_id,TEXT: message,add_post: 1,DESCRIPTION:description,MOTS:mots,CATEGORY:category,TITRE:titre,LIEU: lieu,DATEDEB: datedeb,DATEFIN: datefin},
					function(data) {
						$('.mur').html('');
						$('.mur').append($('.mur', data).html());
						$('.btn-more-post').html('');
 				$('.btn-more-post').append($('.btn-more-post', data).html());
						clearFormFields({
							clearInputs: true,
							clearTextareas: true,
							passwordFieldText: false,
							addClassFocus: "focus",
							filterClass: "default"
						});
						$('.loading-gif').hide();calculateWallHeight();
					});
					break;
				case "profil":
					$.post($(location).attr('href'), { USER_ID: post_user_id,TEXT: message,add_post: 1,DESCRIPTION:description,MOTS:mots,CATEGORY:category,TITRE:titre,LIEU: lieu,DATEDEB: datedeb,DATEFIN: datefin},
					function(data) {
						$('.mur').html('');
						$('.mur').append($('.mur', data).html());
						$('.btn-more-post').html('');
 						$('.btn-more-post').append($('.btn-more-post', data).html());
						clearFormFields({
							clearInputs: true,
							clearTextareas: true,
							passwordFieldText: false,
							addClassFocus: "focus",
							filterClass: "default"
						});
						$('.loading-gif').hide();calculateWallHeight();
					});
					break;
				case "group":
					
					$.post($(location).attr('href'), { USER_ID: post_user_id,TEXT: message,add_post: 1,DESCRIPTION:description,MOTS:mots,CATEGORY:category,TITRE:titre,LIEU: lieu,DATEDEB: datedeb,GID: post_group_id,DATEFIN: datefin},
					function(data) {
						$('.mur').html('');
						$('.mur').append($('.mur', data).html());
						$('.btn-more-post').html('');
 						$('.btn-more-post').append($('.btn-more-post', data).html());
						clearFormFields({
							clearInputs: true,
							clearTextareas: true,
							passwordFieldText: false,
							addClassFocus: "focus",
							filterClass: "default"
						});
						$('.loading-gif').hide();calculateWallHeight();
					});
					break;
			}
		}
	});

	//Validation entrer statut
	$('.status-update-lien-url').live('keypress',function(e){
		
		post_type = $('.post-type').val();
		post_user_id= $('.post-user-id').val();
		post_user_id_affiche= $('.post-user-id-affiche').val();
		post_group_id= $('.post-group-id').val();
		message= $(this).val();
		theUrl = $('#lien-url-url').val();
		var code = (e.keyCode ? e.keyCode : e.which);
 		if(code == 13 && !e.shiftKey) {
			$('.loading-gif').show();
			e.preventDefault();
			$(this).val($(this).text())
			switch (post_type)
			{
				case "home":
					$.post($(location).attr('href'), { USER_ID: post_user_id,TEXT: message,add_post: 1,URL: theUrl},
					function(data) {
						$('.mur').html('');
						$('.mur').append($('.mur', data).html());
						$('.btn-more-post').html('');
 				$('.btn-more-post').append($('.btn-more-post', data).html());
						clearFormFields({
							clearInputs: true,
							clearTextareas: true,
							passwordFieldText: false,
							addClassFocus: "focus",
							filterClass: "default"
						});
						$('.loading-gif').hide();calculateWallHeight();
					});
					break;
				case "profil":
					$.post($(location).attr('href'), { USER_ID_AFFICHE:post_user_id_affiche,USER_ID: post_user_id,TEXT: message,add_post: 1,URL: theUrl},
					function(data) {
						$('.mur').html('');
						$('.mur').append($('.mur', data).html());
						$('.btn-more-post').html('');
 						$('.btn-more-post').append($('.btn-more-post', data).html());
						clearFormFields({
							clearInputs: true,
							clearTextareas: true,
							passwordFieldText: false,
							addClassFocus: "focus",
							filterClass: "default"
						});
						$('.loading-gif').hide();calculateWallHeight();
					});
					break;
				case "group":
					$.post($(location).attr('href'), { GID:post_group_id,USER_ID: post_user_id,TEXT: message,add_post: 1,URL: theUrl},
					function(data) {
						$('.mur').html('');
						$('.mur').append($('.mur', data).html());
						$('.btn-more-post').html('');
 						$('.btn-more-post').append($('.btn-more-post', data).html());
						clearFormFields({
							clearInputs: true,
							clearTextareas: true,
							passwordFieldText: false,
							addClassFocus: "focus",
							filterClass: "default"
						});
						$('.loading-gif').hide();calculateWallHeight();
					});
					break;
			}
		}
	});

	
	
	$('.status-submit').live('click',function(e){
		e.preventDefault();
		var e = jQuery.Event("keypress");
		e.which = 13; // # Some key code value
		$(".status-update").trigger(e);
	});
	
	$('.status-submit-video-embeded').live('click',function(e){
		e.preventDefault();
		var e = jQuery.Event("keypress");
		e.which = 13; // # Some key code value
		$(".status-update-video-embeded").trigger(e);
	});

	$('.status-submit-video-lien').live('click',function(e){
		e.preventDefault();
		var e = jQuery.Event("keypress");
		e.which = 13; // # Some key code value
		$(".status-update-video-lien").trigger(e);
	});
		
	$('.status-submit-doc-redac').live('click',function(e){
		e.preventDefault();
		var e = jQuery.Event("keypress");
		e.which = 13; // # Some key code value
		$(".status-update-doc-redac").trigger(e);
	});
	
	$('.status-submit-event').live('click',function(e){
		e.preventDefault();
		var e = jQuery.Event("keypress");
		e.which = 13; // # Some key code value
		$(".status-update-event").trigger(e);
	});
	
	$('.status-submit-lien-url').live('click',function(e){
		e.preventDefault();
		var e = jQuery.Event("keypress");
		e.which = 13; // # Some key code value
		$(".status-update-lien-url").trigger(e);
	});
	
	/*$('.status-submit-photo-ordi').live('click',function(e){		
		e.preventDefault();
		var e = jQuery.Event("keypress");
		e.which = 13; // # Some key code value
		$(".status-update-photo-ordi").trigger(e);
		
	});*/
	
//Comment-btn
	$('.comment-activator').live('click',function(e){
	e.preventDefault();
		$(this).parent().parent().parent().parent().children('.comment-list').children('.comment-li').show();
		$(this).parent().parent().parent().parent().children('.comment-list').children('li').children('.holder').children('.comment-form').children('.textarea').children('textarea').select();
		});
		
	$('.comment-li').live('focusout',function(e){
		$(this).hide();
	});

//tabset
$('.btn-tous').bind('click',function(e){
e.preventDefault();
		var _link = $(this);
		if (!_link.hasClass('active')){
			$('.btn-tous').removeClass('active');
			$('.btn-contacts').removeClass('active');
			$('.btn-groupes').removeClass('active');
			$('.btn-evenements').removeClass('active');
			_link.addClass('active');
			$('.loading-gif').show();
			$.post($(location).attr('href'), {},
  			function(data) {
  				$('.mur').html('');
  				$('.mur').append($('.mur', data).html());
 				$('.btn-more-post').html('');
 				$('.btn-more-post').append($('.btn-more-post', data).html());
				clearFormFields({
					clearInputs: true,
					clearTextareas: true,
					passwordFieldText: false,
					addClassFocus: "focus",
					filterClass: "default"
				});
				$('.loading-gif').hide();calculateWallHeight();
   			});

		}
	});
	
$('.btn-contacts').bind('click',function(e){
e.preventDefault();
		var _link = $(this);
		if (!_link.hasClass('active')){
			$('.btn-tous').removeClass('active');
			$('.btn-contacts').removeClass('active');
			$('.btn-groupes').removeClass('active');
			$('.btn-evenements').removeClass('active');
			_link.addClass('active');
			$('.loading-gif').show();
			$.post($(location).attr('href'), { print_contacts: 1},
  			function(data) {
  				$('.mur').html('');
  				$('.mur').append($('.mur', data).html());
  				$('.btn-more-post').html('');
  				$('.btn-more-post').append($('.btn-more-post', data).html());
				clearFormFields({
					clearInputs: true,
					clearTextareas: true,
					passwordFieldText: false,
					addClassFocus: "focus",
					filterClass: "default"
				});
				$('.loading-gif').hide();calculateWallHeight();
   			});
		}
	});
	
$('.btn-groupes').bind('click',function(e){
e.preventDefault();
		var _link = $(this);
		if (!_link.hasClass('active')){
			$('.btn-tous').removeClass('active');
			$('.btn-contacts').removeClass('active');
			$('.btn-groupes').removeClass('active');
			$('.btn-evenements').removeClass('active');
			_link.addClass('active');
			$('.loading-gif').show();
			$.post($(location).attr('href'), { print_groups: 1},
  			function(data) {
  				$('.mur').html('');
  				$('.mur').append($('.mur', data).html());
  				$('.btn-more-post').html('');
  				$('.btn-more-post').append($('.btn-more-post', data).html());
				clearFormFields({
					clearInputs: true,
					clearTextareas: true,
					passwordFieldText: false,
					addClassFocus: "focus",
					filterClass: "default"
				});
				$('.loading-gif').hide();calculateWallHeight();
   			});
		}
	});
	
	
$('.btn-evenements').bind('click',function(e){
e.preventDefault();

		var _link = $(this);
		if (!_link.hasClass('active')){
			$('.btn-tous').removeClass('active');
			$('.btn-contacts').removeClass('active');
			$('.btn-groupes').removeClass('active');
			$('.btn-evenements').removeClass('active');
			_link.addClass('active');
			$('.loading-gif').show();
			$.post($(location).attr('href'), { print_events: 1},
  			function(data) {
  				$('.mur').html('');
  				$('.mur').append($('.mur', data).html());
  				$('.btn-more-post').html('');
  				$('.btn-more-post').append($('.btn-more-post', data).html());
				clearFormFields({
					clearInputs: true,
					clearTextareas: true,
					passwordFieldText: false,
					addClassFocus: "focus",
					filterClass: "default"
				});
				$('.loading-gif').hide();calculateWallHeight();
				
   			});
		}
	});
	
//Bouton des documents

$('.btn-tous-docs').bind('click',function(e){
e.preventDefault();
		var _link = $(this);
		if (!_link.hasClass('active')){
			$('.btn-tous-docs').removeClass('active');
			$('.btn-audio').removeClass('active');
			$('.btn-docs').removeClass('active');
			$('.btn-photo').removeClass('active');
			$('.btn-video').removeClass('active');
			_link.addClass('active');
			$('.loading-gif').show();
			$.post($(location).attr('href'), {},
  			function(data) {
  				$('.mur').html('');
  				$('.mur').append($('.mur', data).html());
 				$('.btn-more-viewgroup').html('');
 				$('.btn-more-viewgroup').append($('.btn-more-viewgroup', data).html());
				clearFormFields({
					clearInputs: true,
					clearTextareas: true,
					passwordFieldText: false,
					addClassFocus: "focus",
					filterClass: "default"
				});
				$('.loading-gif').hide();calculateWallHeight();
   			});

		}
	});

$('.btn-audio').bind('click',function(e){
e.preventDefault();
		var _link = $(this);
		if (!_link.hasClass('active')){
			$('.btn-tous-docs').removeClass('active');
			$('.btn-audio').removeClass('active');
			$('.btn-docs').removeClass('active');
			$('.btn-photo').removeClass('active');
			$('.btn-video').removeClass('active');
			_link.addClass('active');
			$('.loading-gif').show();
			$.post($(location).attr('href'), { print_audio: 1},
  			function(data) {
  				$('.mur').html('');
  				$('.mur').append($('.mur', data).html());
  				$('.btn-more-viewgroup').html('');
  				$('.btn-more-viewgroup').append($('.btn-more-viewgroup', data).html());
				clearFormFields({
					clearInputs: true,
					clearTextareas: true,
					passwordFieldText: false,
					addClassFocus: "focus",
					filterClass: "default"
				});
				$('.loading-gif').hide();calculateWallHeight();
   			});
		}
	});
	
$('.btn-photo').bind('click',function(e){
e.preventDefault();
		var _link = $(this);
		if (!_link.hasClass('active')){
			$('.btn-tous-docs').removeClass('active');
			$('.btn-audio').removeClass('active');
			$('.btn-docs').removeClass('active');
			$('.btn-photo').removeClass('active');
			$('.btn-video').removeClass('active');
			_link.addClass('active');
			$('.loading-gif').show();
			$.post($(location).attr('href'), { print_photo: 1},
  			function(data) {
  				$('.mur').html('');
  				$('.mur').append($('.mur', data).html());
  				$('.btn-more-viewgroup').html('');
  				$('.btn-more-viewgroup').append($('.btn-more-viewgroup', data).html());
				clearFormFields({
					clearInputs: true,
					clearTextareas: true,
					passwordFieldText: false,
					addClassFocus: "focus",
					filterClass: "default"
				});
				$('.loading-gif').hide();calculateWallHeight();
   			});
		}
	});
	
$('.btn-photo-ext').bind('click',function(e){
e.preventDefault();
		var _link = $(this);
		if (!_link.hasClass('active')){
			_link.addClass('active');
			url = "/media/media.php";
			$.post($(location).attr('href',url), { print_photo: 1},
  			function(data) {
  				$('.mur').html('');
  				$('.mur').append($('.mur', data).html());
  				$('.btn-more-viewgroup').html('');
  				$('.btn-more-viewgroup').append($('.btn-more-viewgroup', data).html());
				clearFormFields({
					clearInputs: true,
					clearTextareas: true,
					passwordFieldText: false,
					addClassFocus: "focus",
					filterClass: "default"
				});
   			});
		}
	});
	
$('.btn-docs').bind('click',function(e){
e.preventDefault();
		var _link = $(this);
		if (!_link.hasClass('active')){
			$('.btn-tous-docs').removeClass('active');
			$('.btn-audio').removeClass('active');
			$('.btn-docs').removeClass('active');
			$('.btn-photo').removeClass('active');
			$('.btn-video').removeClass('active');
			_link.addClass('active');
			$('.loading-gif').show();
			$.post($(location).attr('href'), { print_document: 1},
  			function(data) {
  				$('.mur').html('');
  				$('.mur').append($('.mur', data).html());
  				$('.btn-more-viewgroup').html('');
  				$('.btn-more-viewgroup').append($('.btn-more-viewgroup', data).html());
				clearFormFields({
					clearInputs: true,
					clearTextareas: true,
					passwordFieldText: false,
					addClassFocus: "focus",
					filterClass: "default"
				});
				$('.loading-gif').hide();calculateWallHeight();
   			});
		}
	});
	
$('.btn-video').bind('click',function(e){
e.preventDefault();
		var _link = $(this);
		if (!_link.hasClass('active')){
			$('.btn-tous-docs').removeClass('active');
			$('.btn-audio').removeClass('active');
			$('.btn-docs').removeClass('active');
			$('.btn-photo').removeClass('active');
			$('.btn-video').removeClass('active');
			_link.addClass('active');
			$('.loading-gif').show();
			$.post($(location).attr('href'), { print_video: 1},
  			function(data) {
  				$('.mur').html('');
  				$('.mur').append($('.mur', data).html());
  				$('.btn-more-viewgroup').html('');
  				$('.btn-more-viewgroup').append($('.btn-more-viewgroup', data).html());
				clearFormFields({
					clearInputs: true,
					clearTextareas: true,
					passwordFieldText: false,
					addClassFocus: "focus",
					filterClass: "default"
				});
				$('.loading-gif').hide();calculateWallHeight();
   			});
		}
	});
	
	
	
//More BTN
$('.btn-plus').live('click',function(e){
	e.preventDefault();
			num_post = $('.last_post').val();
			if(num_post!="")
			{
				$.post($(location).attr('href'), { last_post:num_post},
  				function(data) {
  					//alert($('.comment-'+id_parent, data).html());
  					$('.mur').append($('.mur', data).html());
  					$('.last_post').val(($('.last_post', data).val()));
					clearFormFields({
						clearInputs: true,
						clearTextareas: true,
						passwordFieldText: false,
						addClassFocus: "focus",
						filterClass: "default"
					});
   				});
			}
	});
	
$('.btn-plus-docs').live('click',function(e){
	e.preventDefault();
			num_post = $('.last_post').val();
			if(num_post!="")
			{
				$.post($(location).attr('href'), { last_post:num_post},
  				function(data) {
  					//alert($('.comment-'+id_parent, data).html());
  					$('.mur').append($('.mur', data).html());
  					$('.last_post').val(($('.last_post', data).val()));
					clearFormFields({
						clearInputs: true,
						clearTextareas: true,
						passwordFieldText: false,
						addClassFocus: "focus",
						filterClass: "default"
					});
   				});
			}
	});

//tabs
	$('.tabs').jqueryTabs();
	$('a.tab[href="#tab2"]').bind('hidetab', function(){
		var _link = $(this);
		var _id = _link.attr('href');
		if (_link.hasClass('active')){
			$(_id).children('.tab-section').hide();
			$(_id).children('.sub-tabs').show().find('.subtab').removeClass('active');
			$(_id).hide();
			_link.removeClass('active');
		}
	});
	
	$('a.tab[href="#tab3"]').bind('hidetab', function(){
		var _link = $(this);
		var _id = _link.attr('href');
		if (_link.hasClass('active')){
			$(_id).children('.tab-section').hide();
			$(_id).children('.sub-tabs').show().find('.subtab').removeClass('active');
			$(_id).hide();
			_link.removeClass('active');
		}
	});
	
	$('a.tab[href="#tab4"]').bind('hidetab', function(){
		var _link = $(this);
		var _id = _link.attr('href');
		if (_link.hasClass('active')){
			$(_id).children('.tab-section').hide();
			$(_id).children('.sub-tabs').show().find('.subtab').removeClass('active');
			$(_id).hide();
			_link.removeClass('active');
		}
	});
	
	$('a.tab[href="#tab5"]').bind('hidetab', function(){
		var _link = $(this);
		var _id = _link.attr('href');
		if (_link.hasClass('active')){
			$(_id).children('.tab-section').hide();
			$(_id).children('.sub-tabs').show().find('.subtab').removeClass('active');
			$(_id).hide();
			_link.removeClass('active');
		}
	});
	
	$('a.tab[href="#tab6"]').bind('hidetab', function(){
		var _link = $(this);
		var _id = _link.attr('href');
		if (_link.hasClass('active')){
			$(_id).children('.tab-section').hide();
			$(_id).children('.sub-tabs').show().find('.subtab').removeClass('active');
			$(_id).hide();
			_link.removeClass('active');
		}
	});
	
	$('a.tab[href="#tab7"]').bind('hidetab', function(){
		var _link = $(this);
		var _id = _link.attr('href');
		if (_link.hasClass('active')){
			$(_id).children('.tab-section').hide();
			$(_id).children('.sub-tabs').show().find('.subtab').removeClass('active');
			$(_id).hide();
			_link.removeClass('active');
		}
	});

	
	$('.sub-tabs').jqueryTabs({
		tabLinks: 'a.subtab',
		onChange: function(_tabset){
			_tabset.hide();
		}
	});
}

function initModules(){
	$('.module').each(function(){
		var _holder = $(this);
		var _btnClose = $('.btn-close', _holder);
		_btnClose.click(function(){
			_holder.slideUp(500, function(){
				_holder.remove();
			});
			return false;
		})
		_holder.openClose({
			linkSlide:'.btn-down',
			slideBlock: '.module-content'
		})
	})
}

function initPage(){
	clearFormFields({
		clearInputs: true,
		clearTextareas: true,
		passwordFieldText: false,
		addClassFocus: "focus",
		filterClass: "default"
	});
}


$.fn.openClose = function(_opt){
	var _options = $.extend({
		linkSlide: 'a.open-close', //if parent - slide on click or hover on parent block
		slideBlock: '.slide',
		openClass : 'active',
		openLinkClass: false,
		textOpen : false,
		textClose : false,
		duration: 500,
		event: 'click' //click or hover
	}, _opt);
	var _enabledClass = 'slide-enabled';

	return this.each(function(){
		if ($(this).hasClass(_enabledClass)) return;
		var _parentSlide = $(this),
			_slideBlock = $(_options.slideBlock, _parentSlide),
			_openClassS = _options.openClass,
			_textOpenS = _options.textOpen,
			_textCloseS = _options.textClose,
			_durationSlide = _options.duration,
			_openLinkClass = _options.openLinkClass,
			_t, _linkSlide;
			if (_options.linkSlide == 'parent') _linkSlide = _parentSlide
				else _linkSlide = $(_options.linkSlide, _parentSlide);
		
		_parentSlide.addClass(_enabledClass);
		var _slideH = _slideBlock.height();
		if (!_parentSlide.is('.'+_openClassS)) {
			if (_options.event != 'click') _slideBlock.css({
				'display':'none',
				'height':0
			});
			else _slideBlock.hide();
		}

		//slide on click
		if (_options.event == 'click'){
			_linkSlide.click(function(){
				if (_parentSlide.is('.'+_openClassS)) {
					_parentSlide.trigger('closeStart');
					if (_openLinkClass) _linkSlide.removeClass(_openLinkClass);
					_slideBlock.slideUp(_durationSlide, function(){
						_parentSlide.removeClass(_openClassS);
						_parentSlide.trigger('closeEnd')
					});
					if (_textOpenS) $(this).text(_textOpenS);
				} else {
					_parentSlide.trigger('openStart');
					if (_openLinkClass) _linkSlide.addClass(_openLinkClass);
					_slideBlock.slideDown(_durationSlide, function(){
						_parentSlide.addClass(_openClassS);
						_parentSlide.trigger('openEnd')
					});
					if (_textCloseS) $(this).text(_textCloseS);
				}
				return false;
			});
		}

		//slide on hover
		else if (_options.event == 'hover'){
			_parentSlide.removeClass(_openClassS);
			var _t;
			_parentSlide.mouseleave(function(){
				if (_t) clearTimeout(_t);
				_t = setTimeout(function(){
					_parentSlide.trigger('closeStart');
					if (_openLinkClass) _linkSlide.removeClass(_openLinkClass);
					_slideBlock.stop().animate({
						'height':0
					}, _durationSlide, function(){
						_parentSlide.removeClass(_openClassS);
						_parentSlide.trigger('closeEnd')
					});
					if (_textOpenS) $(this).text(_textOpenS);
				}, 100)
			}).mouseenter(function(){
				if (_t) clearTimeout(_t);
				_t = setTimeout(function(){
					_parentSlide.trigger('openStart');
					if (_openLinkClass) _linkSlide.addClass(_openLinkClass);
					_slideBlock.show().stop().animate({
						'height': _slideH
					}, _durationSlide, function(){
						_parentSlide.addClass(_openClassS);
						_parentSlide.trigger('openEnd')
					});
					if (_textCloseS) $(this).text(_textCloseS);
				}, 100)
			})
		}
	})
}

// jquery tabs plugin
jQuery.fn.jqueryTabs = function(_options){
	// default options
	var _options = jQuery.extend({
		addToParent:false,
		holdHeight:false,
		activeClass:'active',
		tabLinks:'a.tab',
		fadeSpeed:0,
		event:'click',
		onChange: false
	},_options);

	return this.each(function(){
		var _holder = jQuery(this);
		var _fadeSpeed = _options.fadeSpeed;
		var _activeClass = _options.activeClass;
		var _addToParent = _options.addToParent;
		var _holdHeight = _options.holdHeight;
		var _tabLinks = jQuery(_options.tabLinks, _holder);
		var _tabset = (_addToParent ? _tabLinks.parent() : _tabLinks);
		var _event = _options.event;
		var _animating = false;
		var onChange = _options.onChange;

		var loc=window.location.hash.toString();
		
		// tabs init
		_tabLinks.each(function(){
			var _tmpLink = jQuery(this);
			var _tmpTab = jQuery(_tmpLink.attr('href'));
			var _classItem = (_addToParent ? _tmpLink.parent() : _tmpLink);
			if(_tmpTab.length) {
				if (_tmpLink.attr('href') == loc){
					_tmpTab.show();
					_tabLinks.removeClass(_activeClass); 
					_classItem.addClass(_activeClass);
				}
				else if(_classItem.hasClass(_activeClass) && (loc == '' || $(loc).length == 0)) _tmpTab.show();
				else _tmpTab.hide();
			}
		});


		// tab switcher
		function switchTab(_switcher) {
			
			if(!_animating) {
				var _link = jQuery(_switcher);
				var _newItem = (_addToParent ? _link.parent() : _link);
				var _newTab = jQuery(_link.attr('href'));
				if(_newItem.hasClass(_activeClass)) {
					_newItem.trigger('hidetab');
					return;
				}

				var _oldItem = jQuery(_addToParent ? _tabset : _tabLinks).filter('.'+_activeClass);
				var _oldTab = jQuery(jQuery(_addToParent ? _oldItem.children('a') : _oldItem).attr('href'));
				if(_newTab.length) {
					_animating = true;
					if(_oldItem.length) {
						_newItem.addClass(_activeClass);
						_oldItem.removeClass(_activeClass);

						var _parent = _oldTab.parent();
						if(_holdHeight) _parent.css({height:_parent.height()});

						_oldTab.fadeOut(_fadeSpeed,function(){
							_newTab.fadeIn(_fadeSpeed,function(){
								_animating = false;
							});
							if(_holdHeight) _parent.css({height:'auto'});
						});
					} else {
						_newItem.addClass(_activeClass);
						_newTab.fadeIn(_fadeSpeed,function(){
							_animating = false;
						});
					}
				}
				if (onChange) onChange(_holder, _tabLinks)
			}
		}

		// control
		_tabLinks.each(function(){
			jQuery(this).bind(_event,function(){
				switchTab(this);
				return false;
			});
		});
	});
}

function clearFormFields(o)
{
	//Hide all unbound links
	//$('a[href="#"]').hide();
	
	if (o.clearInputs == null) o.clearInputs = true;
	if (o.clearTextareas == null) o.clearTextareas = true;
	if (o.passwordFieldText == null) o.passwordFieldText = false;
	if (o.addClassFocus == null) o.addClassFocus = false;
	if (!o.filterClass) o.filterClass = "default";
	if(o.clearInputs) {
		var inputs = document.getElementsByTagName("input");
		for (var i = 0; i < inputs.length; i++ ) {
			if((inputs[i].type == "text" || inputs[i].type == "password") && inputs[i].className.indexOf(o.filterClass) == -1) {
				inputs[i].valueHtml = inputs[i].value;
				inputs[i].onfocus = function ()	{
					if(this.valueHtml == this.value) this.value = "";
					if(this.fake) {
						inputsSwap(this, this.previousSibling);
						this.previousSibling.focus();
					}
					if(o.addClassFocus && !this.fake) {
						this.className += " " + o.addClassFocus;
						this.parentNode.className += " parent-" + o.addClassFocus;
					}
				}
				inputs[i].onblur = function () {
					if(this.value == "") {
						this.value = this.valueHtml;
						if(o.passwordFieldText && this.type == "password") inputsSwap(this, this.nextSibling);
					}
					if(o.addClassFocus) {
						this.className = this.className.replace(o.addClassFocus, "");
						this.parentNode.className = this.parentNode.className.replace("parent-"+o.addClassFocus, "");
					}
				}
				if(o.passwordFieldText && inputs[i].type == "password") {
					var fakeInput = document.createElement("input");
					fakeInput.type = "text";
					fakeInput.value = inputs[i].value;
					fakeInput.className = inputs[i].className;
					fakeInput.fake = true;
					inputs[i].parentNode.insertBefore(fakeInput, inputs[i].nextSibling);
					inputsSwap(inputs[i], null);
				}
			}
		}
	}
	if(o.clearTextareas) {
		var textareas = document.getElementsByTagName("textarea");
		for(var i=0; i<textareas.length; i++) {
			if(textareas[i].className.indexOf(o.filterClass) == -1) {
				textareas[i].valueHtml = textareas[i].value;
				textareas[i].onfocus = function() {
					if(this.value == this.valueHtml) this.value = "";
					if(o.addClassFocus) {
						this.className += " " + o.addClassFocus;
						this.parentNode.className += " parent-" + o.addClassFocus;
					}
				}
				textareas[i].onblur = function() {
					if(this.value == "") this.value = this.valueHtml;
					if(o.addClassFocus) {
						this.className = this.className.replace(o.addClassFocus, "");
						this.parentNode.className = this.parentNode.className.replace("parent-"+o.addClassFocus, "");
					}
				}
			}
		}
	}
	function inputsSwap(el, el2) {
		if(el) el.style.display = "none";
		if(el2) el2.style.display = "inline";
	}
}
