﻿/**
 *	Written by Nico Bergemann <barracuda415@yahoo.de>
 *	Copyright 2011 Nico Bergemann
 *
 *	This program is free software: you can redistribute it and/or modify
 *	it under the terms of the GNU General Public License as published by
 *	the Free Software Foundation, either version 3 of the License, or
 *	(at your option) any later version.
 *
 *	This program is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU General Public License for more details.
 *
 *	You should have received a copy of the GNU General Public License
 *	along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

jQuery.fn.attrAppend=function(a,c){var b;return this.each(function(){b=$(this);if(b.attr(a)!==undefined&&b.attr(a)!=""){b.attr(a,c+b.attr(a))}})};function SteamProfile(){var q="steamprofile.min.js";var r="steamprofile.xml";var c="../xmlproxy.php";var y;var d;var A="english";var t="english";var x={english:{loading:"Cargando...",no_profile:"No tiene pagina en la comunidad steam.",private_profile:"Perfil privado.",invalid_data:"Perfil invalido.",join_game:"Unirse al Juego",add_friend:"Agregar a Amigos",view_tf2items:"View TF2 Backpack"},german:{loading:"Lade…",no_profile:"Dieser Benutzer hat bisher kein Steam Community Profil angelegt.",private_profile:"Dieses Profil ist privat.",invalid_data:"Ungültige Profildaten.",join_game:"Spiel beitreten",add_friend:"Als Freund hinzufügen",view_tf2items:"TF2-Items ansehen"},portuguese:{loading:"Carregando…",no_profile:"This user has not yet set up their Steam Community profile.",private_profile:"This profile is private.",invalid_data:"Invalid profile data.",join_game:"Entrar",add_friend:"Adicionar à sua lista de amigos",view_tf2items:"Ver Itens do TF2"}};var z=false;var g=false;var w;var a;var f;var e;var j=[];var n={};var u;var h;var v;this.init=function(){if(typeof spBasePath=="string"){y=spBasePath}else{var B=$("script[src$='"+q+"']");if(B.length===0){return}y=B.attr("src").replace(q,"")}jQuery.ajax({type:"GET",url:y+r,dataType:"html",complete:function(D,C){w=$(D.responseXML);i()}})};this.refresh=function(){if(!g||z){return}z=true;j=$(".steamprofile[title]");if(j.length===0){return}j.each(function(){var B=$(this);B.data("profileID",$.trim(B.attr("title")));B.removeAttr("title")});j.empty().append(h);k(0)};this.load=function(B){if(!g||z){return}profile=$('<div class="steamprofile"></div>');profile.append(h);jQuery.ajax({type:"GET",url:p(B),dataType:"xml",complete:function(D,C){profile.empty().append(o($(D.responseXML)))}});return profile};this.isLocked=function(){return z};function p(B){return y+c+"?id="+escape(B)+"&lang="+escape(A)}function l(B){return w.find('vars > var[name="'+B+'"]').text()}function m(B){return l(B).toLowerCase()=="true"}function i(){f=m("slidermenu");a=m("gamebanner");e=m("tf2items");A=l("language");t=A;if(x[t]==null){t="english"}d=y+"themes/"+l("theme")+"/";$("head").append('<link rel="stylesheet" type="text/css" href="'+d+'style.css">');u=$(w.find("templates > profile").text());h=$(w.find("templates > loading").text());v=$(w.find("templates > error").text());u.find("img").attrAppend("src",d);h.find("img").attrAppend("src",d);v.find("img").attrAppend("src",d);u.find(".sp-joingame").attr("title",x[t].join_game);u.find(".sp-addfriend").attr("title",x[t].add_friend);u.find(".sp-viewitems").attr("title",x[t].view_tf2items);h.append(x[t].loading);g=true;SteamProfile.refresh()}function k(C){if(C>=j.length){z=false;return}var D=$(j[C++]);var E=D.data("profileID");if(n[E]==null){jQuery.ajax({type:"GET",url:p(E),dataType:"xml",complete:function(G,F){n[E]=o($(G.responseXML));D.empty().append(n[E]);k(C)}})}else{var B=n[E].clone();s(B);D.empty().append(B);k(C)}}function o(C){if(C.find("profile").length!==0){var B;if(C.find("profile > steamID").text()==""){return b(x[t].no_profile)}else{B=u.clone();var D=C.find("profile > onlineState").text();B.find(".sp-badge").addClass("sp-"+D);B.find(".sp-avatar img").attr("src",C.find("profile > avatarIcon").text());B.find(".sp-info a").append(C.find("profile > steamID").text());if(C.find("profile > visibilityState").text()=="1"){B.find(".sp-info").append(x[t].private_profile)}else{B.find(".sp-info").append(C.find("profile > stateMessage").text())}if(a&&C.find("profile > inGameInfo > gameLogoSmall").length!==0){B.css("background-image","url("+C.find("profile > inGameInfo > gameLogoSmall").text()+")")}else{B.removeClass("sp-bg-game");B.find(".sp-bg-fade").removeClass("sp-bg-fade")}if(f){if(C.find("profile > inGameInfo > gameJoinLink").length!==0){B.find(".sp-joingame").attr("href",C.find("profile > inGameInfo > gameJoinLink").text())}else{B.find(".sp-joingame").remove()}if(e){B.find(".sp-viewitems").attr("href","http://tf2items.com/profiles/"+C.find("profile > steamID64").text())}else{B.find(".sp-viewitems").remove()}B.find(".sp-addfriend").attr("href","steam://friends/add/"+C.find("profile > steamID64").text());B.find(".sp-avatar a, .sp-info a.sp-name").attr("href","http://steamcommunity.com/profiles/"+C.find("profile > steamID64").text());s(B)}else{B.find(".sp-extra").remove()}}return B}else{if(C.find("response").length!==0){return b(C.find("response > error").text())}else{return b(x[t].invalid_data)}}}function s(B){B.find(".sp-handle").click(function(){B.find(".sp-content").toggle(200)})}function b(C){var B=v.clone();B.append(C);return B}}$(document).ready(function(){SteamProfile=new SteamProfile();SteamProfile.init()});
