var usertimer;
var userelm;
var cleditnow=false;

function bjah_alert(val)
{
	$.prompt(val, {opacity: 0});
}

function trim(sInString){
sInString = sInString.replace(/ /g,' ');
return sInString.replace(/(^\s+)|(\s+$)/g, "");
}

function showuser(elm)
{
	userelm=elm;
	$('#usershowdiv').css("top", $(elm).offset().top+$(elm).height()-1);
	$('#usershowdiv').css("left", $(elm).offset().left);
	$('#usershowdiv').html('Загрузка...');
	usertimer=setTimeout("loadshowuser()", 1000);
	
}

function loadshowuser()
{
	$('#usershowdiv').load('ajax/user/show_user.php', {id: $(userelm).attr("rel")});
	doshowuser();
}

function doshowuser()
{
	$('#usershowdiv').show();
}

function hideuser()
{
	clearTimeout(usertimer);
	//$('#usershowdiv').html();
	$('#usershowdiv').hide();
}

function shbl(block, mode)
{
	if (mode==0)
	{
		$('#'+block).val(mode);
		$('#'+block+'_block_off').show();
		$('#'+block+'_block_on').hide();
	}
	
	if (mode==1)
	{
		$('#'+block).val(mode);
		$('#'+block+'_block_off').hide();
		$('#'+block+'_block_on').show();
	}
}


function home_save()
{
	$('#name_form').val($('#name_edit').val());
	$('#ajax-loader').show();
	if (trim($('#name_form').val())=='') {bjah_alert("Ты не заполнил название дома!"); $('#ajax-loader').hide(); return false;}
	//if ($('#greeting_form').val()=='') {bjah_alert("Не заполнено поле приветствие!"); return false;}
	$('#edithomeform').submit();
	return false;
}


function refresh_users()
{
	$('#home-users').load("/ajax/home/home_users.php", {home: home, mode: mode, status: 'family'});
	//$('#friends').load("/ajax/home/home_users.php", {home: home, mode: mode, status: 'friends'});
	//$('#guests').load("/ajax/home/home_users.php", {home: home, mode: mode, status: 'guests'});
}

function saveuser(id)
{
	var propiska;
	if ($('#user_status').val()=='delete')
	{
		if (!confirm('Ты точно хочешь выгнать этого пользователя из дома?'))
		{
			$('#user-menu').html('Загрузка...');
			$('#user-menu').load('ajax/home/show-user.php', {user: id, mode: 'edit', home:home});
			return false;
		}
	}
	if (document.getElementById('user-propiska').checked) propiska="true"; else propiska="false";
	$('#temp-ajax-div').load("/ajax/home/user_edit.php", {user: id, home: home, status: $('#user_status').val(), propiska: propiska});
	$('#user-menu').hide();
	setTimeout("refresh_users()", 3000);
	//bjah_alert(propiska);
}

function saveuser_big(id)
{
	var propiska;
	if ($('#user_status').val()=='delete')
	{
		if (!confirm('Ты точно хочешь выгнать этого пользователя из дома?'))
		{
			$('#user-menu').html('Загрузка...');
			$('#user-menu').load('ajax/home/show-user-big.php', {user: id, mode: 'edit', home:home});
			return false;
		}
	}
	if (document.getElementById('user-propiska').checked) propiska="true"; else propiska="false";
	$('#temp-ajax-div').load("/ajax/home/user_edit-big.php", {user: id, home: home, status: $('#user_status').val(), propiska: propiska});
	$('#user-menu').hide();
	/*if ($('#user_status').val()=='delete')
	{
		//bjah_alert(request_uri);
		setTimeout("function(){location.href=request_uri;}", 3000);
		//location.href=request_uri;
	}*/
}

function deletefalbum(id)
{
	$('#f_al_'+id).load('ajax/home/photo/photo-al-del.php', {id: id});
	hideuserdiv();
	return false;
}

