/**
 * onArcade 2.2.2
 * Copyright © 2006-2009 Hans Mäesalu & Eveterm OÜ, All Rights Reserved
 **
 * ONARCADE IS NOT FREE SOFTWARE!
 * http://www.onarcade.com
 **/
 

 var profile={user_id:0,location:"",location_button:null,location_bubble:null,friends_pages:0,friends:null,comments_page:1,comments:null,comments_form:null,comments_submit:null,draw_friends:function(a,b,c){profile.friends.empty();var d;for(i in a){d=$.createElement("div").addClass("friend");$.createElement("a").attr("href",a[i].url).html('<img src="'+a[i].avatar+'" alt="" />'+a[i].name).appendTo(d);profile.friends.append(d);i==4&&$.createElement("div").addClass("separator").appendTo(profile.friends)}$.createElement("div").addClass("clear").appendTo(profile.friends);
if(b>1){a=$.createElement("div").addClass("pagination");c>1&&$.createElement("a").attr("href","").html("&lsaquo;").data("page",c-1).click(profile.friends_click).appendTo(a);for(i=1;i<=b;i++){d=$.createElement("a").attr("href","").text(i).data("page",i).click(profile.friends_click).appendTo(a);i==c&&d.addClass("current")}c<b&&$.createElement("a").attr("href","").html("&rsaquo;").data("page",c+1).click(profile.friends_click).appendTo(a);profile.friends.append(a)}},friends_click:function(){profile.load_friends($(this).data("page"));
return false},load_friends:function(a){loader.replace(profile.friends);$.getJSON(siteurl+"profile.php?a=friends&u="+profile.user_id+"&p="+a+"&ajax="+profile.friends_pages,function(b){if(b.error)alert(b.message);else{if(b.pages!=undefined)profile.friends_pages=b.pages;profile.draw_friends(b.friends,profile.friends_pages,a)}})},friend_request:function(a){loader.insert(a);$.getJSON(siteurl+"usercp.php?a=friend_request&f="+profile.user_id+"&ajax=1",function(b){error.insert(b.message,a.parent(),{error:b.error});
a.parent().slideUp(250)})},submit_comment:function(){loader.insert(profile.comments_submit);$.post(siteurl+"profile.php?a=submit_comment&u="+profile.user_id+"&ajax=1",profile.comments_form.serializeArray(),function(a){error.insert(a.message,profile.comments_form,{error:a.error});if(a.error)loader.remove(profile.comments_submit);else{profile.comments_form.slideUp();a=$.createElement("div").addClass("comment").html('<a href="'+a.user_url+'"><img src="'+a.avatar+'" class="user_avatar" alt="" /></a><p><span class="user"><a href="'+
a.user_url+'">'+a.username+'</a></span> <span class="date">('+a.date+")</span></p><p>"+a.comment+"</p>");var b=profile.comments.children("div:first-child");b.size()>0?b.before(a):profile.comments.append(a)}},"json")},delete_comment:function(a){if(confirm_delete()){var b=a.closest(".comment");loader.insert(a);$.getJSON(siteurl+"profile.php?a=delete_comment&c="+field_number(b.attr("id"))+"&ajax=1",function(c){c.error?alert(c.message):b.slideUp()})}},load_comments:function(a){loader.replace(profile.comments);
profile.comments.load(siteurl+"profile.php?a=comments&u="+profile.user_id+"&p="+a+"&ajax=1")},open_map:function(){if(profile.location_bubble==null){profile.location_bubble=$.createElement("div").addClass("bubble").width("400px");$.createElement("div").addClass("bubble_up").css("left","70px").appendTo(profile.location_bubble);$(document.body).append(profile.location_bubble);profile.location_bubble.append('<img src="http://maps.google.com/maps/api/staticmap?center='+encodeURI(profile.location)+'&size=400x350&sensor=false&amp;maptype=hybrid" alt="" />');
profile.location_bubble.click(function(b){b.stopPropagation()})}else profile.location_bubble.fadeIn("fast");var a=profile.location_button.offset();profile.location_bubble.css({top:a.top+30,left:a.left-70});$(document).click(profile.close_map)},close_map:function(){profile.location_bubble.fadeOut("fast");$(document).unbind("click",profile.close_map)},init_map:function(){var a=$("#user_location");profile.location=a.children("span").text();if(profile.location.length>0)profile.location_button=a.children("img").css("display",
"inline").click(function(){profile.open_map();return false})},init:function(a){profile.user_id=a;profile.friends=$("#friends");profile.friends.size()>0&&$("#all_friends").click(function(){profile.load_friends(1);return false});$("#friend_request").click(function(){profile.friend_request($(this));return false});profile.comments=$("#comments");profile.comments_form=$("#comment_form");if(profile.comments_form.size()>0){profile.comments_submit=profile.comments_form.find("input:submit");profile.comments_form.submit(function(){profile.submit_comment();
return false})}$("#comments .delete a").live("click",function(b){b.preventDefault();profile.delete_comment($(this))});$("#comments .next").live("click",function(b){b.preventDefault();profile.comments_page++;profile.load_comments(profile.comments_page)});$("#comments .previous").live("click",function(b){b.preventDefault();profile.comments_page--;profile.load_comments(profile.comments_page)});profile.init_map()}};


