(function(b){var a=b.queryNickName=function(c){a(c)};a.defaults={v:"1.0.4",getNickUrl:"http://api.community.virgilio.it/profile-user-api-web/auth-resources/profile-user/getNicks.js?callback=jQuery.queryNickName.setNicks",commTimeout:1000,defSelector:"a.queryNickName",displayAccount:"div.queryNickNameAccount",displayAccountWithoutNick:"div.queryNickNameAccountWithoutNick",displayNoAccount:"div.queryNickNameNoAccount",nickUrl:"http://people.virgilio.it/profilo/",callback:null,cookieCache:false,cookieOpt:{path:"/",expires:1,domain:"virgilio.it"},isAuth:"BT_isAuth",currNick:"BT_currNick",othrNick:"BT_othrNick",authCookie:"PAAA_AUTHE"};b.fn.queryNickName=function(d){var c=a.settings=b.extend({},a.defaults,d);if(c.cookieCache){if(!b.isFunction(b.cookie)){a.cookieInit()}a.readCookies()}setTimeout(function(){a.loadJsonpData()},c.commTimeout)};a.loadJsonpData=function(){var c=document.createElement("script"),d=document.getElementsByTagName("head")[0];c.type="text/javascript";c.charset="UTF-8";c.src=a.settings.getNickUrl;d.appendChild(c)};a.buildView=function(d){var c,g=[],e,f=a.settings;if(true==d.auth){b(f.displayNoAccount).addClass("hidden");if(d.nick.length>0){b(f.displayAccount).removeClass("hidden");b(f.defSelector).text(d.nick).attr("href",f.nickUrl+d.nick).removeClass("hidden");if(b.isFunction(f.callback)){f.callback.call(this,d.nick)}}else{b(f.displayAccountWithoutNick).removeClass("hidden")}}};a.setNicks=function(e){if(a.valiData(e)){var c=e.BT,d=a.settings;a.buildView(c);if(d.cookieCache){a.writeCookies(c)}if(c.err.length>0&&window.console){console.log("Validation BT.data Error: "+c)}}};a.valiData=function(h){var i=false,e=h.BT={auth:false,nick:"",othr:[],err:[]},d=h.user,g="Error while reding ",f;if(h){try{e.auth=("200"==d.responseStatus.resCode)}catch(c){e.err.push(g+"resCode: "+c)}try{f=d.currentNick;if(f){e.nick=f}}catch(c){e.err.push(g+"currentNick: "+c)}try{f=d.othertNicks;if(a.isArray(f)){e.othr=f.slice()}}catch(c){e.err.push(g+"othertNicks: "+c)}e.toString=function(){return"BT.data{authenticated:"+e.auth+", currentNick:"+e.nick+", otherNicks:"+e.othr.join(",")+", errors:"+e.err.join(",")+"}"};i=true}else{if(window.console){console.log("SH - Error while validating data from server: "+h)}}return i};a.isArray=function(c){return Object.prototype.toString.call(c)==="[object Array]"};a.readCookies=function(){var e=a.settings,c={},d;if(b.cookie(e.authCookie)){d=b.cookie(e.isAuth);c.auth=d?"true"==d:false;d=b.cookie(e.currNick);c.nick=d?d:"";d=b.cookie(e.othrNick);c.othr=d?d.split(","):[];a.buildView(c)}};a.writeCookies=function(c){var d=a.settings;b.cookie(d.isAuth,c.auth,d.cookieOpt);b.cookie(d.currNick,c.nick,d.cookieOpt);b.cookie(d.othrNick,c.othr.join(","),d.cookieOpt)};a.cookieInit=function(){b.extend({cookie:function(d,l,o){if(typeof l!="undefined"){o=o||{};if(l===null){l="";o=b.extend({},o);o.expires=-1}var g="";if(o.expires&&(typeof o.expires=="number"||o.expires.toUTCString)){var h;if(typeof o.expires=="number"){h=new Date();h.setTime(h.getTime()+(o.expires*24*60*60*1000))}else{h=o.expires}g="; expires="+h.toUTCString()}var n=o.path?"; path="+(o.path):"";var j=o.domain?"; domain="+(o.domain):"";var c=o.secure?"; secure":"";document.cookie=[d,"=",encodeURIComponent(l),g,n,j,c].join("")}else{var f=null;if(typeof d!="undefined"){if(document.cookie&&document.cookie!=""){var m=document.cookie.split(";");for(var k=0;k<m.length;k++){var e=jQuery.trim(m[k]);if(e.substring(0,d.length+1)==(d+"=")){f=decodeURIComponent(e.substring(d.length+1));break}}}}return f}}})}})(jQuery);