function deletevalbum(id)
{
	$('#v_al_'+id).load('ajax/home/video/video-al-del.php', {id: id});
	hideuserdiv();
	return false;
}

function dofedit(id)
{
	$('#f_al_n_'+id).load('ajax/home/photo/photo-al-doedit.php', {id: id, name: $('#f_ed_name').val(), level: $('#f_ed_level').val()});
	hideuserdiv();
	return false;
}

function dovedit(id)
{
	$('#v_al_n_'+id).load('ajax/home/video/video-al-doedit.php', {id: id, name: $('#v_ed_name').val(), level: $('#v_ed_level').val()});
	hideuserdiv();
	return false;
}

function addcl()
{
	if (trim($('#addclassifiedstext').val())=='') {bjah_alert("Не забывай ввести текст сообщения!"); return false;}
	var cltext=$('#addclassifiedstext').val();
	//$('#addclassifieds').hide();
	$('#addclassifieds').css('visibility', 'hidden');
	$('#classifieds').load('ajax/home/classifieds.php', {action: 'add', homeid: home, text: cltext, mode: mode});
	$('#addclassifiedstext').val('');
}

function editcl(id)
{
	if (cleditnow) return false;
	cleditnow=true;
	var edittext=$('#cl_'+id).html();
	$('#cl_'+id).html("<textarea class=\"text-input\" style=\"width: 90%; height: 50px;\" id=\"ecl_"+id+"\" maxlength=\"160\" onkeypress=\"return isNotMax(event)\">"+edittext+"</textarea><br><img src=\"images/structure/but_save.gif\" style=\"cursor: pointer;\" onClick=\"doeditcl("+id+")\">");
}

function doeditcl(id)
{
	cleditnow=false;
	var cltext=$('#ecl_'+id).val();
	if (trim(cltext)=='') {bjah_alert("Не забывай ввести текст сообщения!"); return false;}
	$('#classifieds').load('ajax/home/classifieds.php', {action: 'edit', homeid: home, msgid: id, mode: mode, text: cltext});
}

function editcl_big(id)
{
	if (cleditnow) return false;
	cleditnow=true;
	var edittext=$('#cl_'+id).html();
	$('#cl_'+id).html("<textarea class=\"text-input\" style=\"width: 90%; height: 50px;\" id=\"ecl_"+id+"\" maxlength=\"160\" onkeypress=\"return isNotMax(event)\">"+edittext+"</textarea><br><img src=\"images/structure/but_save.gif\" style=\"cursor: pointer;\" onClick=\"doeditcl_big("+id+")\">");
}

function doeditcl_big(id)
{
	cleditnow=false;
	var cltext=$('#ecl_'+id).val();
	$('#cl_'+id).html('');
	if (trim(cltext)=='') {bjah_alert("Не забывай ввести текст сообщения!"); return false;}
	$('#cl_'+id).load('ajax/home/edit_classifieds.php', {id: id, text: cltext, action: 'edit'});
}

function deletecl_big(id)
{
	if (confirm('Ты уверен, что хочешь удалить?'))
	{
		$('#cl_over_'+id).remove();
		$('#temp-ajax-div').load('ajax/home/edit_classifieds.php', {id: id, action: 'delete'});
	}
}

function addcl_big(homeid, text, mode)
{
	if (trim(text)=='') {bjah_alert("Не забывай ввести текст сообщения!"); return false;}
	$('#temp-ajax-div').load('ajax/home/add_classifieds.php', {homeid: homeid, text: text, mode: mode});
	$('#add-cl').hide();
	$('#cl-text').val('')
}


