var wslide=false;
function slide(p)
{
	if(wslide)return;
	wslide=true;
	$("#prevarea .prev:eq("+(p==1?0:3)+")").parents("div:eq(0)").animate({width: '0px', opacity: '0'},{queue:false,duration:200,complete:function(){
		$(this).parents("td:eq(0)").remove();
		wslide=false;
	}});
	var html='';
	html+='<td>';
	html+='<div style="overflow: hidden; width: 0px;">';
	html+='<table cellpadding="0" cellspacing="0" border="0" class="prev" width="170">';
	html+='<tr>';
	html+='<td height="20"><div class="px"><!-- --></div></td>';
	html+='</tr>';
	html+='<tr>';
	html+='<td align="center">';
	html+='<div style="width: 167px; height: 112px; background: url(img/pic1.jpg);"><div style="width: 167px; height: 112px; background: url(img/border.gif);"><!-- --></div></div>';
	html+='</td>';
	html+='</tr>';
	html+='<tr>';
	html+='<td>';
	html+='<a href="#">My name is Earl / Меня завут Эрл</a>';
	html+='</td>';
	html+='</tr>';
	html+='</table>';
	html+='</div>';
	html+='</td>';
	if(p==1){
		$("#prevarea tr:eq(0)").append(html);
	}else{
		$("#prevarea tr:eq(0)").prepend(html);
	}
	$("#prevarea .prev:eq("+(p==1?4:0)+")").parents("div:eq(0)").css({opacity: 0}).animate({width: '170px', opacity: '1'},{duration:200,complete:function(){
		wslide=false;
	}});

}

var allsdoanim=false;
var allopen=false;
function allsanim(p)
{
	if(allsdoanim && p==1)return;
	allsdoanim=true;
	$("#alls").animate({top: (p==1?0:-7)+'px'},{duration:150,complete:function(){
		allsdoanim=false;
	}});
}
$(document).ready(function(){
	$("#alls").hover(function(){
		allsanim(1);
	},function(){
		allsanim(0);
	}).click(function(){
		if(!allopen){
			$("#allsarea").animate({height: '500'},{duration: 300,complete: function(){
				allopen=true;
				$("#alls img").attr("src","img/all2.jpg");
			}});
		}else{
			$("#allsarea").animate({height: '0'},{duration: 300,complete: function(){
				allopen=false;
				$("#alls img").attr("src","img/all1.jpg");
			}});
		}
	});
});

function objgo(obj)
	{
		document.location.href=$("a:eq(0)",obj).attr("href");
	}
	
	var search_focus=false;
	$(document).ready(function(){
		$("#header input").focus(function(){
			search_focus=true;
			$(this).css({border:'2px solid #79b5d6',color:'#000'});
		}).blur(function(){
			search_focus=false;
			$(this).css({border:'2px solid #f6f6f6',color:'#999'});
			if($.trim($(this).val())=="")$(this).val("Поиск");
		}).hover(function(){
			if(!search_focus)$(this).css({border:'2px solid #cccccc'});
		},function(){
			if(!search_focus)$(this).css({border:'2px solid #f6f6f6'});
		}).click(function(){
			if($(this).val()=="Поиск")$(this).val("");
		});
		
		$("#menu1 td").hover(function(){
			$(this).css({background:'#4f9ec9'});
		},function(){
			$(this).css({background:'none'});
		}).click(function(){
			objgo(this);
		});
		
		$("#menu2 td").hover(function(){
			$(this).css({background:'#4d99c3'});
			$("a",this).css({color:'#FFFFFF'});
		},function(){
			$(this).css({background:'#4f9ec9'});
			$("a",this).css({color:'#deedf5'});
		}).click(function(){
			objgo(this);
		});
	});

$(document).ready(function(){
	$("table.ratiostars").hover(function(){},function(){
		$(this).find("td.star div").show();
		$(this).find("td.star").css("background-position","0 16px");
	});
	$("table.ratiostars").each(function(){
		$("td.star",this).each(function(i){
			$(this).hover(function(){
				if(i>0){
					for(var q=i;q!=0;q--){
						$(this).parents("tr:eq(0)").find("td.star").eq(q-1).css("background-position","0 32px");
					}
				}
				$(this).parents("tr:eq(0)").find("td.star div").hide();
				$(this).css("background-position","0 32px");
			},function(){
				if(i>0){
					$(this).css("background-position","0 16px");
					for(var q=i;q!=0;q--){
						$(this).parents("tr:eq(0)").find("td.star").eq(q-1).css("background-position","0 16px");
					}
				}
			});
		});
	});
	
});

function post_vote(obj,id,num,goback)
{
	$.get("index.php?p=content&op=ajax_vote&id="+id+"&num="+num,function(response){
		
		$("#post_ratio"+id).html($("response",response).attr("ratio"));
		$("#post_votes_num"+id).html($("response",response).attr("votesnum"));
		$("#post_ratio_stars"+id).html($("response",response).text());
		
		$("#post_ratio_stars"+id).find("td.star").removeAttr("onclick").unbind("mouseover").unbind("mouseout");
		$("#post_ratio_stars"+id).find("td.star div").show();
		$("#post_ratio_stars"+id).find("td.star").css("background-position","0 16px");
	});
	// ajax don't enabled
	//document.location.href="index.php?p=content&op=vote&id="+id+"&num="+num+"&go_back="+goback;
}

function content_bookmark(obj,p,id)
{
	$.get("index.php?p=content&op="+(p==1?'add':'rm')+"_bookmark&id="+id,function(data){
		if(p==1){
			$(".cp_bookmarks_num").html(parseInt($(".cp_bookmarks_num").html())+1);
			$(obj).removeAttr("onclick").unbind("click").bind("click",function(){content_bookmark(obj,0,id); return false;}).text("Удалить из избранного");
		}else{
			if(parseInt($(".cp_bookmarks_num").html())>1){
				$(".cp_bookmarks_num").html(parseInt($(".cp_bookmarks_num").html())-1);
			}else{
				$(".cp_bookmarks_num").html("0");
			}
			$(obj).removeAttr("onclick").unbind("click").bind("click",function(){content_bookmark(obj,1,id); return false;}).text("В избранное");
		}
	});
}

function cp_rm_bookmark(obj,id)
{
	$.get("index.php?p=user&op=rm_bookmark&id="+id,function(data){
		$(obj).parents("div:eq(0)").slideUp("fast");
		if(parseInt($(".cp_bookmarks_num").html())>1){
			$(".cp_bookmarks_num").html(parseInt($(".cp_bookmarks_num").html())-1);
		}else{
			$(".cp_bookmarks_num").html("0");
		}
	});
}

function new_message(to)
{
	window.open("index.php?p=mess&op=send&id=0"+(to>0?'&to='+to:''),"new_message","location=1,status=1,scrollbars=1,resizeable=0,width=600,height="+(to>0?'260':'320'));
}