function toggleDiv(divid){if(document.getElementById(divid).style.display=='none'){document.getElementById(divid).style.display='block';}else{document.getElementById(divid).style.display='none';}};var lastFmRecords=(function(window,document,undefined){var _user;var _period='recenttracks';var _count=6;var _styletype='';var _refreshmin=3;var _placeholder='lastfmrecords';var _defaultthumb='http://cdn.last.fm/depth/catalogue/noimage/cover_85px.gif';var _debug=false;var _gmt_offset='+1';var _linknewscreen=0;var _imgs_found=[];var _LASTFM_APIKEY='fbfa856cc3af93c43359b57921b1e64e';var _LASTFM_WS_URL='http://ws.audioscrobbler.com/2.0/';var _LASTFM_DEFAULTIMG='http://cdn.last.fm/flatness/catalogue/noimage/2/default_album_medium.png';function _logStatus(text){if(_debug)
if('undefined'!=typeof console)
if('function'==typeof console.log)
if('object'==typeof text)
console.log(text);else
console.log('last.fm.records: '+text);};function _getLastFMData(){var _method=false;switch(_period){case'lovedtracks':_method='user.getlovedtracks';break;case'topalbums':case'topalbumsoverall':_method='user.gettopalbums&period=overall';break;case'topalbums7day':_method='user.gettopalbums&period=7day';break;case'topalbums3month':_method='user.gettopalbums&period=3month';break;case'topalbums6month':_method='user.gettopalbums&period=6month';break;case'topalbums12month':_method='user.gettopalbums&period=12month';break;case'toptracks':_method='user.gettoptracks';break;case'tracksoverall':_method='user.gettoptracks&period=overall';break;case'tracks7day':_method='user.gettoptracks&period=7day';break;case'tracks3month':_method='user.gettoptracks&period=3month';break;case'tracks6month':_method='user.gettoptracks&period=6month';break;case'tracks12month':_method='user.gettoptracks&period=12month';break;default:_method='user.getrecenttracks';}
jQuery.getJSON(_LASTFM_WS_URL+'?method='+_method+'&user='+_user+'&api_key='+_LASTFM_APIKEY+'&format=json&callback=?',lastFmRecords.processLastFmData);};function _getArtistData(_artistmbid){jQuery.getJSON(_LASTFM_WS_URL
+'?method=artist.getinfo&mbid='+_artistmbid+'&api_key='+_LASTFM_APIKEY+'&format=json&callback=?',lastFmRecords.processArtistData);};function _errorInLastFmResponse(data){var _errorfound=false;var _errormsg;jQuery.each(data,function(tag,val){if('error'==tag){_errorfound=true;_errormsg=' ('+val+')';}
if(_errorfound&&('message'==tag)){_errormsg=val+_errormsg;}});if(_errorfound){_logStatus('last.fm reported error: '+_errormsg);}
return _errorfound;}
function _findLargestImage(_imgarray){_biggestYet=false;jQuery.each(_imgarray,function(j,_img){if('large'==_img.size){_biggestYet=_img['#text'];return false;}else if('medium'==_img.size){_biggestYet=_img['#text'];}else if(('small'==_img.size)&&(''==_biggestYet)){_biggestYet=_img['#text'];}});return(_LASTFM_DEFAULTIMG==_biggestYet)?false:_biggestYet;}
function _processLastFmData(data){if(_errorInLastFmResponse(data)){return false;}
switch(_period){case'recenttracks':data=data.recenttracks.track;break;case'lovedtracks':data=data.lovedtracks.track;break;case'tracks7day':case'tracks3month':case'tracks6month':case'tracks12month':case'tracksoverall':data=data.toptracks.track;break;default:data=data.topalbums.album;}
if(!data){_logStatus('No return data from Last.fm');return false;}
if(data.name&&'string'==typeof data.name){data=[data];}
jQuery.each(data,function(i,_json){if(i>_count){return false;}
var track=[];track.cdcover=_json.image?_findLargestImage(_json.image):false;track.artistname=_json.artist['#text']||_json.artist.name;track.artistmbid=_json.artist['mbid'];track.name=_json.name;track.mbid=_json.mbid;track.url=('http://'==_json.url.substr(0,7).toLowerCase())?_json.url:'http://'+_json.url;if('recenttracks'==_period){if(_json['@attr']&&('true'==_json['@attr'].nowplaying)){track.time='listening now';}else{track.time=('undefined'==typeof _json.date)?'some time':_getTimeAgo(_json.date['#text'],_gmt_offset);}}else{track.time='';}
_showCover(i,track);});if(_refreshmin>0){setTimeout('lastFmRecords.refreshCovers();',_refreshmin*60000);}};function _showCover(_id,_track){jQuery.each(_track,function(tag,val){jQuery('#lastfmcover'+_id).data(tag,val);});var _title=_track.name+' by '+_track.artistname;if(''!=_track.time){_title+=' ('+_track.time+')';}
jQuery('#lastfmcover'+_id).attr('title',_title);if(''==_track.cdcover){if(_imgs_found[_track.artistmbid]&&('*'!=_imgs_found[_track.artistmbid])){jQuery('#lastfmcover'+_id).attr('src',_imgs_found[_track.artistmbid]);}else{if('*'!=_imgs_found[_track.artistmbid]){if(_track.artistmbid){_logStatus('cover for '+_track.name+' not found, trying to find image of artist '+_track.artistname);_imgs_found[_track.artistmbid]='*';_getArtistData(_track.artistmbid);}else{_logStatus('no last.fm data found for artist '+_track.artistname);}}
jQuery('#lastfmcover'+_id).attr('src',_defaultthumb);jQuery('#lastfmcover'+_id).addClass(_track.artistmbid);}}else{jQuery('#lastfmcover'+_id).attr('src',_track.cdcover).parent('a').attr('href',_track.url).unbind('click',lastFmRecords.dontFollowLink);}};function _processArtistData(data){if(_errorInLastFmResponse(data)){return false;}
jQuery.each(data,function(i,_json){_imgurl=_findLargestImage(_json.image);_mbid=_json.mbid;jQuery('.'+_mbid).each(function(){jQuery(this).attr('src',_imgurl).removeClass(_mbid).parent('a').attr('href',_json.url).unbind('click',lastFmRecords.dontFollowLink);});_imgs_found[_mbid]=_imgurl;return false;});};function _getTimeAgo(_t,gmt_offset){var _diff=new Date()-new Date(_t);_diff=_diff-(gmt_offset*60000*60);var _d=[];_d.ye=parseInt(_diff/(1000*60*60*24*365));_d.da=parseInt(_diff/(1000*60*60*24))-(_d.ye*365);_d.ho=parseInt(_diff/(1000*60*60))-(_d.ye*365*24)-(_d.da*24);_d.mi=parseInt(_diff/(1000*60))-(_d.ye*365*24*60)-(_d.da*24*60)-(_d.ho*60);var _meantime=[];if(_d.ye>0){_meantime.push(_d.ye+' year'+_getPluralS(_d.ye));}
if(_d.da>0){_meantime.push(_d.da+' day'+_getPluralS(_d.da));}
if(_d.ho>0){_meantime.push(_d.ho+' hour'+_getPluralS(_d.ho));}
if(_d.mi>0){_meantime.push(_d.mi+' minute'+_getPluralS(_d.mi))};return _meantime.join(', ')+' ago';};function _getPluralS(_c){return(1==_c)?'':'s';};function _handleError(_msg,_url,_linenumber){var _err=[];_err.msg=_msg;_err.url=_url;_err.line=_linenumber;_err.ref=document.location.href;_logStatus(_err);return false;};return{addStyle:function(styletype){_logStatus('function addStyle not supported yet');},setUser:function(orUsername){_user=orUsername;},setPeriod:function(orPeriod){_period=orPeriod;},setCount:function(orCount){var _pI=parseInt(orCount);if(_pI>0){_count=_pI;}},setStyle:function(orStyle){_styletype=orStyle;},setPlaceholder:function(orPlaceholder){_placeholder=orPlaceholder;},setDefaultThumb:function(orDefaultThumb){_defaultthumb=orDefaultThumb;},setRefreshMinutes:function(orRefresh){var _pI=parseInt(orRefresh);if(_pI>0){_refreshmin=_pI;}},setTimeOffset:function(orOffset){_gmt_offset=parseInt(orOffset);},setLinkNewScreen:function(orLinkNewScreen){_linknewscreen=('1'==orLinkNewScreen);},debug:function(){_debug=true;},err:function(msg,url,linenumber){_handleError(msg,url,linenumber);},dontFollowLink:function(){return false;},init:function(_settings){_logStatus('initializing');jQuery(window).bind('error',lastFmRecords.err);_logStatus('registering error handler');if(_settings.placeholder){this.setPlaceholder(_settings.placeholder);}
var _regex=/\[lastfmrecords\|[a-z]+\|[0-9]+\]/;var _match=document.body.innerHTML.match(_regex);_logStatus(_match);if(_match){document.body.innerHTML=document.body.innerHTML.replace(_regex,'<div id='+_placeholder+'></div>');_match=_match[0].replace('[','').replace(']','').split('|');_logStatus('Hey, that\'s nice, this site is using the [lastfmrecords|period|count] way of showing covers.');if(_match[1]){_settings.period=_match[1];_logStatus('Changing period to '+_match[1]);}
if(_match[2]){_settings.count=_match[2];_logStatus('Changing number of covers to '+_match[2]);}}
if(jQuery("div#"+_placeholder).length<1){_logStatus('error: placeholder for cd covers not found');return false;}
if(_settings.username){this.setUser(_settings.username)}
if(_settings.period){this.setPeriod(_settings.period);}
if(_settings.defaultthumb){this.setDefaultThumb(_settings.defaultthumb);}
if(_settings.count){this.setCount(_settings.count);}
if(_settings.refresh){this.setRefreshMinutes(_settings.refresh);}
if(_settings.offset){this.setTimeOffset(_settings.offset);}
if(_settings.styletype){this.setStyle(_settings.styletype);}
if(_settings.linknewscreen){this.setLinkNewScreen(_settings.linknewscreen);}
if('1'==_settings.debug){this.debug();}
_logStatus(_user);if(!_user){_logStatus('No last.fm username available. Impossible to fetch listening habits. Goodbye.');return false;}
if('recenttracks'!=_period){_refreshmin=0;}
var _ol=jQuery("<ol></ol>").appendTo("div#"+_placeholder);if(!_ol){_logStatus('error: placeholder for cd covers not found');}
_logStatus('adding temporary cd covers');var _img,_li;for(var i=0;i<_count;i++){_li=jQuery('<li></li>').attr('style','display: inline;');_a=jQuery('<a></a>').bind('click',lastFmRecords.dontFollowLink).attr('href','').appendTo(_li);if('highslide'==_styletype){_a.click(function(){return hs.expand(this);});}
else if('lightbox'==_styletype){_a.attr('rel','lightbox');}
else if('1'==_linknewscreen){_a.attr('target','_blank');}
_img=jQuery('<img></img>').attr('src',_defaultthumb).attr('id','lastfmcover'+i).error(function(){jQuery(this).attr("src",_defaultthumb);}).appendTo(_a);_li.appendTo(_ol);}
_getLastFMData();},refreshCovers:function(){_getLastFMData();},processLastFmData:function(data){_processLastFmData(data);},processArtistData:function(data){_processArtistData(data);}};})(this,document);;jQuery.noConflict();var tgm_url=tgm_objects.tgm_url;var tgm_icons=[];var tgm_iw=new google.maps.InfoWindow();var tgm_sh=new google.maps.MarkerImage("http://chart.googleapis.com/chart?chst=d_map_pin_shadow",new google.maps.Size(40,37),null,new google.maps.Point(10,37));var tgm_size=new google.maps.Size(21,34);function thydzikgm(i,c,j,h,e,d){var f=tgm_url+"?u="+c,a=new google.maps.LatLngBounds(),b=new google.maps.Map(document.getElementById(i));switch(h){case"SATELLITE":b.setMapTypeId(google.maps.MapTypeId.SATELLITE);break;case"HYBRID":b.setMapTypeId(google.maps.MapTypeId.HYBRID);break;case"TERRAIN":b.setMapTypeId(google.maps.MapTypeId.TERRAIN);break;default:b.setMapTypeId(google.maps.MapTypeId.ROADMAP)}function g(){var k,n,m,l;k=document.createElement("div");k.style.marginRight="5px";n=document.createElement("div");n.style.width="50px";n.style.height="21px";n.style.backgroundColor="#fcfcfc";n.style.borderStyle="solid";n.style.borderWidth="1px";n.style.borderColor="#678ac7";k.appendChild(n);m=document.createElement("a");m.href=f+"&d=gpx";n.appendChild(m);l=document.createElement("img");l.src="http://chart.googleapis.com/chart?chst=d_simple_text_icon_left&chld=gpx|14|000|mobile|16|000|FFF&.png";l.alt="gpx";l.title="Download gpx file!";l.style.display="block";l.style.marginTop="2px";l.style.marginLeft="2px";l.style.borderStyle="none";m.appendChild(l);return k}if(e){b.controls[google.maps.ControlPosition.RIGHT_BOTTOM].push(g())}jQuery.get(f,function(m){if((d==="KML")||(d==="KMZ")){var l=new google.maps.KmlLayer(f);l.setMap(b)}else{jQuery(m).find("marker").each(function(){var s=jQuery(this).attr("lat");var o=jQuery(this).attr("lng");if(s&&o){var u=new google.maps.LatLng(parseFloat(s),parseFloat(o));a.extend(u);var t=(jQuery(this).attr("icon")||"").replace("Marker.png","").substring(0,2)||"%e2%bc%80";var r=jQuery(this).attr("colour")||jQuery(this).attr("color")||"ff776b";var q=t+r;if(!tgm_icons[q]){tgm_icons[q]=new google.maps.MarkerImage("http://chart.googleapis.com/chart?chst=d_map_pin_letter&chld="+t+"|"+r+"|000000&.png",tgm_size)}var n=new google.maps.Marker({position:u,icon:tgm_icons[q],map:b,shadow:tgm_sh});var p=jQuery(this).attr("html");if(p){google.maps.event.addListener(n,"click",function(){tgm_iw.setContent(p);tgm_iw.open(b,n)})}else{n.setClickable(false)}}});jQuery.each(["line","points"],function(){jQuery(m).find(String(this)).each(function(){var o=[];var p=jQuery(this).attr("colour")||jQuery(this).attr("color")||"0000ff";if(p.charAt(0)!=="#"){p="#"+p}jQuery(this).find("point").each(function(){var r=jQuery(this).attr("lat");var q=jQuery(this).attr("lng");if(r&&q){var s=new google.maps.LatLng(parseFloat(r),parseFloat(q));a.extend(s);o.push(s)}});var n=new google.maps.Polyline({path:o,strokeColor:p,strokeOpacity:parseFloat(jQuery(this).attr("opacity")||"0.75"),strokeWeight:parseFloat(jQuery(this).attr("width")||"4")});n.setMap(b)})});b.fitBounds(a);if(j!==-1){var k=google.maps.event.addListener(b,"idle",function(){b.setZoom(j);google.maps.event.removeListener(k)})}google.maps.event.addListener(b,"click",function(){tgm_iw.close(b)})}},"xml")};;function sack(file){this.xmlhttp=null;this.resetData=function(){this.method="POST";this.queryStringSeparator="?";this.argumentSeparator="&";this.URLString="";this.encodeURIString=true;this.execute=false;this.element=null;this.elementObj=null;this.requestFile=file;this.vars=new Object();this.responseStatus=new Array(2)};this.resetFunctions=function(){this.onLoading=function(){};this.onLoaded=function(){};this.onInteractive=function(){};this.onCompletion=function(){};this.onError=function(){};this.onFail=function(){}};this.reset=function(){this.resetFunctions();this.resetData()};this.createAJAX=function(){try{this.xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")}catch(e1){try{this.xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")}catch(e2){this.xmlhttp=null}}if(!this.xmlhttp){if(typeof XMLHttpRequest!="undefined"){this.xmlhttp=new XMLHttpRequest()}else{this.failed=true}}};this.setVar=function(name,value){this.vars[name]=Array(value,false)};this.encVar=function(name,value,returnvars){if(true==returnvars){return Array(encodeURIComponent(name),encodeURIComponent(value))}else{this.vars[encodeURIComponent(name)]=Array(encodeURIComponent(value),true)}};this.processURLString=function(string,encode){encoded=encodeURIComponent(this.argumentSeparator);regexp=new RegExp(this.argumentSeparator+"|"+encoded);varArray=string.split(regexp);for(i=0;i<varArray.length;i++){urlVars=varArray[i].split("=");if(true==encode){this.encVar(urlVars[0],urlVars[1])}else{this.setVar(urlVars[0],urlVars[1])}}};this.createURLString=function(urlstring){if(this.encodeURIString&&this.URLString.length){this.processURLString(this.URLString,true)}if(urlstring){if(this.URLString.length){this.URLString+=this.argumentSeparator+urlstring}else{this.URLString=urlstring}}this.setVar("rndval",new Date().getTime());urlstringtemp=new Array();for(key in this.vars){if(false==this.vars[key][1]&&true==this.encodeURIString){encoded=this.encVar(key,this.vars[key][0],true);delete this.vars[key];this.vars[encoded[0]]=Array(encoded[1],true);key=encoded[0]}urlstringtemp[urlstringtemp.length]=key+"="+this.vars[key][0]}if(urlstring){this.URLString+=this.argumentSeparator+urlstringtemp.join(this.argumentSeparator)}else{this.URLString+=urlstringtemp.join(this.argumentSeparator)}};this.runResponse=function(){eval(this.response)};this.runAJAX=function(urlstring){if(this.failed){this.onFail()}else{this.createURLString(urlstring);if(this.element){this.elementObj=document.getElementById(this.element)}if(this.xmlhttp){var self=this;if(this.method=="GET"){totalurlstring=this.requestFile+this.queryStringSeparator+this.URLString;this.xmlhttp.open(this.method,totalurlstring,true)}else{this.xmlhttp.open(this.method,this.requestFile,true);try{this.xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded")}catch(e){}}this.xmlhttp.onreadystatechange=function(){switch(self.xmlhttp.readyState){case 1:self.onLoading();break;case 2:self.onLoaded();break;case 3:self.onInteractive();break;case 4:self.response=self.xmlhttp.responseText;self.responseXML=self.xmlhttp.responseXML;self.responseStatus[0]=self.xmlhttp.status;self.responseStatus[1]=self.xmlhttp.statusText;if(self.execute){self.runResponse()}if(self.elementObj){elemNodeName=self.elementObj.nodeName;elemNodeName.toLowerCase();if(elemNodeName=="input"||elemNodeName=="select"||elemNodeName=="option"||elemNodeName=="textarea"){self.elementObj.value=self.response}else{self.elementObj.innerHTML=self.response}}if(self.responseStatus[0]=="200"){self.onCompletion()}else{self.onError()}self.URLString="";break}};this.xmlhttp.send(this.URLString)}}};this.reset();this.createAJAX()};