function showuserdiv(obj, directId, event, mode) {
	$('#user-menu').html('Загрузка...');
	$('#user-menu').css('z-index', '1000');
	$('#bgwrp').css('background', 'transparent');
	$('#bgwrp').css('top', '0');
	$('#bgwrp').css('height', $('.pre-footer').height());
	$('#bgwrp').css('left', '0');
	$('#bgwrp').css('width', $('body').width());
	$('#bgwrp').css('z-index', '900');
	$('#bgwrp').show();
	//obj.blur();
	if(navigator.userAgent.indexOf("MSIE") != -1) event = window.event;
	var usermenu = document.getElementById('user-menu');
	usermenu.style.left = (event.clientX + getScrollLeft() + 15) + 'px';
	usermenu.style.top = (event.clientY + getScrollTop() + 5) + 'px';
	$('#user-menu').load('ajax/home/show-user.php', {user: directId, mode: mode, home:home});
	$('#user-menu').show();
	return cancelEvent(event);
}

function showuserdiv_big(obj, directId, event) {
	$('#user-menu').html('Загрузка...');
	$('#user-menu').css('z-index', '1000');
	$('#bgwrp').css('background', 'transparent');
	$('#bgwrp').css('top', '0');
	$('#bgwrp').css('height', $('.pre-footer').height());
	$('#bgwrp').css('left', '0');
	$('#bgwrp').css('width', $('body').width());
	$('#bgwrp').css('z-index', '900');
	$('#bgwrp').show();
	//obj.blur();
	if(navigator.userAgent.indexOf("MSIE") != -1) event = window.event;
	var usermenu = document.getElementById('user-menu');
	usermenu.style.left = (event.clientX + getScrollLeft() + 15) + 'px';
	usermenu.style.top = (event.clientY + getScrollTop() + 5) + 'px';
	$('#user-menu').load('ajax/home/show-user-big.php', {user: directId, mode: mode, home:home});
	$('#user-menu').show();
	return cancelEvent(event);
}

function showuserdiv_oi(obj, user, event)
{
	$('#user-menu').html('Загрузка...');
	$('#user-menu').css('z-index', '1000');
	$('#bgwrp').css('background', 'transparent');
	$('#bgwrp').css('top', '0');
	$('#bgwrp').css('height', $('.pre-footer').height());
	$('#bgwrp').css('left', '0');
	$('#bgwrp').css('width', $('body').width());
	$('#bgwrp').css('z-index', '900');
	$('#bgwrp').show();
	//obj.blur();
	if(navigator.userAgent.indexOf("MSIE") != -1) event = window.event;
	var usermenu = document.getElementById('user-menu');
	usermenu.style.left = (event.clientX + getScrollLeft() + 15) + 'px';
	usermenu.style.top = (event.clientY + getScrollTop() + 5) + 'px';
	$('#user-menu').load('ajax/oi/show-user.php', {user: user});
	$('#user-menu').show();
	return cancelEvent(event);
}

function showuserdiv_nh(obj, directId, event)
{
	$('#user-menu').html('Загрузка...');
	$('#user-menu').css('z-index', '1000');
	$('#bgwrp').css('background', 'transparent');
	$('#bgwrp').css('top', '0');
	$('#bgwrp').css('height', $('.pre-footer').height());
	$('#bgwrp').css('left', '0');
	$('#bgwrp').css('width', $('body').width());
	$('#bgwrp').css('z-index', '900');
	$('#bgwrp').show();
	//obj.blur();
	if(navigator.userAgent.indexOf("MSIE") != -1) event = window.event;
	var usermenu = document.getElementById('user-menu');
	usermenu.style.left = (event.clientX + getScrollLeft() + 15) + 'px';
	usermenu.style.top = (event.clientY + getScrollTop() + 5) + 'px';
	$('#user-menu').load('ajax/show-user.php', {user: directId});
	$('#user-menu').show();
	return cancelEvent(event);
}

function hideuserdiv()
{
	if ($('#user-menu2').css('display')=='block' && $('#user-menu').css('display')=='block')
	{
		$('#user-menu2').hide();
		return false;
	}
	$('#user-menu2').hide();
	$('#bgwrp').hide();
	$('#user-menu').hide();
	$('#this-invite').removeAttr('id');
}