var color_field;function slide_content(slider_name,slide_id,slides_count){var div=doc_id(slider_name+"_"+slide_id);var slider=div.parentNode;clearInterval(slider.timer);slider.target=div.offsetTop;slider.style.top=slider.style.top||'0px';slider.current=slider.style.top.replace("px","");slider.direction=(Math.abs(slider.current)>slider.target)?1:-1;slider.style.opacity=0.5;slider.style.filter="alpha(opacity=50)";slider.timer=setInterval(function(){slide_animate(slider)},3);if(slide_id>0)doc_id(slider_name+"_up").onclick=function(){slide_content(slider_name,(slide_id-1),slides_count);};else doc_id(slider_name+"_up").onclick="";if(slide_id<(slides_count-1))doc_id(slider_name+"_down").onclick=function(){slide_content(slider_name,(slide_id+1),slides_count);};else doc_id(slider_name+"_down").onclick="";}function slide_animate(slider){var curr=Math.abs(slider.current);var tar=Math.abs(slider.target);var dir=slider.direction;if((tar-curr<=3&&dir==-1)||(curr-tar<=3&&dir==1)){slider.style.top=(slider.target*-1)+"px";slider.style.opacity=1;slider.style.filter='alpha(opacity=100)';clearInterval(slider.timer);}else{var pos=(dir==1?parseInt(slider.current)+3:slider.current-3);slider.current=pos;slider.style.top=pos+"px";}}function init_slider(slider_id,slides_count){var slider_width=doc_id(slider_id).offsetWidth;var slider_height=doc_id(slider_id+"_0").offsetHeight-20;var up_arrow=doc_id(slider_id+"_up");var down_arrow=doc_id(slider_id+"_down");if(slider_height>0){doc_id(slider_id).style.height=slider_height+"px";up_arrow.style.top=-(slider_height)+"px";up_arrow.style.left=(slider_width-16)+"px";up_arrow.style.display="inline";down_arrow.style.top=-16+"px";down_arrow.style.left=(slider_width-16)+"px";down_arrow.style.display="inline";}if(slides_count>1)down_arrow.onclick=function(){slide_content(slider_id,1,slides_count);};}function submit_pcomment(user_id){var submit=doc_id("submit_comment");var error=doc_id("comment_error");var loader=doc_id("loader");submit.disabled=true;loader.style.display="";function back_function(server_r){error.innerHTML=server_r.message;error.style.display="";if(server_r.error==0)doc_id("comment_form").style.display="none";else{submit.disabled=false;loader.style.display="none";}}makeHttpRequest(siteurl+"/profile.php?a=submit_comment&u="+user_id+"&ajax=1",back_function, true,"message="+doc_id("message").value);}function display_pcomments(user_id,comment_page){doc_id("comments").innerHTML="<br />"+loader+"<br />";makeHttpRequest(siteurl+"/profile.php?a=comments&u="+user_id+"&p="+comment_page+"&ajax=1",function(response){doc_id("comments").innerHTML=response;},false);}function delete_comment(comment_id){function back_function(server_r){if(server_r.error==0)doc_id("comment_"+comment_id).style.display="none";}if(confirm_delete())makeHttpRequest(siteurl+"/profile.php?a=delete_comment&c="+comment_id+"&ajax=1",back_function, true);}function color_selector(button,field_id){color_field=doc_id(field_id);if(document.getElementById("color_selector")){var selector=doc_id("color_selector");selector.style.display="";}else{var selector=document.createElement("div");selector.setAttribute("id","color_selector");selector.style.cursor="pointer";selector.style.width="30px";selector.style.border="1px solid #808080";document.body.appendChild(selector);var colors=new Array("00FFFF","000000","0000FF","FF00FF","008000","808080","00FF00","800000","000080","808000","800080","FF0000","C0C0C0","008080","FFFFFF","FFFF00");for(var i=0;i<colors.length;i++){var s_color=document.createElement("div");s_color.setAttribute("title",colors[i]);s_color.style.height="10px";s_color.style.background="#"+colors[i];s_color.onclick=function(){color_field.value=this.title;selector.style.display="none";};selector.appendChild(s_color);}}var position=get_position(button);selector.style.position="absolute";selector.style.left=position[0]+"px";selector.style.top=position[1]+"px";}function friend_request(friend_id){var friend_request=doc_id("friend_request");friend_request.innerHTML=loader;function back_function(server_r){friend_request.innerHTML=server_r.message;}makeHttpRequest(siteurl+"/usercp.php?a=friend_request&f="+friend_id+"&ajax=1",back_function, true);}function accept_friend(button,friend_id){button.onclick="";button.src="images/load.gif";function back_function(server_r){doc_id("friend_"+friend_id).style.display="none";}makeHttpRequest(siteurl+"/usercp.php?a=friend_request&f="+friend_id+"&ajax=1",back_function, true);}function remove_friend(button,friend_id){if(!window.confirm(sure_remove_friend))return;button.onclick="";button.src="images/load.gif";function back_function(server_r){doc_id("friend_"+friend_id).style.display="none";}makeHttpRequest(siteurl+"/usercp.php?a=remove_friend&f="+friend_id+"&ajax=1",back_function, true);}
