/**
 * ColorBox v1.3.15 - a full featured, light-weight, customizable lightbox based on jQuery 1.3+
 * Copyright (c) 2010 Jack Moore - jack@colorpowered.com
 * Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
 */
(function(b,ib){var t="none",M="LoadedContent",c=false,v="resize.",o="y",q="auto",e=true,L="nofollow",m="x";function f(a,c){a=a?' id="'+i+a+'"':"";c=c?' style="'+c+'"':"";return b("<div"+a+c+"/>")}function p(a,b){b=b===m?n.width():n.height();return typeof a==="string"?Math.round(/%/.test(a)?b/100*parseInt(a,10):parseInt(a,10)):a}function U(b){return a.photo||/\.(gif|png|jpg|jpeg|bmp)(?:\?([^#]*))?(?:#(\.*))?$/i.test(b)}function cb(a){for(var c in a)if(b.isFunction(a[c])&&c.substring(0,2)!=="on")a[c]=a[c].call(l);a.rel=a.rel||l.rel||L;a.href=a.href||b(l).attr("href");a.title=a.title||l.title;return a}function w(c,a){a&&a.call(l);b.event.trigger(c)}function jb(){var b,e=i+"Slideshow_",c="click."+i,f,k;if(a.slideshow&&h[1]){f=function(){F.text(a.slideshowStop).unbind(c).bind(V,function(){if(g<h.length-1||a.loop)b=setTimeout(d.next,a.slideshowSpeed)}).bind(W,function(){clearTimeout(b)}).one(c+" "+N,k);j.removeClass(e+"off").addClass(e+"on");b=setTimeout(d.next,a.slideshowSpeed)};k=function(){clearTimeout(b);F.text(a.slideshowStart).unbind([V,W,N,c].join(" ")).one(c,f);j.removeClass(e+"on").addClass(e+"off")};a.slideshowAuto?f():k()}}function db(c){if(!O){l=c;a=cb(b.extend({},b.data(l,r)));h=b(l);g=0;if(a.rel!==L){h=b("."+G).filter(function(){return (b.data(this,r).rel||this.rel)===a.rel});g=h.index(l);if(g===-1){h=h.add(l);g=h.length-1}}if(!u){u=D=e;j.show();if(a.returnFocus)try{l.blur();b(l).one(eb,function(){try{this.focus()}catch(a){}})}catch(f){}x.css({opacity:+a.opacity,cursor:a.overlayClose?"pointer":q}).show();a.w=p(a.initialWidth,m);a.h=p(a.initialHeight,o);d.position(0);X&&n.bind(v+P+" scroll."+P,function(){x.css({width:n.width(),height:n.height(),top:n.scrollTop(),left:n.scrollLeft()})}).trigger("scroll."+P);w(fb,a.onOpen);Y.add(H).add(I).add(F).add(Z).hide();ab.html(a.close).show()}d.load(e)}}var gb={transition:"elastic",speed:300,width:c,initialWidth:"600",innerWidth:c,maxWidth:c,height:c,initialHeight:"450",innerHeight:c,maxHeight:c,scalePhotos:e,scrolling:e,inline:c,html:c,iframe:c,photo:c,href:c,title:c,rel:c,opacity:.7,preloading:e,current:"image {current} of {total}",previous:"previous",next:"next",close:"close",open:c,returnFocus:e,loop:e,slideshow:c,slideshowAuto:e,slideshowSpeed:2500,slideshowStart:"start slideshow",slideshowStop:"stop slideshow",onOpen:c,onLoad:c,onComplete:c,onCleanup:c,onClosed:c,overlayClose:e,escKey:e,arrowKey:e},r="colorbox",i="cbox",fb=i+"_open",W=i+"_load",V=i+"_complete",N=i+"_cleanup",eb=i+"_closed",Q=i+"_purge",hb=i+"_loaded",E=b.browser.msie&&!b.support.opacity,X=E&&b.browser.version<7,P=i+"_IE6",x,j,A,s,bb,T,R,S,h,n,k,J,K,Z,Y,F,I,H,ab,B,C,y,z,l,g,a,u,D,O=c,d,G=i+"Element";d=b.fn[r]=b[r]=function(c,f){var a=this,d;if(!a[0]&&a.selector)return a;c=c||{};if(f)c.onComplete=f;if(!a[0]||a.selector===undefined){a=b("<a/>");c.open=e}a.each(function(){b.data(this,r,b.extend({},b.data(this,r)||gb,c));b(this).addClass(G)});d=c.open;if(b.isFunction(d))d=d.call(a);d&&db(a[0]);return a};d.init=function(){var l="hover",m="clear:left";n=b(ib);j=f().attr({id:r,"class":E?i+"IE":""});x=f("Overlay",X?"position:absolute":"").hide();A=f("Wrapper");s=f("Content").append(k=f(M,"width:0; height:0; overflow:hidden"),K=f("LoadingOverlay").add(f("LoadingGraphic")),Z=f("Title"),Y=f("Current"),I=f("Next"),H=f("Previous"),F=f("Slideshow").bind(fb,jb),ab=f("Close"));A.append(f().append(f("TopLeft"),bb=f("TopCenter"),f("TopRight")),f(c,m).append(T=f("MiddleLeft"),s,R=f("MiddleRight")),f(c,m).append(f("BottomLeft"),S=f("BottomCenter"),f("BottomRight"))).children().children().css({"float":"left"});J=f(c,"position:absolute; width:9999px; visibility:hidden; display:none");b("body").prepend(x,j.append(A,J));s.children().hover(function(){b(this).addClass(l)},function(){b(this).removeClass(l)}).addClass(l);B=bb.height()+S.height()+s.outerHeight(e)-s.height();C=T.width()+R.width()+s.outerWidth(e)-s.width();y=k.outerHeight(e);z=k.outerWidth(e);j.css({"padding-bottom":B,"padding-right":C}).hide();I.click(d.next);H.click(d.prev);ab.click(d.close);s.children().removeClass(l);b("."+G).live("click",function(a){if(!(a.button!==0&&typeof a.button!=="undefined"||a.ctrlKey||a.shiftKey||a.altKey)){a.preventDefault();db(this)}});x.click(function(){a.overlayClose&&d.close()});b(document).bind("keydown",function(b){if(u&&a.escKey&&b.keyCode===27){b.preventDefault();d.close()}if(u&&a.arrowKey&&!D&&h[1])if(b.keyCode===37&&(g||a.loop)){b.preventDefault();H.click()}else if(b.keyCode===39&&(g<h.length-1||a.loop)){b.preventDefault();I.click()}})};d.remove=function(){j.add(x).remove();b("."+G).die("click").removeData(r).removeClass(G)};d.position=function(f,d){function b(a){bb[0].style.width=S[0].style.width=s[0].style.width=a.style.width;K[0].style.height=K[1].style.height=s[0].style.height=T[0].style.height=R[0].style.height=a.style.height}var e,h=Math.max(document.documentElement.clientHeight-a.h-y-B,0)/2+n.scrollTop(),g=Math.max(n.width()-a.w-z-C,0)/2+n.scrollLeft();e=j.width()===a.w+z&&j.height()===a.h+y?0:f;A[0].style.width=A[0].style.height="9999px";j.dequeue().animate({width:a.w+z,height:a.h+y,top:h,left:g},{duration:e,complete:function(){b(this);D=c;A[0].style.width=a.w+z+C+"px";A[0].style.height=a.h+y+B+"px";d&&d()},step:function(){b(this)}})};d.resize=function(b){if(u){b=b||{};if(b.width)a.w=p(b.width,m)-z-C;if(b.innerWidth)a.w=p(b.innerWidth,m);k.css({width:a.w});if(b.height)a.h=p(b.height,o)-y-B;if(b.innerHeight)a.h=p(b.innerHeight,o);if(!b.innerHeight&&!b.height){b=k.wrapInner("<div style='overflow:auto'></div>").children();a.h=b.height();b.replaceWith(b.children())}k.css({height:a.h});d.position(a.transition===t?0:a.speed)}};d.prep=function(m){var c="hidden";function l(s){var p,f,m,c,l=h.length,q=a.loop;d.position(s,function(){function s(){E&&j[0].style.removeAttribute("filter")}if(u){E&&o&&k.fadeIn(100);k.show();w(hb);Z.show().html(a.title);if(l>1){typeof a.current==="string"&&Y.html(a.current.replace(/\{current\}/,g+1).replace(/\{total\}/,l)).show();I[q||g<l-1?"show":"hide"]().html(a.next);H[q||g?"show":"hide"]().html(a.previous);p=g?h[g-1]:h[l-1];m=g<l-1?h[g+1]:h[0];a.slideshow&&F.show();if(a.preloading){c=b.data(m,r).href||m.href;f=b.data(p,r).href||p.href;c=b.isFunction(c)?c.call(m):c;f=b.isFunction(f)?f.call(p):f;if(U(c))b("<img/>")[0].src=c;if(U(f))b("<img/>")[0].src=f}}K.hide();a.transition==="fade"?j.fadeTo(e,1,function(){s()}):s();n.bind(v+i,function(){d.position(0)});w(V,a.onComplete)}})}if(u){var o,e=a.transition===t?0:a.speed;n.unbind(v+i);k.remove();k=f(M).html(m);k.hide().appendTo(J.show()).css({width:function(){a.w=a.w||k.width();a.w=a.mw&&a.mw<a.w?a.mw:a.w;return a.w}(),overflow:a.scrolling?q:c}).css({height:function(){a.h=a.h||k.height();a.h=a.mh&&a.mh<a.h?a.mh:a.h;return a.h}()}).prependTo(s);J.hide();b("#"+i+"Photo").css({cssFloat:t,marginLeft:q,marginRight:q});X&&b("select").not(j.find("select")).filter(function(){return this.style.visibility!==c}).css({visibility:c}).one(N,function(){this.style.visibility="inherit"});a.transition==="fade"?j.fadeTo(e,0,function(){l(0)}):l(e)}};d.load=function(u){var n,c,s,q=d.prep;D=e;l=h[g];u||(a=cb(b.extend({},b.data(l,r))));w(Q);w(W,a.onLoad);a.h=a.height?p(a.height,o)-y-B:a.innerHeight&&p(a.innerHeight,o);a.w=a.width?p(a.width,m)-z-C:a.innerWidth&&p(a.innerWidth,m);a.mw=a.w;a.mh=a.h;if(a.maxWidth){a.mw=p(a.maxWidth,m)-z-C;a.mw=a.w&&a.w<a.mw?a.w:a.mw}if(a.maxHeight){a.mh=p(a.maxHeight,o)-y-B;a.mh=a.h&&a.h<a.mh?a.h:a.mh}n=a.href;K.show();if(a.inline){f().hide().insertBefore(b(n)[0]).one(Q,function(){b(this).replaceWith(k.children())});q(b(n))}else if(a.iframe){j.one(hb,function(){var c=b("<iframe frameborder='0' style='width:100%; height:100%; border:0; display:block'/>")[0];c.name=i+ +new Date;c.src=a.href;if(!a.scrolling)c.scrolling="no";if(E)c.allowtransparency="true";b(c).appendTo(k).one(Q,function(){c.src="//about:blank"})});q(" ")}else if(a.html)q(a.html);else if(U(n)){c=new Image;c.onload=function(){var e;c.onload=null;c.id=i+"Photo";b(c).css({border:t,display:"block",cssFloat:"left"});if(a.scalePhotos){s=function(){c.height-=c.height*e;c.width-=c.width*e};if(a.mw&&c.width>a.mw){e=(c.width-a.mw)/c.width;s()}if(a.mh&&c.height>a.mh){e=(c.height-a.mh)/c.height;s()}}if(a.h)c.style.marginTop=Math.max(a.h-c.height,0)/2+"px";h[1]&&(g<h.length-1||a.loop)&&b(c).css({cursor:"pointer"}).click(d.next);if(E)c.style.msInterpolationMode="bicubic";setTimeout(function(){q(c)},1)};setTimeout(function(){c.src=n},1)}else n&&J.load(n,function(d,c,a){q(c==="error"?"Request unsuccessful: "+a.statusText:b(this).children())})};d.next=function(){if(!D){g=g<h.length-1?g+1:0;d.load()}};d.prev=function(){if(!D){g=g?g-1:h.length-1;d.load()}};d.close=function(){if(u&&!O){O=e;u=c;w(N,a.onCleanup);n.unbind("."+i+" ."+P);x.fadeTo("fast",0);j.stop().fadeTo("fast",0,function(){w(Q);k.remove();j.add(x).css({opacity:1,cursor:q}).hide();setTimeout(function(){O=c;w(eb,a.onClosed)},1)})}};d.element=function(){return b(l)};d.settings=gb;b(d.init)})(jQuery,this);

/**
 * Supertextarea
 * Created by Truth <truth@truthanduntruth.com>
 * Report Bugs: <bugs@truthanduntruth.com>
 * Copyright 2010
 */
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('(b($){$.M.K=b(1v){7 2=$(U);7 15=2.1f();7 1m={j:2.f(),q:15.f(),k:2.c(),z:15.c(),v:{A:r,1x:r,p:3},6:{\'1o\':\'1N\'},G:1M,u:{A:r,o:\'1O\',6:{},S:C},X:0,I:{o:\'1P\',6:{},1h:r},a:{A:C,o:\'\',6:{\'1o\':\'1Q\'}}};7 1k={};7 4=$.1L(1k,1m,1v);5(!4.k){4.k=2.c()}5(!4.j){4.j=2.f()}5(4.z<4.k){4.z=4.k}5(4.q<4.j){4.q=4.j}2.6(4.6);2.c(4.k).f(4.j);5(4.v.A&&4.v.p<1){4.v.p=1}7 P=[\'1K\',\'1F\',\'1E\',\'1G\',\'1H\',\'1J\',\'1I\',\'1R\'];5(1S $.M.K.V==\'s\'){$.M.K.V=0}7 14=$.M.K.V;$.M.K.V++;U.21(b(){5(U.20!=\'22\'){Z C}7 m=$(\'<1e />\').6({\'23\':\'1D\',\'1Z\':\'1Y\',\'1g-1U\':\'1T-1g\'});7 E=W(2.6(\'E-c\'))||W(2.6(\'1V-1W\'));7 1X=0;m.25(2.1f());1C(7 i=0;i<P.H;i++){m.6(P[i].1r(),2.6(P[i].1r()))}m.6(\'1A-f\',4.q);b O(c,D){B=N.1w(W(c));5(2.c()!=B){2.6({\'c\':B+\'1y\',\'D-y\':D})}}b Y(f,D){w=N.1w(W(f));5(2.f()!=w){2.6({\'f\':w+\'1y\',\'D-x\':D})}}b 12(e){5(4.u.A&&4.G&&!2.d(\'S\')){7 h;5(!$("#1c"+2.d(\'1d\')).H){h=$(\'<1e></1e>\');h.1B(\'24\',"1c"+14);2.2e(h);2.d(\'1d\',14)}l{h=$("#1c"+2.d(\'1d\'))}7 T=2.d(\'a\')?0:2.8().H;7 J=4.G-T;J=J<0?0:J;7 1a=T-4.X;7 10;7 p;7 F;5(1a<0&&4.I.o!=s){p=N.1b(1a);F=4.I.o;5(4.I.6!=s){h.6(4.I.6)}l 5(4.u.6!=s){h.6(4.u.6)}}l{p=J;F=4.u.o;5(4.u.6!=s){h.6(4.u.6)}}5(F.2A(/\\$/)){10=F.L(\'$\',\' \'+p+\' \')}l{10=p+\' \'+F}h.o(10);5(4.u.S){h.2B(b(){$(U).2C();2.d(\'S\',r)})}}5(4.G&&4.G-T<0){2.8(2.8().1s(0,4.G))}7 13=2.8().L(/&/g,\'&2z;\').L(/  /g,\'&R;&R;\').L(/<|>/g,\'&2y;\').L(/\\n/g,\'<2v />\');7 1i=m.17();5(13+\'&R;\'!=1i){m.17(13+\'&R;\');5(N.1b(m.c()+E-2.c())>3){7 B=m.c()+E;7 z=4.z;7 k=4.k;5(B>=z){O(z,\'16\')}l 5(B<=k){O(k,\'Q\')}l{O(B,\'Q\')}}5(N.1b(m.f()+E-2.f())>3){7 w=m.f()+E;7 q=4.q;7 j=4.j;5(w>=q){Y(q,\'16\')}l 5(w<=j){Y(j,\'Q\')}l{Y(w,\'Q\')}}}5(4.v.A&&e){1u(e)}}2.2I("2F").2G(b(e){5(2.8().H<4.X||4.X>0&&2.d(\'a\')){5(4.I.1h){$("17, 2H").2K({19:2.2w().2t})}e.2d();e.18();Z C}5(2.d(\'a\')){2.8(\'\')}});b 1u(e){7 1z=e.1t?e.1t:e.2u?e.2f:e.2g;7 1j=4.v.1x?" ":"\\t";7 11=2c 2b(4.v.p+1).27(1j);5(1z==9&&!e.28&&!e.29&&!e.2a){7 1q=2.19();5(2.2h){7 1l=2.2i;7 1n=2.2q;2.8(2.8().1s(0,1l)+11+2.8.2r(1n));2.1p()}l 5(2.2s){2o.2n.2j().o=11;e.2k=C}l{2.8(2.8()+11)}2.19(1q);5(e.18){e.18()}Z C}Z r}5(4.a.A){5(!2.8().H){5(4.a.6!=s){2.6(4.a.6)}2.8(4.a.o);2.d(\'a\',r)}2.1p(b(){5(2.d(\'a\')){2.8(\'\');5(4.6!=s){2.6(4.6)}2.d(\'a\',C)}});2.2l(b(){5(!2.8().H){2.d(\'a\',r);5(4.a.6!=s){2.6(4.a.6)}2.8(4.a.o)}})}2.6({\'D\':\'16\'}).2m(b(e){12(e)}).2p(\'2J 2D\',b(){2E(12,26)});12()})}})(2x);',62,171,'||area||justice|if|css|var|val||plch|function|height|data||width||dsm||minw|minh|else|beh||text|num|maxw|true|undefined||dsrm|tabr|nw|||maxh|use|nh|false|overflow|line|msg|maxl|length|dstg|txt|supertextarea|replace|fn|Math|eval_height|rep_css|hidden|nbsp|rmv|tl|this|counter|parseInt|minl|eval_width|return|remtxt|str|update|ac|idcounter|cont|auto|html|preventDefault|scrollTop|rem|abs|textarea_dsrm|partner|div|parent|word|slide|bc|sp|love|ss|hope|se|color|focus|os|toString|substring|keyCode|tab_replace|faith|floor|space|px|key|max|attr|for|absolute|paddingBottom|paddingRight|paddingLeft|fontSize|fontFamily|lineHeight|paddingTop|extend|1000|black|Remaining|Required|gray|fontWeight|typeof|break|wrap|font|size|goalheight|none|display|type|each|textarea|position|id|appendTo|250|join|shiftKey|ctrlKey|altKey|Array|new|stopPropagation|after|charCode|which|setSelectionRange|selectionStart|createRange|returnValue|blur|keydown|selection|document|live|selectionEnd|substr|createTextRange|top|charChode|br|offset|jQuery|gt|amp|match|click|hide|paste|setTimeout|form|submit|body|parents|input|animate'.split('|'),0,{}));

/**
 * Twitter
 * Copyright (c) 2010 Thomas Billenstein, http://thomasbillenstein.com/jTweetsAnywhere
 */
(function(e){e.fn.jTweetsAnywhere=function(a){a=e.extend({username:"demotape",list:null,searchParams:null,count:0,tweetProfileImagePresent:null,tweetFilter:defaultTweetFilter,showTweetFeed:true,showFollowButton:false,showConnectButton:false,showLoginInfo:false,showTweetBox:false,mainDecorator:defaultMainDecorator,tweetFeedDecorator:defaultTweetFeedDecorator,tweetDecorator:defaultTweetDecorator,tweetProfileImageDecorator:defaultTweetProfileImageDecorator,tweetBodyDecorator:defaultTweetBodyDecorator, tweetUsernameDecorator:defaultTweetUsernameDecorator,tweetTextDecorator:defaultTweetTextDecorator,tweetAttributesDecorator:defaultTweetAttributesDecorator,tweetTimestampDecorator:defaultTweetTimestampDecorator,tweetSourceDecorator:defaultTweetSourceDecorator,tweetGeoLocationDecorator:defaultTweetGeoLocationDecorator,tweetInReplyToDecorator:defaultTweetInReplyToDecorator,tweetRetweeterDecorator:defaultTweetRetweeterDecorator,tweetFeedControlsDecorator:defaultTweetFeedControlsDecorator,tweetFeedControlsMoreBtnDecorator:defaultTweetFeedControlsMoreBtnDecorator, tweetFeedControlsPrevBtnDecorator:defaultTweetFeedControlsPrevBtnDecorator,tweetFeedControlsNextBtnDecorator:defaultTweetFeedControlsNextBtnDecorator,tweetFeedAutorefreshTriggerDecorator:defaultTweetFeedAutorefreshTriggerDecorator,tweetFeedAutorefreshTriggerContentDecorator:defaultTweetFeedAutorefreshTriggerContentDecorator,connectButtonDecorator:defaultConnectButtonDecorator,loginInfoDecorator:defaultLoginInfoDecorator,loginInfoContentDecorator:defaultLoginInfoContentDecorator,followButtonDecorator:defaultFollowButtonDecorator, tweetBoxDecorator:defaultTweetBoxDecorator,linkDecorator:defaultLinkDecorator,usernameDecorator:defaultUsernameDecorator,hashtagDecorator:defaultHashtagDecorator,loadingDecorator:defaultLoadingDecorator,errorDecorator:defaultErrorDecorator,noDataDecorator:defaultNoDataDecorator,tweetTimestampFormatter:defaultTweetTimestampFormatter,tweetTimestampTooltipFormatter:defaultTweetTimestampTooltipFormatter,tweetVisualizer:defaultTweetVisualizer,loadingIndicatorVisualizer:defaultLoadingIndicatorVisualizer, autorefreshTriggerVisualizer:defaultAutorefreshTriggerVisualizer,onDataRequestHandler:defaultOnDataRequestHandler,onRateLimitDataHandler:defaultOnRateLimitDataHandler,_tweetFeedConfig:{expandHovercards:false,showTimestamp:{refreshInterval:0},showSource:false,showGeoLocation:true,showInReplyTo:true,showProfileImages:null,showUserScreenNames:null,showUserFullNames:false,includeRetweets:true,paging:{mode:"none",_limit:0,_offset:0},autorefresh:{mode:"none",interval:60,duration:3600,_startTime:null,_triggerElement:null}, _pageParam:0,_maxId:null,_recLevel:0,_noData:false,_clearBeforePopulate:false},_tweetBoxConfig:{counter:true,width:515,height:65,label:"What's happening?",defaultContent:"",onTweet:function(){}},_connectButtonConfig:{size:"medium"},_baseSelector:null,_baseElement:null,_tweetFeedElement:null,_tweetFeedControlsElement:null,_followButtonElement:null,_loginInfoElement:null,_connectButtonElement:null,_tweetBoxElement:null,_loadingIndicatorElement:null,_noDataElement:null,_tweetsCache:[],_autorefreshTweetsCache:[], _stats:{dataRequestCount:0,rateLimitPreventionCount:0,rateLimit:{remaining_hits:150,hourly_limit:150}}},a);if(a.mainDecorator){a._baseSelector=this.selector;if(typeof a.username!="string"){if(!a.searchParams)a.searchParams=["q=from:"+a.username.join(" OR from:")];a.username=a.username[0]}typeof a.showTweetFeed=="object"&&e.extend(true,a._tweetFeedConfig,a.showTweetFeed);if(typeof a.showTweetBox=="object"){a._tweetBoxConfig=a.showTweetBox;a.showTweetBox=true}if(typeof a.showConnectButton=="object"){a._connectButtonConfig= a.showConnectButton;a.showConnectButton=true}if(a._tweetFeedConfig.showProfileImages==null)a._tweetFeedConfig.showProfileImages=a.tweetProfileImagePresent;if(a._tweetFeedConfig.showProfileImages==null)a._tweetFeedConfig.showProfileImages=(a.list||a.searchParams)&&a.tweetProfileImageDecorator;if(a._tweetFeedConfig.showUserScreenNames==null){if(a.list||a.searchParams)a._tweetFeedConfig.showUserScreenNames=true;if(!a.tweetUsernameDecorator)a._tweetFeedConfig.showUserScreenNames=false}if(a._tweetFeedConfig.showUserFullNames== null){if(a.list||a.searchParams)a._tweetFeedConfig.showUserFullNames=true;if(!a.tweetUsernameDecorator)a._tweetFeedConfig.showUserFullNames=false}a.count=validateRange(a.count,0,a.searchParams?100:20);a._tweetFeedConfig.autorefresh.interval=Math.max(30,a._tweetFeedConfig.autorefresh.interval);a._tweetFeedConfig.paging._offset=0;a._tweetFeedConfig.paging._limit=a.count;if(a.count==0||!a.showTweetFeed){a.tweetFeedDecorator=null;a.tweetFeedControlsDecorator=null}if(a._tweetFeedConfig.paging.mode=="none")a.tweetFeedControlsDecorator= null;if(!a.showFollowButton)a.followButtonDecorator=null;if(!a.showTweetBox)a.tweetBoxDecorator=null;if(!a.showConnectButton)a.connectButtonDecorator=null;if(!a.showLoginInfo)a.loginInfoDecorator=null;if(!a._tweetFeedConfig.showTimestamp)a.tweetTimestampDecorator=null;if(!a._tweetFeedConfig.showSource)a.tweetSourceDecorator=null;if(!a._tweetFeedConfig.showGeoLocation)a.tweetGeoLocationDecorator=null;if(!a._tweetFeedConfig.showInReplyTo)a.tweetInReplyToDecorator=null;e.ajaxSetup({cache:true});return this.each(function(){a._baseElement= e(this);a._tweetFeedElement=a.tweetFeedDecorator?e(a.tweetFeedDecorator(a)):null;a._tweetFeedControlsElement=a.tweetFeedControlsDecorator?e(a.tweetFeedControlsDecorator(a)):null;a._followButtonElement=a.followButtonDecorator?e(a.followButtonDecorator(a)):null;a._tweetBoxElement=a.tweetBoxDecorator?e(a.tweetBoxDecorator(a)):null;a._connectButtonElement=a.connectButtonDecorator?e(a.connectButtonDecorator(a)):null;a._loginInfoElement=a.loginInfoDecorator?e(a.loginInfoDecorator(a)):null;a.mainDecorator(a); populateTweetFeed(a);populateAnywhereControls(a);bindEventHandlers(a);a._tweetFeedConfig.autorefresh._startTime=(new Date).getTime();startAutorefresh(a);startTimestampRefresh(a)})}};defaultMainDecorator=function(a){a._tweetFeedElement&&a._baseElement.append(a._tweetFeedElement);a._tweetFeedControlsElement&&a._baseElement.append(a._tweetFeedControlsElement);a._connectButtonElement&&a._baseElement.append(a._connectButtonElement);a._loginInfoElement&&a._baseElement.append(a._loginInfoElement);a._followButtonElement&& a._baseElement.append(a._followButtonElement);a._tweetBoxElement&&a._baseElement.append(a._tweetBoxElement)};defaultTweetFeedControlsDecorator=function(a){var b="";if(a._tweetFeedConfig.paging.mode=="prev-next"){if(a.tweetFeedControlsPrevBtnDecorator)b+=a.tweetFeedControlsPrevBtnDecorator(a);if(a.tweetFeedControlsNextBtnDecorator)b+=a.tweetFeedControlsNextBtnDecorator(a)}else if(a._tweetFeedConfig.paging.mode!="endless-scroll")if(a.tweetFeedControlsMoreBtnDecorator)b+=a.tweetFeedControlsMoreBtnDecorator(a); return'<div class="jta-tweet-list-controls">'+b+"</div>"};defaultTweetFeedControlsMoreBtnDecorator=function(){return'<span class="jta-tweet-list-controls-button jta-tweet-list-controls-button-more">More</span>'};defaultTweetFeedControlsPrevBtnDecorator=function(){return'<span class="jta-tweet-list-controls-button jta-tweet-list-controls-button-prev">Prev</span>'};defaultTweetFeedControlsNextBtnDecorator=function(){return'<span class="jta-tweet-list-controls-button jta-tweet-list-controls-button-next">Next</span>'}; defaultTweetFeedAutorefreshTriggerDecorator=function(a,b){var c="";if(b.tweetFeedAutorefreshTriggerContentDecorator)c=b.tweetFeedAutorefreshTriggerContentDecorator(a,b);return'<li class="jta-tweet-list-autorefresh-trigger">'+c+"</li>"};defaultTweetFeedAutorefreshTriggerContentDecorator=function(a){return'<span class="jta-tweet-list-autorefresh-trigger-content">'+(""+a+" new "+(a>1?" tweets":" tweet"))+"</span>"};defaultTweetFeedDecorator=function(){return'<ul class="jta-tweet-list"></ul>'};defaultTweetDecorator= function(a,b){var c="";if(b._tweetFeedConfig.showProfileImages)c+=b.tweetProfileImageDecorator(a,b);if(b.tweetBodyDecorator)c+=b.tweetBodyDecorator(a,b);c+='<div class="jta-clear">&nbsp;</div>';return'<li class="jta-tweet-list-item">'+c+"</li>"};defaultTweetProfileImageDecorator=function(a){a=a.retweeted_status||a;var b=a.user?a.user.screen_name:a.from_user;return'<div class="jta-tweet-profile-image">'+('<a class="jta-tweet-profile-image-link" href="http://twitter.com/'+b+'" target="_blank"><img src="'+ (a.user?a.user.profile_image_url:a.profile_image_url)+'" alt="'+b+'"'+(isAnywherePresent()?"":' title="'+b+'"')+"/></a>")+"</div>"};defaultTweetBodyDecorator=function(a,b){var c="";if(b.tweetTextDecorator)c+=b.tweetTextDecorator(a,b);if(b.tweetAttributesDecorator)c+=b.tweetAttributesDecorator(a,b);return'<div class="jta-tweet-body '+(b._tweetFeedConfig.showProfileImages?"jta-tweet-body-list-profile-image-present":"")+'">'+c+"</div>"};defaultTweetTextDecorator=function(a,b){var c=a.text;if(a.retweeted_status&& (b._tweetFeedConfig.showUserScreenNames||b._tweetFeedConfig.showUserScreenNames==null||b._tweetFeedConfig.showUserFullNames||b._tweetFeedConfig.showUserFullNames==null))c=a.retweeted_status.text;if(b.linkDecorator)c=b.linkDecorator(c,b);if(b.usernameDecorator)c=b.usernameDecorator(c,b);if(b.hashtagDecorator)c=b.hashtagDecorator(c,b);if(b._tweetFeedConfig.showUserScreenNames||b._tweetFeedConfig.showUserFullNames||a.retweeted_status&&(b._tweetFeedConfig.showUserScreenNames==null||b._tweetFeedConfig.showUserFullNames== null))c=b.tweetUsernameDecorator(a,b)+" "+c;return'<span class="jta-tweet-text">'+c+"</span>"};defaultTweetUsernameDecorator=function(a,b){var c=a.retweeted_status||a,d=c.user?c.user.screen_name:c.from_user;c=c.user?c.user.name:null;var f;if(d&&(b._tweetFeedConfig.showUserScreenNames||b._tweetFeedConfig.showUserScreenNames==null&&a.retweeted_status))f='<span class="jta-tweet-user-screen-name"><a class="jta-tweet-user-screen-name-link" href="http://twitter.com/'+d+'" target="_blank">'+d+"</a></span>"; var g;if(c&&(b._tweetFeedConfig.showUserFullNames||b._tweetFeedConfig.showUserFullNames==null&&a.retweeted_status))g='<span class="jta-tweet-user-full-name">'+(f?" (":"")+'<a class="jta-tweet-user-full-name-link" href="http://twitter.com/'+d+'" name="'+d+'" target="_blank">'+c+"</a>"+(f?")":"")+"</span>";d="";if(f)d+=f;if(g){if(f)d+=" ";d+=g}if(f||g)d='<span class="jta-tweet-user-name">'+(a.retweeted_status?"RT ":"")+d+"</span>";return d};defaultTweetAttributesDecorator=function(a,b){var c="";if(b.tweetTimestampDecorator|| b.tweetSourceDecorator||b.tweetGeoLocationDecorator||b.tweetInReplyToDecorator||a.retweeted_status&&b.tweetRetweeterDecorator){c+='<span class="jta-tweet-attributes">';if(b.tweetTimestampDecorator)c+=b.tweetTimestampDecorator(a,b);if(b.tweetSourceDecorator)c+=b.tweetSourceDecorator(a,b);if(b.tweetGeoLocationDecorator)c+=b.tweetGeoLocationDecorator(a,b);if(b.tweetInReplyToDecorator)c+=b.tweetInReplyToDecorator(a,b);if(a.retweeted_status&&b.tweetRetweeterDecorator)c+=b.tweetRetweeterDecorator(a,b); c+="</span>"}return c};defaultTweetTimestampDecorator=function(a,b){var c=a.retweeted_status||a,d=formatDate(c.created_at),f=b.tweetTimestampFormatter(d),g=b.tweetTimestampTooltipFormatter(d);return'<span class="jta-tweet-timestamp"><a class="jta-tweet-timestamp-link" data-timestamp="'+d+'" href="http://twitter.com/'+(c.user?c.user.screen_name:c.from_user)+"/status/"+c.id+'" target="_blank" title="'+g+'">'+f+"</a></span>"};defaultTweetTimestampTooltipFormatter=function(a){return(new Date(a)).toLocaleString()}; defaultTweetTimestampFormatter=function(a){var b=new Date,c=parseInt((b.getTime()-Date.parse(a))/1E3),d="";if(c<60)d+=c+" second"+(c==1?"":"s")+" ago";else if(c<3600){b=parseInt((c+30)/60);d+=b+" minute"+(b==1?"":"s")+" ago"}else if(c<86400){b=parseInt((c+1800)/3600);d+=b+" hour"+(b==1?"":"s")+" ago"}else{a=new Date(a);a.getHours();a.getMinutes();d+=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][a.getMonth()]+" "+a.getDate();if(a.getFullYear()<b.getFullYear())d+=", "+a.getFullYear(); b=parseInt((c+43200)/86400);d+=" ("+b+" day"+(b==1?"":"s")+" ago)"}return d};exTimestampFormatter=function(a){var b=parseInt(((new Date).getTime()-Date.parse(a))/1E3),c="";if(b<60)c+="less than a minute ago";else if(b<3600){b=parseInt((b+30)/60);c+=b+" minute"+(b==1?"":"s")+" ago"}else if(b<86400){b=parseInt((b+1800)/3600);c+="about "+b+" hour"+(b==1?"":"s")+" ago"}else{b=parseInt((b+43200)/86400);c+="about "+b+" day"+(b==1?"":"s")+" ago";a=new Date(a);b="AM";var d=a.getHours();if(d>12){d-=12;b="PM"}var f= a.getMinutes();c+=" ("+d+":"+((f<10?"0":"")+f)+" "+b+" "+(a.getMonth()+1)+"/"+a.getDate()+"/"+a.getFullYear()+")"}return c};defaultTweetSourceDecorator=function(a){return'<span class="jta-tweet-source"> via <span class="jta-tweet-source-link">'+(a.retweeted_status||a).source.replace(/\&lt\;/gi,"<").replace(/\&gt\;/gi,">").replace(/\&quot\;/gi,'"')+"</span></span>"};defaultTweetGeoLocationDecorator=function(a){var b="";a=a.retweeted_status||a;var c;if(a.geo&&a.geo.coordinates)c=a.geo.coordinates.join(); else if(a.place&&a.place.full_name)c=a.place.full_name;if(c){b="here";if(a.place&&a.place.full_name)b=a.place.full_name;b='<span class="jta-tweet-location"> from <a class="jta-tweet-location-link" href="'+("http://maps.google.com/maps?q="+c)+'" target="_blank">'+b+"</a></span>"}return b};defaultTweetInReplyToDecorator=function(a){a=a.retweeted_status||a;var b="";if(a.in_reply_to_status_id&&a.in_reply_to_screen_name)b='<span class="jta-tweet-inreplyto"> <a class="jta-tweet-inreplyto-link" href="http://twitter.com/'+ a.in_reply_to_screen_name+"/status/"+a.in_reply_to_status_id+'" target="_blank">in reply to '+a.in_reply_to_screen_name+"</a></span>";return b};defaultTweetRetweeterDecorator=function(a){var b="";if(a.retweeted_status){b=a.user?a.user.screen_name:a.from_user;a=(a.retweeted_status.retweet_count||0)-1;var c=" and "+a+(a>1?" others":" other");b='<br/><span class="jta-tweet-retweeter">Retweeted by '+('<a class="jta-tweet-retweeter-link" href="http://twitter.com/'+b+'" target="_blank">'+b+"</a>")+(a>0? c:"")+"</span>"}return b};defaultConnectButtonDecorator=function(){return'<div class="jta-connect-button"></div>'};defaultLoginInfoDecorator=function(){return'<div class="jta-login-info"></div>'};defaultLoginInfoContentDecorator=function(a,b){var c="";if(b.isConnected()){c=b.currentUser.data("screen_name");var d=b.currentUser.data("profile_image_url");c='<div class="jta-login-info-profile-image"><a href="http://twitter.com/'+c+'" target="_blank"><img src="'+d+'" alt="'+c+'" title="'+c+'"/></a></div><div class="jta-login-info-block"><div class="jta-login-info-screen-name"><a href="http://twitter.com/'+ c+'" target="_blank">'+c+'</a></div><div class="jta-login-info-sign-out">Sign out</div></div><div class="jta-clear">&nbsp;</div>'}return c};defaultFollowButtonDecorator=function(){return'<div class="jta-follow-button"></div>'};defaultTweetBoxDecorator=function(){return'<div class="jta-tweet-box"></div>'};defaultLinkDecorator=function(a){return a.replace(/((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi,'<a href="$1" class="jta-tweet-a jta-tweet-link" target="_blank" rel="nofollow">$1</a>')}; defaultUsernameDecorator=function(a){return isAnywherePresent()?a:a.replace(/@([a-zA-Z0-9_]+)/gi,'@<a href="http://twitter.com/$1" class="jta-tweet-a twitter-anywhere-user" target="_blank" rel="nofollow">$1</a>')};defaultHashtagDecorator=function(a){return a.replace(/#([a-zA-Z0-9_]+)/gi,'<a href="http://search.twitter.com/search?q=%23$1" class="jta-tweet-a jta-tweet-hashtag" title="#$1" target="_blank" rel="nofollow">#$1</a>')};defaultLoadingDecorator=function(){return'<li class="jta-loading">loading ...</li>'}; defaultErrorDecorator=function(a){return'<li class="jta-error">ERROR: '+a+"</li>"};defaultNoDataDecorator=function(){return'<li class="jta-nodata">No more data</li>'};defaultTweetFilter=function(){return true};defaultTweetVisualizer=function(a,b,c){a[c](b)};defaultLoadingIndicatorVisualizer=function(a,b,c,d){defaultVisualizer(a,b,"append","fadeIn",600,"fadeOut",200,d)};defaultAutorefreshTriggerVisualizer=function(a,b,c,d){defaultVisualizer(a,b,"prepend","slideDown",600,"fadeOut",200,d)};defaultVisualizer= function(a,b,c,d,f,g,k,h){var j=function(){h&&h()};if(a){b.hide();a[c](b);b[d](f,j)}else b[g](k,function(){b.remove();j()})};defaultOnDataRequestHandler=function(){return true};defaultOnRateLimitDataHandler=function(){};updateLoginInfoElement=function(a,b){if(a._loginInfoElement&&a.loginInfoContentDecorator){a._loginInfoElement.children().remove();a._loginInfoElement.append(a.loginInfoContentDecorator(a,b));e(a._baseSelector+" .jta-login-info-sign-out").bind("click",function(){twttr.anywhere.signOut()})}}; getFeedUrl=function(a,b){var c="https:"==document.location.protocol?"https:":"http:";if(a.searchParams)c+="//search.twitter.com/search.json?"+(a.searchParams instanceof Array?a.searchParams.join("&"):a.searchParams)+"&rpp=100";else if(a.list)c+="//api.twitter.com/1/"+a.username+"/lists/"+a.list+"/statuses.json?per_page=20";else{c+="//api.twitter.com/1/statuses/user_timeline.json?screen_name="+a.username+"&count=20";if(a._tweetFeedConfig.includeRetweets)c+="&include_rts=true"}if(b)c+=(a._tweetFeedConfig._maxId? "&max_id="+a._tweetFeedConfig._maxId:"")+"&page="+a._tweetFeedConfig._pageParam;c+="&callback=?";return c};isAnywherePresent=function(){return typeof twttr!="undefined"};clearTweetFeed=function(a){a._tweetFeedElement&&a._tweetFeedElement.empty()};populateTweetFeed=function(a){a.tweetDecorator&&a._tweetFeedElement&&getPagedTweets(a,function(b,c){c._tweetFeedConfig._clearBeforePopulate&&clearTweetFeed(c);hideLoadingIndicator(c,function(){e.each(b,function(d,f){c.tweetVisualizer(c._tweetFeedElement, e(c.tweetDecorator(f,c)),"append",c)});if(c._tweetFeedConfig._noData&&c.noDataDecorator&&!c._tweetFeedConfig._noDataElement){c._tweetFeedConfig._noDataElement=e(c.noDataDecorator(c));c._tweetFeedElement.append(c._tweetFeedConfig._noDataElement)}c._tweetFeedConfig._clearBeforePopulate&&c._tweetFeedElement.scrollTop(0);addHovercards(c)})})};populateTweetFeed2=function(a){if(a._tweetFeedElement&&a._autorefreshTweetsCache.length>0)if(a._tweetFeedConfig.autorefresh.mode=="trigger-insert")if(a._tweetFeedConfig.autorefresh._triggerElement)a.tweetFeedAutorefreshTriggerContentDecorator&& a._tweetFeedConfig.autorefresh._triggerElement.html(a.tweetFeedAutorefreshTriggerContentDecorator(a._autorefreshTweetsCache.length,a));else{if(a.tweetFeedAutorefreshTriggerDecorator){a._tweetFeedConfig.autorefresh._triggerElement=e(a.tweetFeedAutorefreshTriggerDecorator(a._autorefreshTweetsCache.length,a));a._tweetFeedConfig.autorefresh._triggerElement.bind("click",function(){a.autorefreshTriggerVisualizer(null,a._tweetFeedConfig.autorefresh._triggerElement,a,function(){insertTriggerTweets(a)});a._tweetFeedConfig.autorefresh._triggerElement= null});a.autorefreshTriggerVisualizer(a._tweetFeedElement,a._tweetFeedConfig.autorefresh._triggerElement,a)}}else insertTriggerTweets(a)};insertTriggerTweets=function(a){if(a.tweetDecorator&&a._autorefreshTweetsCache.length>0){for(;a._autorefreshTweetsCache.length>0;){var b=a._autorefreshTweetsCache.pop();a._tweetsCache.unshift(b);a._tweetFeedConfig.paging._offset++;a.tweetVisualizer(a._tweetFeedElement,e(a.tweetDecorator(b,a)),"prepend",a)}addHovercards(a)}};addHovercards=function(a){isAnywherePresent()&& twttr.anywhere(function(b){b(a._baseSelector+" .jta-tweet-list").hovercards({expanded:a._tweetFeedConfig.expandHovercards});b(a._baseSelector+" .jta-tweet-profile-image img").hovercards({expanded:a._tweetFeedConfig.expandHovercards,username:function(c){return c.alt}});b(a._baseSelector+" .jta-tweet-retweeter-link").hovercards({expanded:a._tweetFeedConfig.expandHovercards,username:function(c){return c.text}});b(a._baseSelector+" .jta-tweet-user-screen-name-link").hovercards({expanded:a._tweetFeedConfig.expandHovercards, username:function(c){return c.text}});b(a._baseSelector+" .jta-tweet-user-full-name-link").hovercards({expanded:a._tweetFeedConfig.expandHovercards,username:function(c){return c.name}})})};populateAnywhereControls=function(a){isAnywherePresent()&&twttr.anywhere(function(b){a.tweetBoxDecorator&&b(a._baseSelector+" .jta-tweet-box").tweetBox(a._tweetBoxConfig);a.followButtonDecorator&&b(a._baseSelector+" .jta-follow-button").followButton(a.username);if(a.connectButtonDecorator){var c=e.extend({authComplete:function(){updateLoginInfoElement(a, b)},signOut:function(){updateLoginInfoElement(a,b)}},a._connectButtonConfig);b(a._baseSelector+" .jta-connect-button").connectButton(c);updateLoginInfoElement(a,b)}})};bindEventHandlers=function(a){if(a.tweetFeedControlsDecorator)if(a._tweetFeedConfig.paging.mode=="prev-next"){e(a._baseSelector+" .jta-tweet-list-controls-button-prev").bind("click",function(){!isLoading(a)&&a._tweetFeedConfig.paging._offset>0&&prevPage(a,true)});e(a._baseSelector+" .jta-tweet-list-controls-button-next").bind("click", function(){isLoading(a)||nextPage(a,true)})}else a._tweetFeedConfig.paging.mode=="endless-scroll"?a._tweetFeedElement.bind("scroll",function(){!isLoading(a)&&e(this)[0].scrollHeight-e(this).scrollTop()==e(this).outerHeight()&&nextPage(a,false)}):e(a._baseSelector+" .jta-tweet-list-controls-button-more").bind("click",function(){isLoading(a)||nextPage(a,false)})};nextPage=function(a,b){doPage(a,b,Math.min(a._tweetFeedConfig.paging._offset+a._tweetFeedConfig.paging._limit,a._tweetsCache.length))};prevPage= function(a,b){doPage(a,b,Math.max(0,a._tweetFeedConfig.paging._offset-a._tweetFeedConfig.paging._limit))};doPage=function(a,b,c){a._tweetFeedConfig.paging._offset=c;a._tweetFeedConfig._clearBeforePopulate=b;populateTweetFeed(a)};startAutorefresh=function(a){if(a._tweetFeedConfig.autorefresh.mode!="none"&&a._tweetFeedConfig.paging.mode!="prev-next"&&a._tweetFeedConfig.autorefresh.duration!=0&&(a._tweetFeedConfig.autorefresh.duration<0||(new Date).getTime()-a._tweetFeedConfig.autorefresh._startTime<= a._tweetFeedConfig.autorefresh.duration*1E3))window.setTimeout(function(){processAutorefresh(a)},a._tweetFeedConfig.autorefresh.interval*1E3)};stopAutorefresh=function(a){a._tweetFeedConfig.autorefresh.duration=0};processAutorefresh=function(a){if(a._tweetFeedConfig.autorefresh.duration!=0){getRateLimitedData(a,true,getFeedUrl(a,false),function(b,c){var d=(b.results||b).slice(0);d.reverse();e.each(d,function(f,g){isTweetInCache(g,c)||c.tweetFilter(g,c)&&c._autorefreshTweetsCache.unshift(g)});populateTweetFeed2(c)}); startAutorefresh(a)}};startTimestampRefresh=function(a){a.tweetTimestampDecorator&&typeof a._tweetFeedConfig.showTimestamp=="object"&&a._tweetFeedConfig.showTimestamp.refreshInterval>0&&window.setTimeout(function(){processTimestampRefresh(a)},a._tweetFeedConfig.showTimestamp.refreshInterval*1E3)};processTimestampRefresh=function(a){e.each(a._tweetFeedElement.find(".jta-tweet-timestamp-link"),function(b,c){var d=e(c).attr("data-timestamp");e(c).html(a.tweetTimestampFormatter(d))});startTimestampRefresh(a)}; isTweetInCache=function(a,b){for(var c=b._tweetsCache.length,d=0;d<c;d++)if(a.id==b._tweetsCache[d].id)return true;return false};showLoadingIndicator=function(a){if(a._tweetFeedElement&&a.loadingDecorator&&!a._loadingIndicatorElement){a._loadingIndicatorElement=e(a.loadingDecorator(a));a.loadingIndicatorVisualizer(a._tweetFeedElement,a._loadingIndicatorElement,a,null);a._tweetFeedElement.scrollTop(1E6)}};hideLoadingIndicator=function(a,b){if(a._loadingIndicatorElement){a.loadingIndicatorVisualizer(null, a._loadingIndicatorElement,a,b);a._loadingIndicatorElement=null}else b&&b()};isLoading=function(a){return a._loadingIndicatorElement!=null};formatDate=function(a){return a.replace(/^([a-z]{3})( [a-z]{3} \d\d?)(.*)( \d{4})$/i,"$1,$2$4$3")};validateRange=function(a,b,c){if(a<b)a=b;if(a>c)a=c;return a};showError=function(a,b){a.errorDecorator&&a._tweetFeedElement&&a._tweetFeedElement.append(a.errorDecorator(b,a))};getPagedTweets=function(a,b){a._tweetFeedConfig._recLevel=0;getRecPagedTweets(a,a._tweetFeedConfig.paging._offset, a._tweetFeedConfig.paging._limit,b)};getRecPagedTweets=function(a,b,c,d){++a._tweetFeedConfig._recLevel;if(b+c<=a._tweetsCache.length||a._tweetFeedConfig._recLevel>3||a._tweetFeedConfig._noData){if(b+c>a._tweetsCache.length)c=Math.max(0,a._tweetsCache.length-b);for(var f=[],g=0;g<c;g++)f[g]=a._tweetsCache[b+g];d(f,a)}else{++a._tweetFeedConfig._pageParam;getRateLimitedData(a,false,getFeedUrl(a,true),function(k,h){var j=k.results||k;if(j.length==0)h._tweetFeedConfig._noData=true;else e.each(j,function(l, i){if(i.id_str)i.id=i.id_str;if(i.in_reply_to_status_id_str)i.in_reply_to_status_id=i.in_reply_to_status_id_str;if(!h._tweetFeedConfig._maxId)h._tweetFeedConfig._maxId=i.id;h.tweetFilter(i,h)&&h._tweetsCache.push(i)});getRecPagedTweets(h,b,c,d)})}};getRateLimitedData=function(a,b,c,d){getRateLimit(a,function(f){if(f&&f.remaining_hits<=0){a._stats.rateLimitPreventionCount++;hideLoadingIndicator(a,null)}else getData(a,b,c,d)})};getData=function(a,b,c,d){a._stats.dataRequestCount++;if(a.onDataRequestHandler(a._stats, a)){b||showLoadingIndicator(a);e.getJSON(c,function(f){f.error?showError(a,f.error):d(f,a)})}else hideLoadingIndicator(a,null)};getRateLimit=function(a,b){e.getJSON("http://api.twitter.com/1/account/rate_limit_status.json?callback=?",function(c){a._stats.rateLimit=c;a.onRateLimitDataHandler(a._stats,a);b(c)})}})(jQuery);

/**
 * jQuery Star Rating Plugin v3.13 - 2009-03-26
 * Home: http://www.fyneworks.com/jquery/star-rating/
 * Code: http://code.google.com/p/jquery-star-rating-plugin/
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
*/
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}(';5(29.1j)(7($){5($.1L.1J)1I{1t.1H("1K",J,H)}1M(e){};$.n.3=7(i){5(4.Q==0)k 4;5(A I[0]==\'1h\'){5(4.Q>1){8 j=I;k 4.W(7(){$.n.3.y($(4),j)})};$.n.3[I[0]].y(4,$.1T(I).1U(1)||[]);k 4};8 i=$.12({},$.n.3.1s,i||{});$.n.3.K++;4.2a(\'.9-3-1f\').o(\'9-3-1f\').W(7(){8 a,l=$(4);8 b=(4.23||\'21-3\').1v(/\\[|\\]/g,\'Z\').1v(/^\\Z+|\\Z+$/g,\'\');8 c=$(4.1X||1t.1W);8 d=c.6(\'3\');5(!d||d.18!=$.n.3.K)d={z:0,18:$.n.3.K};8 e=d[b];5(e)a=e.6(\'3\');5(e&&a)a.z++;x{a=$.12({},i||{},($.1b?l.1b():($.1S?l.6():s))||{},{z:0,F:[],v:[]});a.w=d.z++;e=$(\'<1R V="9-3-1Q"/>\');l.1P(e);e.o(\'3-15-T-17\');5(l.S(\'R\'))a.m=H;e.1c(a.E=$(\'<P V="3-E"><a 14="\'+a.E+\'">\'+a.1d+\'</a></P>\').1g(7(){$(4).3(\'O\');$(4).o(\'9-3-N\')}).1i(7(){$(4).3(\'u\');$(4).G(\'9-3-N\')}).1l(7(){$(4).3(\'r\')}).6(\'3\',a))};8 f=$(\'<P V="9-3 q-\'+a.w+\'"><a 14="\'+(4.14||4.1p)+\'">\'+4.1p+\'</a></P>\');e.1c(f);5(4.11)f.S(\'11\',4.11);5(4.1r)f.o(4.1r);5(a.1F)a.t=2;5(A a.t==\'1u\'&&a.t>0){8 g=($.n.10?f.10():0)||a.1w;8 h=(a.z%a.t),Y=1y.1z(g/a.t);f.10(Y).1A(\'a\').1B({\'1C-1D\':\'-\'+(h*Y)+\'1E\'})};5(a.m)f.o(\'9-3-1o\');x f.o(\'9-3-1G\').1g(7(){$(4).3(\'1n\');$(4).3(\'D\')}).1i(7(){$(4).3(\'u\');$(4).3(\'C\')}).1l(7(){$(4).3(\'r\')});5(4.L)a.p=f;l.1q();l.1N(7(){$(4).3(\'r\')});f.6(\'3.l\',l.6(\'3.9\',f));a.F[a.F.Q]=f[0];a.v[a.v.Q]=l[0];a.q=d[b]=e;a.1O=c;l.6(\'3\',a);e.6(\'3\',a);f.6(\'3\',a);c.6(\'3\',d)});$(\'.3-15-T-17\').3(\'u\').G(\'3-15-T-17\');k 4};$.12($.n.3,{K:0,D:7(){8 a=4.6(\'3\');5(!a)k 4;5(!a.D)k 4;8 b=$(4).6(\'3.l\')||$(4.U==\'13\'?4:s);5(a.D)a.D.y(b[0],[b.M(),$(\'a\',b.6(\'3.9\'))[0]])},C:7(){8 a=4.6(\'3\');5(!a)k 4;5(!a.C)k 4;8 b=$(4).6(\'3.l\')||$(4.U==\'13\'?4:s);5(a.C)a.C.y(b[0],[b.M(),$(\'a\',b.6(\'3.9\'))[0]])},1n:7(){8 a=4.6(\'3\');5(!a)k 4;5(a.m)k;4.3(\'O\');4.1a().19().X(\'.q-\'+a.w).o(\'9-3-N\')},O:7(){8 a=4.6(\'3\');5(!a)k 4;5(a.m)k;a.q.1V().X(\'.q-\'+a.w).G(\'9-3-1k\').G(\'9-3-N\')},u:7(){8 a=4.6(\'3\');5(!a)k 4;4.3(\'O\');5(a.p){a.p.6(\'3.l\').S(\'L\',\'L\');a.p.1a().19().X(\'.q-\'+a.w).o(\'9-3-1k\')}x $(a.v).1m(\'L\');a.E[a.m||a.1Y?\'1q\':\'1Z\']();4.20()[a.m?\'o\':\'G\'](\'9-3-1o\')},r:7(a,b){8 c=4.6(\'3\');5(!c)k 4;5(c.m)k;c.p=s;5(A a!=\'B\'){5(A a==\'1u\')k $(c.F[a]).3(\'r\',B,b);5(A a==\'1h\')$.W(c.F,7(){5($(4).6(\'3.l\').M()==a)$(4).3(\'r\',B,b)})}x c.p=4[0].U==\'13\'?4.6(\'3.9\'):(4.22(\'.q-\'+c.w)?4:s);4.6(\'3\',c);4.3(\'u\');8 d=$(c.p?c.p.6(\'3.l\'):s);5((b||b==B)&&c.1e)c.1e.y(d[0],[d.M(),$(\'a\',c.p)[0]])},m:7(a,b){8 c=4.6(\'3\');5(!c)k 4;c.m=a||a==B?H:J;5(b)$(c.v).S("R","R");x $(c.v).1m("R");4.6(\'3\',c);4.3(\'u\')},1x:7(){4.3(\'m\',H,H)},24:7(){4.3(\'m\',J,J)}});$.n.3.1s={E:\'25 26\',1d:\'\',t:0,1w:16};$(7(){$(\'l[27=28].9\').3()})})(1j);',62,135,'|||rating|this|if|data|function|var|star|||||||||||return|input|readOnly|fn|addClass|current|rater|select|null|split|draw|inputs|serial|else|apply|count|typeof|undefined|blur|focus|cancel|stars|removeClass|true|arguments|false|calls|checked|val|hover|drain|div|length|disabled|attr|be|tagName|class|each|filter|spw|_|width|id|extend|INPUT|title|to||drawn|call|andSelf|prevAll|metadata|append|cancelValue|callback|applied|mouseover|string|mouseout|jQuery|on|click|removeAttr|fill|readonly|value|hide|className|options|document|number|replace|starWidth|disable|Math|floor|find|css|margin|left|px|half|live|execCommand|try|msie|BackgroundImageCache|browser|catch|change|context|before|control|span|meta|makeArray|slice|children|body|form|required|show|siblings|unnamed|is|name|enable|Cancel|Rating|type|radio|window|not'.split('|'),0,{}))

/**
 * jquery.timer.js
 *
 * Copyright (c) 2011 Jason Chavannes <jason.chavannes@gmail.com>
 *
 * http://code.google.com/p/jquery-timer/
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use, copy,
 * modify, merge, publish, distribute, sublicense, and/or sell copies
 * of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}(';(4($){$.9=4(6,3,8){2.o=4(6,3,8){5(q 6==\'w\'){g c=[\'8\',\'3\',\'b\'];v(g f y c){5(6[c[f]]!=d){u(c[f]+" = 6[c[f]]")}};6=6.b}5(q 6==\'4\'){2.b=6}5(!x(3)){2.p=3}5(8==F){2.a=1;2.e()}7 2};2.E=4(3){5(3!=d){2.h(3)}m{2.h()}7 2};2.j=4(){5(2.a==0){2.a=1;2.e()}7 2};2.i=4(){2.a=0;2.k();7 2};2.z=4(){5(2.a>0){2.i()}m{2.j()}7 2};2.C=4(){2.i().j();7 2};2.k=4(){l.B(2.t)};2.e=4(3){5(3==d){3=2.p}2.k();g 9=2;2.t=l.r(4(){9.s()},3)};2.h=4(3){5(3==d){3=0}g 9=2;l.r(4(){9.n()},3)};2.s=4(){5(2.a!=0){2.b();2.e()}};2.n=4(){2.b()};5(2.b!=d){7 A $.9(6,3,8)}m{2.o(6,3,8);7 2}}})(D);',42,42,'||this|time|function|if|func|return|autostart|timer|active|action|params|undefined|setTimer|arg|var|setOnce|pause|play|clearTimer|window|else|goOnce|set|intervalTime|typeof|setTimeout|go|timeoutObject|eval|for|object|isNaN|in|toggle|new|clearTimeout|reset|jQuery|once|true'.split('|'),0,{}))

/*

highlight v3

Highlights arbitrary terms.

<http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html>

MIT license.

Johann Burkard
<http://johannburkard.de>
<mailto:jb@eaio.com>

*/
jQuery.fn.highlight=function(b){function a(e,j){var l=0;if(e.nodeType==3){var k=e.data.toUpperCase().indexOf(j);if(k>=0){var h=document.createElement("span");h.className="highlight";var f=e.splitText(k);var c=f.splitText(j.length);var d=f.cloneNode(true);h.appendChild(d);f.parentNode.replaceChild(h,f);l=1}}else{if(e.nodeType==1&&e.childNodes&&!/(script|style)/i.test(e.tagName)){for(var g=0;g<e.childNodes.length;++g){g+=a(e.childNodes[g],j)}}}return l}return this.each(function(){a(this,b.toUpperCase())})};jQuery.fn.removeHighlight=function(){return this.find("span.highlight").each(function(){this.parentNode.firstChild.nodeName;with(this.parentNode){replaceChild(this.firstChild,this);normalize()}}).end()};

function initDemotapeJquery(){
	
	$('.loadParent').click(function(){
		var url = $(this).attr('href');
		parent.$.fn.colorbox.close();
		window.parent.loadingIndicator.show();
		window.parent.Spring.remoting.getResource(url, '', false);
		return false;
	});
	
	//Language switcher
	$("a.language_link").click(function(){
		loadingIndicator.show();
		var v_lang = this.id.replace('lang_', '');
		var url = YAHOO.util.History.getCurrentState("p");
		url = (url.indexOf("?") === -1) ? url+'?lang='+v_lang : url+'&lang='+v_lang
		Spring.remoting.getResource(url, '', false);
		return false;
	});
	
	//Facebook
	window.fbAsyncInit = function() {
		FB.init({appId: demotape.fbAppId, status: true, cookie: true, xfbml: true, oauth: true});
	};
	(function() {
		var e = document.createElement('script'); e.async = true;
		e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
		document.getElementById('fb-root').appendChild(e);
	}());

	//Carousel
	$('#my-carousel').carousel({
		itemsPerPage: 1, // number of items to show on each page
		itemsPerTransition: 1, // number of items moved with each transition
		noOfRows: 1, // number of rows (see demo)
		nextPrevLinks: false, // whether next and prev links will be included
		pagination: true, // whether pagination links will be included
		speed: 'normal' // animation speed
	});
	
	//STAR RATING
	$('.auto-submit-star').rating({
		required: true,
		callback: function(value, link){
			var rate = value.substring(0,1);
			var artistId = value.substring(1,value.length);
			$.colorbox({href:demotape.contextRoot + 'rate/artist/' + artistId + '?rate=' + rate, width:"700px", height:"400px", iframe:true });
		}
	});
	
	//COLORBOX
	$('#aboutRejectedSongs').colorbox({width:"400px", height:"400px", iframe:true});
	$("a[rel='photo-gallery']").colorbox({transition:"elastic"});
	$('.yotubePopup').colorbox({innerWidth:640, innerHeight:390, iframe:true});
	$('.mapPopup').colorbox({ innerWidth:821, innerHeight:621, iframe:true });
	$('.followArtistPopup').colorbox({width:"700px", height:"400px", iframe:true });
	$('.logInAndReloadPopup').colorbox({width:"700px", height:"400px", iframe:true });
	$('.embedSongPopup').colorbox({width:"700px", height:"300px", iframe:true });
	$('.playlistPopup').colorbox({width:"700px", height:"400px", iframe:true });
	$('.statPopup').colorbox({width:"700px", height:"500px", iframe:true });
	$('.loginPopup').colorbox({width:"750px", height:"400px", iframe:true });
	$('.joinCompetitionPopup').colorbox({width:"700px", height:"400px", iframe:true });
	$('.imagePopup').colorbox({transition:"elastic"});
	$('.termsPopup').colorbox({width:"700px", height:"700px", iframe:true });
	$('.tipFriendPopup').colorbox({width:"700px", height:"620px", iframe:true });
	$('.sendPrivateMessagePopup').colorbox({width:"800px", height:"620px", iframe:true });
	$('.deleteMembershipPopup').colorbox({width:"700px", height:"300px", iframe:true });
	
	//Player controles
	$('.buttonsOnPlayer').click(function(){
		this.id
		var wimpy_obj = document.getElementById("playerIframe").contentWindow.wimpy_getTrackInfo();
		if(wimpy_obj.songid != null){
			if(this.id == 'Player_tipFriend'){
				$.colorbox({href:demotape.contextRoot + 'songs/' + wimpy_obj.songid + '/tip', width:"700px", height:"620px", iframe:true});
			}else if(this.id == 'Player_thumbUp'){
				$.colorbox({href:demotape.contextRoot + 'rate/song/' + wimpy_obj.songid, width:"700px", height:"400px", iframe:true});
			}else if(this.id == 'Player_favourite'){
				$.colorbox({href:demotape.contextRoot + 'playlists/addSong/' + wimpy_obj.songid, width:"700px", height:"400px", iframe:true});
			}else if(this.id == 'Player_artistPage'){
				Spring.remoting.getResource(demotape.contextRoot + 'artists/' + wimpy_obj.artistid, '', false);
			}else if(this.id == 'Player_facebook'){
				//TODO
			}
		}
		return false;
	});
	
	//Facebook like
	$(".facebook-icon-single").toggle(
		function () {
			$(this).next('.facebookLikeContainer').show();
			$('#demotapeOverlay').show();
			return false;
		}, 
		function () {
			$(this).next('.facebookLikeContainer').hide();
			$('#demotapeOverlay').hide();
			return false;
		}
	);
	$('#demotapeOverlay').click(function(){
		$('.facebookLikeContainer').hide();
		$('#errorPopupContainer').hide();
		$(this).hide();
	});
	$('.facebookLikeClose').click(function(){
		$('#demotapeOverlay').hide();
		$('.facebookLikeContainer').hide();
	});
	
	//Error popup close
	$('.errorClose').click(function(){
		$('#demotapeOverlay').hide();
		$('#errorPopupContainer').hide();
	});
	
	//Focus on username
	if($('#j_username').length > 0){
		$("#j_username").focus();
	}
	
	/******************
	 * ARTIST PUBLIC PAGE
	 ******************/
	$('#facebookSidebarLink').click(function(){
		$(this).find('span').toggle();
		$('#facebookSidebarContent').toggle();
		if($('#twitterSidebarContent:visible')){
			$('#twitterSidebarContent, #twitterSidebarLink span').hide();
		}
		return false;
	});
	$('#twitterSidebarLink').click(function(){
		$(this).find('span').toggle();
		$('#twitterSidebarContent').toggle();
		if($('#facebookSidebarContent:visible')){
			$('#facebookSidebarContent, #facebookSidebarLink span').hide();
		}
		return false;
	});
	
	/******************
	 * DEMOTAPE PLAYER
	 ******************/
	//ADDING SONGS TO PLAYER
	$('.dtPlayer_playSong').click(function(){
		var JSON  = jQuery.parseJSON($(this).attr('data-meta'));
		addToPlayList(JSON, true);
		return false;
	});
	$('.dtPlayer_addSong').click(function(){
		var JSON  = jQuery.parseJSON($(this).attr('data-meta'));
		addToPlayList(JSON, false);
		return false;
	});
	
	$('.dtPlayer_addPlaylist').click(function(){
		var JSON  = jQuery.parseJSON($(this).attr('data-meta'));
		jQuery.each(JSON, function(i, val) {
			addToPlayList(val, false);
		});
		return false;
	});
	
	//PLAYER CONTROLES
	$('#Player_PrevSong').click(function(){
		document.getElementById('playerIframe').contentWindow.wimpy_prev();
		return false;
	});
	$('#Player_playPause').click(function(){
		var status = document.getElementById('playerIframe').contentWindow.wimpy_getPlayerState().status;
		
		if(status===1){
			$(this).removeClass('pause').addClass('play');
			document.getElementById('playerIframe').contentWindow.wimpy_pause();
		}else{
			$(this).removeClass('play').addClass('pause');
			document.getElementById('playerIframe').contentWindow.wimpy_play();
		}
		
		return false;
	});
	$('#Player_NextSong').click(function(){
		document.getElementById('playerIframe').contentWindow.wimpy_next();
		return false;
	});
	$('#Player_clearPlaylist').click(function(){
		document.getElementById('playerIframe').contentWindow.wimpy_clearPlaylist();
		return false;
	});
	
	//TOGGLE BETWEEN FULL AND SMALL PLAYER
	$('#togglePlayer').click(function(){
		$('#player').slideToggle('slow');
		$('#smallPlayer').slideToggle('slow');
		$('#Player_clearPlaylist').toggle();
		$('#togglePlayer').toggleClass('minimizePlayer').toggleClass('maximizePlayer');
		
		$('.playerIframeContainer iframe').css("height",function(){
			
			if($(this).css('height') == '110px'){
				$('.playerIframeContainer').css("height","0");
				$('.playerIframeContainer iframe').css("height","0");
			}else{
				$('.playerIframeContainer').css("height","110px");
				$('.playerIframeContainer iframe').css("height","110px");
			}
		});
		return false;
	});
	
	
	//HIGHLIGHTE INPUT ON FOCUS
	$('input[type="text"], input[type="password"], input[type="file"], textarea').focus(function() {
		$(this).addClass("on-focus");
	});
	$('input[type="text"], input[type="password"], input[type="file"], textarea').blur(function() {
		$(this).removeClass("on-focus");
	});
	
	//NICK AVAILABLE
	$('#nickAvailableLink').click(function(){
		checkAvailability('nick', 'nickErrors', 'users/nickAvailable');
		return false;
	});
	
	//UNIQUE NAME AVAILABLE
	$('#uniqueNameAvailableLink').click(function(){
		checkAvailability('uniqueName', 'uniqueNameErrors', 'artists/uniqueNameAvailable');
		return false;
	});
	
	
	/******************
	 * LOCATION
	 ******************/
	//INIT FYLKE
	$(".countrySelect").change(function () {
		$('select.fylkeSelect').html('<option value="-1">Loading</option>');
		$('select.kommuneSelect').html('<option value="-1">-----------</option>');
		loadFylker($(".countrySelect").val());			
		return false;
	});
	
	//INIT KOMMUNE
	$(".fylkeSelect").change(function () {
		loadKommuner($(".fylkeSelect").val());
		return false;
	});
	
	
	/******************
	 * GENRES
	 ******************/
	$('.mainGenreSelect').change(function () {
		loadSubGenres($('.mainGenreSelect').val());
		return false;
	});
	
	/******************
	 * CONCERTS
	 ******************/
	$('#concertFilterDropdown').toggle(function() {
		$('#concertFilterDropdownContent').show();
		$('#concertFilterDropdown').css("background-color", "#FFF");
		$('#concertFilterDropdown p').addClass('open').removeClass('closed');
	}, function(){
		$('#concertFilterDropdownContent').hide();
		$('#concertFilterDropdown').css("background-color", "transparent");
		$('#concertFilterDropdown p').addClass('closed').removeClass('open');
	});
	
	$('#selectSubGenreDropdown').toggle(function() {
		$('#selectSubGenreContent').show();
		$('#selectSubGenreDropdown').css("background-color", "#FFF");
		$('#selectSubGenreDropdown p').addClass('open').removeClass('closed');
	}, function(){
		$('#selectSubGenreContent').hide();
		$('#selectSubGenreDropdown').css("background-color", "transparent");
		$('#selectSubGenreDropdown p').addClass('closed').removeClass('open');
	});
	
	$('#artistListSortByDropdown').toggle(function() {
		$('#artistListSortByContent').show();
		$('#artistListSortByDropdown').css("background-color", "#FFF");
		$('#artistListSortByDropdown p').addClass('open').removeClass('closed');
	}, function(){
		$('#artistListSortByContent').hide();
		$('#artistListSortByDropdown').css("background-color", "transparent");
		$('#artistListSortByDropdown p').addClass('closed').removeClass('open');
	});
	
	
	//Toggle image action links
	$('#profilePictureContainer').hover(
		function () {
			$('#profilePictureLinks').show();
			$('#imageEditLinkTips').hide();
		}, 
		function () {
			$('#profilePictureLinks').hide();
			$('#imageEditLinkTips').show();
		}
	);
	
	//Simple table row hover
	$(".tr-hover").hover(function() {
		$(this).addClass('tr-hover-bg');
		
	}, function() {
		$(this).removeClass('tr-hover-bg');
	});
	
	//Menu handler
	$('.menuSwitcher a').click(function(event){
		menuSwitcher(event.target);
		return false;
	});
	
	//Dropdown
	$('.dropdown-menu .default').click(function(){
		$(this).next('.dropdown-sub-menu').toggle();
	});
	
	//Upload animation
	$('#addSongButton').click(function(){
		$('#fileUploadLoader').show();
		resizeContentIframe();
	});
	
	//Facebook
	$('.facebookLogin').click(function() {		
		var popup = $(this).attr('data-meta');		
		// fetch the status on load
		FB.getLoginStatus();		
		FB.login(function(response) {
		  	if (response.authResponse) {		    				    		
		      	// user is logged in and granted some permissions.			      			    		  		
	    		var accessToken = response.authResponse.accessToken;			    		
	    		if(popup==='true') {
	    			//TODO: For now ajax doesn't work in popups, /facebook/newUser view isn't returned correctly.
	    			//Luckly, this behaviour will not reload player.		    			
	    			window.document.location = demotape.contextRoot + 'facebook/login?accessToken='+accessToken;                                                    
	    		}
	    		else {
	    			//If not popup, do ajax login.
	    			loadingIndicator.show();
	    			Spring.remoting.getResource(demotape.contextRoot + 'facebook/login?accessToken='+accessToken, { fragments: 'content'}, false);			    			
	    		}		    	
		  	} 
		  	else {
		    	// user is not logged in
			  	return;
		  	}
		}, {scope:'email'}); //Put extended permissions here		
	});	
}


/******************
 * SONG LIST
 ******************/
function toggleSongList(id){
	$('.hiddenSongList' + id).toggle();
	$('.songListExpand' + id).toggle();
	$('.songListMinimize' + id).toggle();
	return false;
}

/******************
 * COLORBOX FUNCTIONS
 ******************/
function closePopup(){ $.colorbox.close(); }


/******************
 * PLAYER
 ******************/
function addToPlayList(JSON, startPlaying){
	var addFile = "";
	addFile += "<playlist>";
	addFile += "<item>";
	addFile += "<filename>"+JSON.filePath+"</filename>";
	addFile += "<artist>"+JSON.artistName+"</artist>";
	addFile += "<artistid>"+JSON.artistId+"</artistid>";
	addFile += "<title>"+JSON.songName+"</title>";
	addFile += "<link>"+JSON.artistId+"</link>";
	addFile += "<image>"+JSON.imageUrl+"</image>";
	addFile += "<songid>"+JSON.songId+"</songid>";
	addFile += "</item>";
	addFile += "</playlist>";
	
	document.getElementById('playerIframe').contentWindow.wimpy_appendPlaylist(addFile, startPlaying);
	$.getJSON(demotape.contextRoot + 'stat/songs/' + JSON.songId + '/new', null, null);
}

function setCurrentSongNameInPlayer(trackInfo){
	$('#currentSongNameInPlayer').text(trackInfo.artist.replace("%27","'") + " : " + trackInfo.title.replace("%27","'"));
	$('#currentArtistPictureInPlayer').attr('src', trackInfo.image);
}

//Update thumbs up
function updateThumbsUp(id, val){
	$('#thumbsUp_Song_' + id).html(val);
}

//Resize iframe
function resizeContentIframe(){
	var newHeight = $('body').height()+20;
	window.parent.setIframeHeight(newHeight);
}
function setIframeHeight(newHeight){
	$('.resizeableIframe').attr('height', newHeight);
}

//Function for checking nick and unique name availability
function checkAvailability(variableId, errorId, getJSON_URL){
	$('#availableSuccess').addClass('hide');
	$('#availableError').addClass('hide');
	
	$('#' + errorId).addClass('hide'); 
	$('#' + variableId).removeClass('input-error');
	$('.availableError').addClass('hide');
	
	if($('#' + variableId).val().length>0){
		$('#availableLoader').removeClass('hide');
		
		$.getJSON(demotape.contextRoot + getJSON_URL, { stringToCheck : $('#' + variableId).val() }, function(available) {
			$('#availableLoader').addClass('hide');
			if (available) {
				$('#availableSuccess').removeClass('hide');
				$('#' + variableId).addClass('border-success');
			} else {
				$('#availableError').removeClass('hide');
				$('#' + variableId).addClass('input-error');
			}
		});
	}
	return false;
}

//Design tool
function reloadCustomPicture(artistId){
	$.getJSON(demotape.contextRoot + 'artists/' + artistId + '/customPictureURL', null, function(mfList) {
		$('#artistCustomPicture').css('background-image', 'url(' + mfList.medium + ')');
		$('#artistCustomPicture').css('background-position', 'left top');
		$('#currentPictureHolder').removeClass('hide');
		$('#currentPicture').attr('src', mfList.thumb);
	});
}

//Function for loading sub genres
function loadSubGenres(mainGenreId, selectedValue){
	if(mainGenreId > 0){
		
		//Show loader
		$('#mainGenreLoader').removeClass('hide');
		
		//Fetching kommuner
		$.getJSON(demotape.contextRoot + "genre/getSubGenres", { mainGenreId:mainGenreId }, function(subGenreList) {
			
			//Creating the drop down
			var options = '';
			$.each(subGenreList, function(k, v){
				options += '<option value="' + k + '">' + v + '</option>';
			});
			
			//Populate dropdown and hide loader
			$('select.subGenreSelect').html(options);
			
			//Setting correct selected
			$('select.subGenreSelect').val(selectedValue);
			
			$('#mainGenreLoader').addClass('hide');
		});
	}
}

//Function for loading fylker
function loadFylker(countryId, selectedValue) {
	//Show fylke, kommune and loader
	$('#fylkeLoader').removeClass('hide');
	$('#fylkeDropdown').removeClass('hide');
	$('#kommuneDropdown').removeClass('hide');
		
	//Fetching fylker
	$.getJSON(demotape.contextRoot + "location/getFylker", { countryId: countryId}, function(fylker) {
		
		$('#fylkeDropdown').removeClass('hide');
		$('#kommuneDropdown').removeClass('hide');
		
		//Creating the drop down
		var options = '<option value="-1">Choose</option>';
		var count = 0;
		$.each(fylker, function(k, v){
			options += '<option value="' + k + '">' + v + '</option>';
			count++;
		});
		
		if(count > 0){
			//Populate dropdown and hide loader
			$('select.fylkeSelect').html(options);
			
			//Setting correct selected
			$('select.fylkeSelect').val(selectedValue);
			
			$('#fylkeLoader').addClass('hide');
		}else{
			$('#fylkeDropdown').addClass('hide');
			$('#kommuneDropdown').addClass('hide');
		}
		count === 0;
	});	
}

//Function for loading kommuner
function loadKommuner(fylkeId, selectedValue){
	if(fylkeId > 0){
		
		//Show loader
		$('#kommuneLoader').removeClass('hide');
		
		//Fetching kommuner
		$.getJSON(demotape.contextRoot + "location/getKommuner", { fylkeId:fylkeId }, function(kommuner) {
			
			//Creating the drop down
			var options = '';
			$.each(kommuner, function(k, v){
				options += '<option value="' + k + '">' + v + '</option>';
			});
			
			//Populate dropdown and hide loader
			$('select.kommuneSelect').html(options);
			
			//Setting correct selected
			$('select.kommuneSelect').val(selectedValue);
			
			$('#kommuneLoader').addClass('hide');
		});
	}
}

/************************************************************************/
/*		DIV																*/
/************************************************************************/
function disableButton(hideButton, showButton){
	$("#"+hideButton).hide();
	$("#"+showButton).show();
}

function menuSwitcher(object){
	var id = $(object).attr("id");
	var nr = id.substring(id.length-1, id.length);
	$('.contentContainer').addClass('hide');
	$('.leftSideMenu .menuContainer a').removeClass('active');
	$('#content_' + nr).removeClass('hide');		
	$('#' + id).addClass('active');
	return false;
}

function showErrorBox(status, responseText){
	loadingIndicator.hide();
	//alert('status: ' + status);
	//alert('responseText: ' + responseText);
	$('#demotapeOverlay').show();
	$('#errorPopupContainer').show();
	//$('#errorStatus').html(status);
	$('#errorResponseText').html(responseText);
	
}

/************************************************************************/
/*		RESIZE IFRAME													*/
/************************************************************************/
/* Rezising iframe to fit content */
function resizeIframe(previewHeight) {
	var newHeight = $('body').height();
	
	var h = (previewHeight > newHeight) ? previewHeight : newHeight;
	window.parent.setIframeHeight(h);
}
function setIframeHeight(newHeight){
	$('#contentIframe').attr('height', newHeight);
	$('#height').html(newHeight);
	
}

/************************************************************************/
/*		COOKIE															*/
/************************************************************************/
//Creating cookie
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
//Read cookie
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
//Delete cookie
function eraseCookie(name) {
	createCookie(name,"",-1);
}

/*
 * jQuery Carousel Plugin v1.0
 * http://richardscarrott.co.uk/posts/view/jquery-carousel-plugin
 *
 * Copyright (c) 2010 Richard Scarrott
 *
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 * Requires jQuery v1.4+
 *
 */

// prototypal inheritance
if (typeof Object.create !== 'function') {
	Object.create = function (o) {
		function F() {}
		F.prototype = o;
		return new F();
	};
}

(function($) {
	// ie alias
	var headache = $.browser.msie && $.browser.version.substr(0,1)<9;

	// carousel
	var Carousel = {
		settings: {
			itemsPerPage: 1,
			itemsPerTransition: 1,
			noOfRows: 1,
			pagination: true,
			nextPrevLinks: true,
			speed: 'normal',
			easing: 'swing'
		},
		init: function(el, options) {
			if (!el.length) {return false;}
			this.options = $.extend({}, this.settings, options);
			this.itemIndex = 0;	
			this.container = el;
			this.runner = this.container.find('ul');
			this.items = this.runner.children('li');
			this.noOfItems = this.items.length;
			this.setRunnerWidth();
			if (this.noOfItems <= this.options.itemsPerPage) {return false;} // bail if there are too few items to paginate
			this.insertMask();
			this.noOfPages = Math.ceil((this.noOfItems - this.options.itemsPerPage) / this.options.itemsPerTransition) + 1;
			if (this.options.pagination) {this.insertPagination();}
			if (this.options.nextPrevLinks) {this.insertNextPrevLinks();}
			this.updateBtnStyles();
		},
		insertMask: function() {
			this.runner.wrap('<div class="mask" />');
			this.mask = this.container.find('div.mask');

			// set mask height so items can be of varying height
			var maskHeight = this.runner.outerHeight(true);
			this.mask = this.container.find('div.mask');
			this.mask.height(maskHeight);
		},
		setRunnerWidth: function() {
			this.noOfItems = Math.round(this.noOfItems / this.options.noOfRows);
			var width =  this.items.outerWidth(true) * this.noOfItems;
			this.runner.width(width);
		},
		insertPagination: function() {
			var i, links = [];
			this.paginationLinks = $('<ol class="pagination-links" />');
			for (i = 0; i < this.noOfPages; i++) {
				links[i] = '<li><a href="#item-' + i + '">' + (i + 1) + '</a></li>';
			}
			this.paginationLinks
				.append(links.join(''))
				.appendTo(this.container)
				.find('a')
					.bind('click.carousel', $.proxy(this, 'paginationHandler'));
		},
		paginationHandler: function(e) {
			this.itemIndex = e.target.hash.substr(1).split('-')[1] * this.options.itemsPerTransition;
			this.animate();
			return false;
		},
		insertNextPrevLinks: function() {
			this.prevLink = $('<a href="#" class="prev">Prev</a>')
								.bind('click.carousel', $.proxy(this, 'prevItem'))
								.appendTo(this.container);
			this.nextLink = $('<a href="#" class="next">Next</a>')
								.bind('click.carousel', $.proxy(this, 'nextItem'))
								.appendTo(this.container);
		},
		nextItem: function() {
			this.itemIndex = this.itemIndex + this.options.itemsPerTransition;
			this.animate();
			return false;
		},
		prevItem: function() {
			this.itemIndex = this.itemIndex - this.options.itemsPerTransition;
			this.animate();
			return false;
		},
		updateBtnStyles: function() {
			if (this.options.pagination) {
				this.paginationLinks
					.children('li')
						.removeClass('current')
						.eq(Math.ceil(this.itemIndex / this.options.itemsPerTransition))
							.addClass('current');
			}

			if (this.options.nextPrevLinks) {
				this.nextLink
					.add(this.prevLink)
						.removeClass('disabled');
				if (this.itemIndex === (this.noOfItems - this.options.itemsPerPage)) {
					this.nextLink.addClass('disabled');
				} 
				else if (this.itemIndex === 0) {
					this.prevLink.addClass('disabled');
				}
			}
		},
		animate: function() {
			var nextItem, pos;
			// check whether there are enough items to animate to
			if (this.itemIndex > (this.noOfItems - this.options.itemsPerPage)) {
				this.itemIndex = this.noOfItems - this.options.itemsPerPage; // go to last panel - items per transition
			}
			if (this.itemIndex < 0) {
				this.itemIndex = 0; // go to first
			}
			nextItem = this.items.eq(this.itemIndex);
			pos = nextItem.position();
			
			if (headache) {
				this.runner
					.stop()
					.animate({left: -pos.left}, this.options.speed, this.options.easing);
			}
			else {
				this.mask
					.stop()
					.animate({scrollLeft: pos.left}, this.options.speed, this.options.easing);
			}
			this.updateBtnStyles();
		}
	};

	// bridge
	$.fn.carousel = function(options) {
		return this.each(function() {
			var obj = Object.create(Carousel);
			obj.init($(this), options);
			$.data(this, 'carousel', obj);
		});
	};
})(jQuery);