function showphotodiv(id, event)
{
	$('#user-menu').html('Загрузка...');
	$('#user-menu').css('z-index', '1000');
	$('#bgwrp').css('background', 'transparent');
	$('#bgwrp').css('top', '0');
	$('#bgwrp').css('height', $('.pre-footer').height());
	$('#bgwrp').css('left', '0');
	$('#bgwrp').css('width', $('body').width());
	$('#bgwrp').css('z-index', '900');
	$('#bgwrp').show();
	if(navigator.userAgent.indexOf("MSIE") != -1) event = window.event;
	var usermenu = document.getElementById('user-menu');
	$('#user-menu').show('');
	usermenu.style.left = (event.clientX + getScrollLeft() + 15) + 'px';
	usermenu.style.top = (event.clientY + getScrollTop() + 5) + 'px';
	$('#user-menu').load('ajax/home/photo/photo-al-edit.php', {id: id});
	return cancelEvent(event);
}

function showvideodiv(id, event)
{
	$('#user-menu').html('Загрузка...');
	$('#user-menu').css('z-index', '1000');
	$('#bgwrp').css('background', 'transparent');
	$('#bgwrp').css('top', '0');
	$('#bgwrp').css('height', $('.pre-footer').height());
	$('#bgwrp').css('left', '0');
	$('#bgwrp').css('width', $('body').width());
	$('#bgwrp').css('z-index', '900');
	$('#bgwrp').show();
	if(navigator.userAgent.indexOf("MSIE") != -1) event = window.event;
	var usermenu = document.getElementById('user-menu');
	$('#user-menu').show('');
	usermenu.style.left = (event.clientX + getScrollLeft() + 15) + 'px';
	usermenu.style.top = (event.clientY + getScrollTop() + 5) + 'px';
	$('#user-menu').load('ajax/home/video/video-al-edit.php', {id: id});
	return cancelEvent(event);
}

function htmlspecialchars(text)
{
   var chars = Array("<", ">", '"', "'");
   var replacements = Array("&lt;", "&gt;", "&quot;", "'");
   for (var i=0; i<chars.length; i++)
   {
       var re = new RegExp(chars[i], "gi");
       if(re.test(text))
       {
           text = text.replace(re, replacements[i]);
       }
	   
	   
	   
   }
	return text;
}

function addsmiles(text)
{
	text=text.replace(":)", "<img src=\"images/smiles/1.gif\">");
	text=text.replace(":-)", "<img src=\"images/smiles/1.gif\">");
	text=text.replace(":(", "<img src=\"images/smiles/2.gif\">");
	text=text.replace(":-(", "<img src=\"images/smiles/2.gif\">");
	text=text.replace(";)", "<img src=\"images/smiles/3.gif\">");
	text=text.replace(";-)", "<img src=\"images/smiles/3.gif\">");
	text=text.replace(":P", "<img src=\"images/smiles/4.gif\">");
	text=text.replace("8)", "<img src=\"images/smiles/5.gif\">");
	text=text.replace("8-)", "<img src=\"images/smiles/5.gif\">");
	text=text.replace(":D", "<img src=\"images/smiles/6.gif\">");
	text=text.replace(":-[", "<img src=\"images/smiles/7.gif\">");
	text=text.replace("=-0", "<img src=\"images/smiles/8.gif\">");
	text=text.replace(":-*", "<img src=\"images/smiles/9.gif\">");
	text=text.replace(":`(", "<img src=\"images/smiles/10.gif\">");
	text=text.replace("*BEER*", "<img src=\"images/smiles/11.gif\">");
	text=text.replace("*LOL*", "<img src=\"images/smiles/12.gif\">");
	text=text.replace("*YAHOO*", "<img src=\"images/smiles/13.gif\">");
   return text;
}


function addmessage()
{	
	if (settimer==true) {clearTimeout(timid); settimer=false;}
	var str = $('#chat-input').val();
	$('#chat-input').val('');
	if (trim(str)!='')
	{
		$('#empty').load('ajax/home/chat-add.php', {msg: str, prvmsg: prvmsg, home: home});
		remprv();

		var tmp = $('#chat-messages').html() + "<b class=\"dsct-nick\">" + user_in_chat + "</b><span class=\"dsct-message\">" + addsmiles(htmlspecialchars(str)) + "</span><br>";
		
		$('#chat-messages').html(tmp);
		
		$('#chat-input').val('');
		$('#chat-scroll').scrollTop($('#chat-messages').height());
		$('#chat-input').focus();
		
	refresh();
	}
	return false;
}

function refresh()
{	
	if (settimer==true) {clearTimeout(timid); settimer=false;}
	if($('#tmp').html()!='')
	{
		var tmp=$('#tmp').html();
		tmp = $('#chat-messages').html() + tmp;
		$('#chat-messages').html(tmp);
		$('#tmp').html('');
		$('#chat-scroll').scrollTop($('#chat-messages').height());
		settimer=true;
		timid=setTimeout("refresh()", 3000);
		return true;
	}
	onlval++;
	if (onlval>=5)
	{
		onlval=0;
		refreshonline();
		return true;
	}
	$('#tmp').load('ajax/home/chat-refresh.php', {home: home});
		settimer=true;
		timid=setTimeout("refresh()", 3000);
		return true;
}

function refreshonline()
{
	if (settimer==true) {clearTimeout(timid); settimer=false;}
	$('#chat-online').load('ajax/home/chat-online.php', {home: home});
	settimer=true;
	timid=setTimeout("refresh()", 3000);
	return true;
}

function smile(elm)
{
	if($('#smilebox').css("display")=='none')
	{
		$('#smilebox').css("top",$(elm).offset().top - 260);
		$('#smilebox').css("left",$(elm).offset().left-300);
		$('#smilebox').show();
	}
	else
		$('#smilebox').hide();
		
	return false;
}

function emoticon(text)
{
	var txtarea = document.getElementById('chat-input');
	text = ' ' + text + ' ';
	if (txtarea.createTextRange && txtarea.caretPos)
	{
		var caretPos = txtarea.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
		txtarea.focus();
	}
	else
	{
		txtarea.value  += text;
		txtarea.focus();
	}
	$('#smilebox').hide();
}

function addprv(name, id)
{
	if (id==user) return false;
	prvmsg=id;
	$('#prvdiv').html("Личное сообщение для <b>"+name+"</b> (<a href=\"#\" onClick=\"remprv(); return false;\">Отмена</a>)");
	$('#prvdiv').show();
	$('#chat-input').focus();
}

function remprv()
{
	prvmsg=0;
	$('#prvdiv').html("");
	$('#prvdiv').hide();
	$('#chat-input').focus();
}

function addphotocomment(photo)
{
	if ($('#commenttext').val()!='')
	{
		var tmN=new Date();
		var dH=''+tmN.getHours();dH=dH.length<2?'0'+dH:dH;
		var dM=''+tmN.getMinutes();dM=dM.length<2?'0'+dM:dM;
		var dS=''+tmN.getSeconds();dS=dS.length<2?'0'+dS:dS;
		var day=''+tmN.getDate();day=day.length<2?'0'+day:day;
		var year=''+tmN.getFullYear();
		var month=tmN.getMonth()+1;month=month<10?'0'+month:month;
		var newid='comm'+day+month+year+dH+dM+dS;

	
		var tmp=$('#comments').html();
		var txt=$('#commenttext').val();
		$('#commenttext').val('');
		tmp = tmp + "<div id=\""+newid+"\" style=\"display: none;\">Загрузка...</div>";
		$('#comments').html(tmp)
		
		$('#'+newid).load('ajax/home/photo/photo-add-comm.php', {text: txt, photo: photo});
		
	}
}

function addvideocomment(video)
{
	if ($('#commenttext').val()!='')
	{
		var tmN=new Date();
		var dH=''+tmN.getHours();dH=dH.length<2?'0'+dH:dH;
		var dM=''+tmN.getMinutes();dM=dM.length<2?'0'+dM:dM;
		var dS=''+tmN.getSeconds();dS=dS.length<2?'0'+dS:dS;
		var day=''+tmN.getDate();day=day.length<2?'0'+day:day;
		var year=''+tmN.getFullYear();
		var month=tmN.getMonth()+1;month=month<10?'0'+month:month;
		var newid='comm'+day+month+year+dH+dM+dS;

	
		var tmp=$('#comments').html();
		var txt=$('#commenttext').val();
		$('#commenttext').val('');
		tmp = tmp + "<div id=\""+newid+"\" style=\"display: none;\">Загрузка...</div>";
		$('#comments').html(tmp)
		
		$('#'+newid).load('ajax/home/video/video-add-comm.php', {text: txt, video: video});
		
	}
}

function loadmessageshref()
{
	$('#messageshref').load('/ajax/messageshref.php');
}

document.onclick = function() {
	$('#pic-menu').hide();
	$('#photo-menu').hide();
	$('#dropinvite_new_div').hide();
}

function dropinvite_new(email, elm, event, elmid) {
	$('#dropinvite_new_div').css("width", $(elm).width());
	$('#dropinvite_new_div').css("top", $(elm).offset().top+$(elm).height());
	$('#dropinvite_new_div').css("left", $(elm).offset().left);
	$('#dropinvite_new_div').html("<a href=\"#\" onClick=\"invite_new('"+email+"', 'family', '"+elmid+"'); return false;\">Семья</a><br><a href=\"#\" onClick=\"invite_new('"+email+"', 'relative', '"+elmid+"'); return false;\">Родственник</a><br><a href=\"#\" onClick=\"invite_new('"+email+"', 'friend', '"+elmid+"'); return false;\">Друг семьи</a><!--<br><a href=\"#\" onClick=\"invite_new('"+email+"', 'guest', '"+elmid+"'); return false;\">Гость</a>-->");
	$('#dropinvite_new_div').show();
	cancelEvent(event);
}

function invite_new(email, status, elm)
{
	$('#'+elm).html("Подождите...");
	$('#'+elm).load('ajax/oi/invite_new.php', {email: email, status: status});
}

function guest_bjah_alert()
{
	$.prompt("Пожалуйста, <a href=\"/register\">зарегистрируйтесь</a>, чтобы получить доступ ко всем возможностям!", { buttons: { ok: true, Cancel: false }, submit:function(v,m,f){if(v) return true; else location.href='/register';}, focus: 2});
}

function make_guest_div()
{
	$('#gcl').css("z-index", "100");
	$('#gcl').css("position", "absolute");
	$('#gcl').css("top", "0");
	$('#gcl').css("left", "0");
	$('#gcl').css("bottom", "0");
	$('#gcl').css("right", "0");
	$('#gcl').css("background-color", "transparent");
	$('#gcl').attr("onclick", "guest_bjah_alert()");
}

function dropinvite_exists(email, elm, event, elmid)
{
	$('#dropinvite_new_div').css("width", $(elm).width());
	$('#dropinvite_new_div').css("top", $(elm).offset().top+$(elm).height());
	$('#dropinvite_new_div').css("left", $(elm).offset().left);
	$('#dropinvite_new_div').html("<a href=\"#\" onClick=\"invite_exists('"+email+"', 'family', '"+elmid+"'); return false;\">Как члена семьи</a><br><a href=\"#\" onClick=\"invite_exists('"+email+"', 'relative', '"+elmid+"'); return false;\">Как родственника</a><br><a href=\"#\" onClick=\"invite_exists('"+email+"', 'friend', '"+elmid+"'); return false;\">Как друга</a>");
	$('#dropinvite_new_div').show();
	cancelEvent(event);
}

function invite_exists(email, status, elm)
{
	$('#'+elm).html("Подождите...");
	$('#'+elm).load('ajax/oi/invite_exists.php', {email: email, status: status});
}

function invite_knock(email, elm)
{
	$('#'+elm).html("Подождите...");
	$('#'+elm).load('ajax/oi/invite_knock.php', {email: email});
}

function loadajaxphoto(id)
{
	$('#photo_here').html('Загрузка...');
	$('#photo_here').load('ajax/home/photo/photo-ajax.php', {id: id});
}

function save_photo_params()
{
	$('#tip').load('ajax/home/photo/photo-save-params.php', {id: ph_id, name: $('#ph_name_input').val(), desc: $('#ph_desc_input').val(), album: $('#ph_album_input').val()});
	ph_name=$('#ph_name_input').val();
	$('#save-changes').hide();
	$('#save-changes2').hide();
	if (sort_order!='')
	{
		$('#temp-ajax-div').load('ajax/home/photo/photo-save-ord.php', {ord: sort_order, id: ph_id});
	}
}

function testanchor()
{
	var test=self.document.location.hash;
	test=test.substr(1);
	if (test!=anchor)
	{
		anchor=test;
		if (anchor=='') {loadajaxphoto(ph_default); return false;}
		loadajaxphoto(anchor);
	}
}

function delphoto()
{
	var tmp;
	tmp=anchor;
	if (tmp=='') tmp=ph_default;
	$('#photo_here').load('ajax/home/photo/photo-del.php', {id: tmp});
}

function loadajaxvideo(id)
{
	$('#video_load').html('Загрузка...');
	$('#video_load').load('ajax/home/video/video-ajax.php', {id: id});
}

function save_video_params()
{
	$('#tip').load('ajax/home/video/video-save-params.php', {id: ph_id, name: $('#ph_name_input').val(), desc: $('#ph_desc_input').val(), album: $('#ph_album_input').val()});
	ph_name=$('#ph_name_input').val();
	$('#save-changes').hide();
	$('#save-changes2').hide();
	if (sort_order!='')
	{
		$('#temp-ajax-div').load('ajax/home/video/video-save-ord.php', {ord: sort_order, id: ph_id});
	}
}

function testanchorv()
{
	var test=self.document.location.hash;
	test=test.substr(1);
	if (test!=anchor)
	{
		anchor=test;
		if (anchor=='') {loadajaxvideo(ph_default); return false;}
		loadajaxvideo(anchor);
	}
}

function delvideo()
{
	var tmp;
	tmp=anchor;
	if (tmp=='') tmp=ph_default;
	$('#video_load').load('ajax/home/video/video-del.php', {id: tmp});
}

function showphotomenu(event, id, thumb)
{
	if(navigator.userAgent.indexOf("MSIE") != -1) event = window.event;
	var picMenu = document.getElementById('photo-menu');
	
	if (user_level<2)
	{
	$('#photo-menu').html("<a href=\"" + thumb + "/height/0/width/0\" onClick=\"window.open('" + thumb + "/height/0/width/0', 'qwerty', 'status=no,toolbar=no,menubar=no,scrollbars=yes'); return false;\">Увеличить</a><br><a href=\"#\" onClick=\"ph_make_main_a('"+id+"'); return false;\">Сделать главной в альбоме</a><br><a href=\"#\" onClick=\"ph_make_main_h('"+id+"'); return false;\">Сделать главной в доме</a>");
	}
	else
	$('#photo-menu').html("<a href=\"" + thumb + "/height/0/width/0\">Увеличить</a>");
	
	picMenu.style.display = 'block';
	picMenu.style.left = (event.clientX + getScrollLeft() + 15) + 'px';
	picMenu.style.top = (event.clientY + getScrollTop() + 5) + 'px';
	cancelEvent(event);
	
	
	return false;
}

function ph_make_main_a(id)
{
	$('#temp-ajax-div').load('ajax/home/photo/photo-main-a.php', {id: id});
}

function ph_make_main_h(id)
{
	$('#temp-ajax-div').load('ajax/home/photo/photo-main-h.php', {id: id});
}

function del_home_photo(id)
{
	$('#temp-ajax-div').load('ajax/home/del-home-photo.php', {id: id});
	$('#home_photo_a').html("<img src=\"images/home_default.jpg\" alt=\"\">");
	$('#del-home-photo-a').hide();
}

function make_photo_al_first(id, enname)
{
	$('#temp-ajax-div').load('ajax/home/photo/photo-al-first.php', {id: id});
	location.href='/home/'+enname;
}

function make_video_al_first(id, enname)
{
	$('#temp-ajax-div').load('ajax/home/video/video-al-first.php', {id: id});
	location.href='/home/'+enname;
}

function make_photo_al_unfirst(id, enname)
{
	$('#temp-ajax-div').load('ajax/home/photo/photo-al-unfirst.php', {id: id});
	location.href='/home/'+enname;
}

function make_video_al_unfirst(id, enname)
{
	$('#temp-ajax-div').load('ajax/home/video/video-al-unfirst.php', {id: id});
	location.href='/home/'+enname;
}

function del_propiska()
{
	if (confirm('Ты уверен, что хочешь выписаться из дома?'))
		$('#user-propiska').load('ajax/user/del-propiska.php');
}

function del_home_submit()
{
	if (document.getElementById('deleteform').password.value=='')
	{
		bjah_alert("Введите свой пароль!");
		document.getElementById('deleteform').password.focus();
		return false;
	}
	if (confirm('Ты точно уверен, что хочешь удалить свой дом?'))
	{
		$('#deleteform').submit();
	}
}

function drop_invite_user(user, elm)
{
	$('#user-menu2').css('top', $(elm).offset().top);
	$('#user-menu2').css('left', $(elm).offset().left +  $(elm).width());
	$('#user-menu2').html("<a href=\"invite/home/"+user+"/family\" onClick=\"invite_my_home('"+user+"', 'family'); return false;\">Семья</a><br><a href=\"invite/home/"+user+"/relative\" onClick=\"invite_my_home('"+user+"', 'relative'); return false;\">Родственник</a><br><a href=\"invite/home/"+user+"/friend\" onClick=\"invite_my_home('"+user+"', 'friend'); return false;\">Друг семьи</a><!--<br><a href=\"invite/home/"+user+"/guest\" onClick=\"invite_my_home('"+user+"', 'guest'); return false;\">Гость</a>-->");
	$('#user-menu2').show();
	$('#bgwrp').css('background', 'transparent');
	$('#bgwrp').css('top', '0');
	$('#bgwrp').css('height', $('.pre-footer').height());
	$('#bgwrp').css('right', '0');
	$('#bgwrp').css('left', '0');
	$('#bgwrp').css('z-index', '900');
	$('#bgwrp').show();
}

function invite_my_home(user, status)
{
	$('#temp-ajax-div').load('ajax/user/invite_user.php', {user: user, status: status});
	$('#bgwrp').hide();
	$('#user-menu').hide();
	$('#user-menu2').hide();
	$('#this-invite').hide();
	$('#this-invite').removeAttr('id');
}

function isNotMax(e)
{
	return true;
	e = e || window.event;
	var target = e.target || e.srcElement;
	var code=e.keyCode?e.keyCode:(e.which?e.which:e.charCode)
	switch (code)
	{
		case 13:
		case 8:
		case 9:
		case 46:
		case 37:
		case 38:
		case 39:
		case 40:
		return true;
	}
	return target.value.length <= target.getAttribute('maxlength');
}



$(document).ready(function(){
	$('img').ifixpng(); 
});















