
function Newsfeeds(element,type,options,pid)
{this.element=element?jQuery(element):jQuery('<div></div>');this.element.append(this.htmlNone());this.mainElement=jQuery('<div></div>').append(jQuery(this.htmlLikes())).append(this.element);this.url='';this.type=type?type:'all';this.count=5;this.min_count=1;this.pid=pid;if(typeof options=='object'&&options)
{var i;for(i in options)
{this[i]=options[i];}}
var self=this;this.submitResponse=function(e)
{self.submitNewsfeed(self.$form.find('form'));}
this.call_get=function(){if(self.more){self.more.mouseout();}self.get();}
if(this.construct)
{this.construct();}
self.reset();this.viewMore();this.get();}
Newsfeeds.prototype.reset=function()
{this.newsfeeds={};this.order=[];}
Newsfeeds.prototype.get=function(start,count)
{var cnt=count;var greater;var first=!this.order.length;if(this.processing)
{return;}
this.processing=true;if(typeof start!='number'&&typeof start!='string')
{start=this.order.length-1;greater=first;}
else
{greater=true;}
var self=this;var c;var count=this.min_count+(c=count?count:this.count);var callback=function(data)
{var i;var d;var n=data.length>c?data.length-self.min_count:data.length;if(self.type=='all')
{if(self.count)
{n=self.count;}}
for(i=0;i<n;i++)
{self.add(data[i],!first);}
if(self.type=='all'&&self.order.length>self.count)
{for(i=self.count;i<self.order.length;i++)
{self.order[i].element.hide(self.speed);}
self.order.length=self.count;}
if(self.element)
{if(!cnt&&self.more)
{if(data.length>c)
{self.more.appendTo(self.element);}
else
{self.more.hide();}}}
if(!self.lived)
{self.live_timer();}
if(!cnt)
{self.textMore();}
if(self.order.length)
{self.$none.hide();}
else
{self.$none.show();}
self.processing=false;}
if(!cnt)
{self.textMore(true);}
jQuery.getJSON(this.url+'/users/'+this.type+'_newsfeed_callback/'+(greater?count:-count)+'/'+(first?0:(this.order.length>start?this.order[start].id:0))+'/'+this.pid,callback);}
Newsfeeds.prototype.viewMore=function()
{var self=this;if(this.type!='all')
{this.more=jQuery('<table style="width:100%;height:50px;margin-bottom:5px;background-color:white;border:solid 1px #e1e1e1;cursor:pointer"><tr><td style="text-align:center;vertical-align:middle;background:transparent;width:100%;" id="t"></td></tr></table>');}
this.textMore();this.firstData=0;this.el();return this.more;}
Newsfeeds.prototype.el=function()
{this.addEvents();return this.mainElement;}
Newsfeeds.prototype.addEvents=function()
{var self=this;if(this.more)
{this.more.bind('click',this.call_get);this.more.bind('mouseover',function(){self.more.css('background-color','#dfecf5');});this.more.bind('mouseout',function(){self.more.css('background-color','#ffffff');});}
var i;for(i=0;i<this.order.length;i++)
{this.order[i].addEvents();}
if(this.$form)
{var $form=this.$form.find('form');var text=$form.find('textarea');text.focus(function(e)
{if(text[0].value==Newsfeed.empty)
{text[0].value='';}
text.height(Newsfeed.textHeight);});text.blur(function(e)
{if(text[0].value=='')
{text[0].value=Newsfeed.empty;}});$form.unbind('submit',self.submitResponse);$form.bind('submit',self.submitResponse);}
return this.element;}
Newsfeeds.prototype.textMore=function(loading)
{if(this.more)
{var el=this.more.find('#t');el.html(loading?'<img src="/img/spinner.gif" />':'More Newsfeeds...');}}
Newsfeeds.prototype.beforeElements=function()
{var $children=this.element.children('.newsfeed_main');var i,j;var el;var id;for(i=0;i<$children.length;i++)
{el=$children.get(i);id=parseInt(el.id);if(!isNaN(id))
{el.id=id+1;}}}
Newsfeeds.prototype.add=function(data,animated)
{if(data?this.newsfeeds[data['Newsfeed']['id']]:true){return null;}
var before=typeof this.order[0]=='object'?parseInt(data.Newsfeed.id)>parseInt(this.order[0].id):false;if(before)
{this.beforeElements();}
var d=new Newsfeed(data,animated,!this.more,this,(this.firstData+(before?1:this.order.length))%2,before?'0':String(this.order.length),this);if(before)
{this.beforeData++;}
if(this.element)
{d.element[before?'prependTo':'appendTo'](this.element);if(before&&this.$form)
{this.element.prepend(this.$form);}}
this.order[before?'unshift':'push'](d);this.length=this.order.length;this.newsfeeds[d.id]=d;return d;}
Newsfeeds.prototype.live=function(ms)
{if(ms)
{this.ms=parseInt(ms);}
else
{this.ms=5000;}
return this;}
Newsfeeds.prototype.htmlNone=function()
{this.$none=jQuery('<table style="width:100%;height:60px;"><tr><td style="vertical-align:middle;text-align:middle">There are no newsfeed!</td></tr></table>');this.$none.hide();return this.$none;}
Newsfeeds.prototype.live_timer=function()
{if(!this.ms)
{return this.lived=undefined;}
var self=this;this.lived=setTimeout(function(){self.live_timer();},this.ms);if(this.element.attr('display')=='none'||this.element.parent().length)
{this.get(0,self.type=='all'?self.count:1000);}
return this;}
Newsfeeds.prototype.htmlFeed=function(user,text,x,content,id)
{var color=this.alt_color?"#f8f8f8":"#f8f8f8";var c;this.htmlColor=color;var bottomTable='';if(typeof x=='object')
{content=x.html();}
else if(typeof x=='string')
{content=x;x=false;}
if(typeof content=='object')
{content=content.html();}
var res='<table class="newsfeed_main"'+(id?'id="'+id+'"':'')+'>'
+'<tr>'
+(user?'<td style="text-align:center;vertical-align:top;width:50px;"><a href="/users/homes/'+user['id']+'">'
+'<img src="/images/geticon/'+(user['image_id']==null?'no/profile':user['image_id'])+'"></img></a>'
+'</td>':'')
+'<td style="text-align:left;vertical-align:middle;font-size:12px">'+'<table class="newsfeed">'+'<tr><td id="border7"></td><td id="border8">'+(user?'<a href="/users/homes/'+user.id+'">'+user.name+'</a>':'')+' '+text+'</td><td id="border9"></td></tr>'+'<tr><td id="border4"></td><td>'+
(content?content:'')+'</td><td id="border6"></td></tr>'+'<tr><td id="border1"></td><td id="border2"></td><td id="border3"></td></tr></table>'
+'</td>'
+'</tr>'
+'<tr><td></td>'
res+='</table>';return res;}
Newsfeeds.prototype.htmlLikes=function()
{return'<div id="likePopup" style="position:absolute;z-index:1000;display:none;width:540px;padding-top:30px;height:620px;padding-left:20px">'
+'<table style="border:none;width:510px;margin-left:10px">'
+'<tr>'
+'<td id="likeTitle" style="font-size:14px;font-weight:bold;text-align:left;margin-bottom:0px">'
+'</td>'
+'<td id="close_likes" style="text-align:right;">'
+'<a href="#" style="outline:none" onclick="return false;"><img src="/img/icons/closex.png"></img></a>'
+'</td>'
+'</tr>'
+'</table>'
+'<div id="likeContent"></div>'
+'</div>';}
Newsfeeds.prototype.htmlComments=function()
{return'<div id="commentsPopup" style="position:absolute;display:none;z-index:2000;width:640px;padding:30px 20px;">'
+'<table style="width: 600px;" class="noBorder ctr">'
+'<tr>'
+'<td style="background-image: url(/img/roundBorders/r8-top-left.gif); width: 8px; height: 8px;"></td>'
+'<td style="background-image: url(/img/roundBorders/r8-top-across.gif); height: 8px;"></td>'
+'<td style="background-image: url(/img/roundBorders/r8-top-right.gif); width: 8px; height: 8px;"></td>'
+'</tr>'
+'<tr>'
+'<td style="background-image: url(/img/roundBorders/r8-left-side.gif); width: 8px;"></td>'
+'<td class="al">'
+'<a href="#" class="fr" onclick="document.getElementById(&quot;commentsPopup&quot;).style.display=&quot;none&quot;; return false;">'
+'x'
+'</a>'
+'<div id="commentsContent">'
+'</div>'
+'</td>'
+'<td style="background-image: url(/img/roundBorders/r8-right-side.gif); width: 8px;"></td>'
+'</tr>'
+'<tr>'
+'<td style="background-image: url(/img/roundBorders/r8-bottom-left.gif); width: 8px; height: 8px;"></td>'
+'<td style="background-image: url(/img/roundBorders/r8-bottom-across.gif); height: 8px;"></td>'
+'<td style="background-image: url(/img/roundBorders/r8-bottom-right.gif); width: 8px; height: 8px;"></td>'
+'</tr>'
+'</table>'
+'</div>';}
Newsfeeds.prototype.form=function()
{if(this.pid!='home')
{return this;}
this.$form=jQuery(Newsfeeds.htmlTextarea({'class':'newsfeed-header'}));this.$formElement=this.$form.find('#f');this.$form.find('textarea')[0].value=Newsfeed.empty;this.element.prepend(this.$form);return this;}
Newsfeeds.htmlTextarea=function(options,inputs)
{if(!options)
{options={};}
var width=options.width?options.width:'100%';var height=options.height?options.height:'16px';var id=options.id?options.id:'f';var text_id=options.text_id?options.text_id:'t';var $class=options['class']?options['class']:undefined;inputs=inputs?inputs:'<div style="text-align:left;width:600px;padding-top:8px;"><input type="image" src="/img/icons/button-submit.png" value="Submit" /></div>';return(($class?'<table class="'+$class+'">'+'<tr><td>':'')+'<form id="'+id+'" onsubmit="return false;">'+'<div style="text-align:center">'+'<table class="textfield">'+'<tr><td id="border7"></td><td id="border8"></td><td id="border9"></td></tr>'+'<tr><td id="border4"></td><td>'+'<textarea style="width:'+width+';height:'+height+';text-align:left;border:1px none;background:transparent" id="'+text_id+'"></textarea>'+'</td><td id="border6"></td></tr>'+'<tr><td id="border1"></td><td id="border2"></td><td id="border3"></td></tr></table>'+'</div>'+
inputs+'</form>'+
($class?'</tr></td>'+'</table>':''));}
Newsfeeds.prototype.submitNewsfeed=function(form)
{var self=this;var T=form.find('textarea');if(!T[0].value||T[0].value==Newsfeed.empty)
{return false;}
var submit=function(data)
{T[0].value=Newsfeed.empty;T.attr('disabled',false);}
T.attr('disabled',true);jQuery.post('/users/newsfeed_submit/',{newsfeed:T[0].value},submit,'json');}
function Newsfeed(data,animated,nomore,parent,alt_color,index,parent)
{this.parent=parent;this.index=index;this.alt_color=alt_color;this.url='';this.count=5;this.min_count=1;this.speed=navigator.appName.match(/Microsoft/i)?0:'medium';var self=this;self.__submitComment=function()
{self.submitComment(self.$commentPost.find('#f'));}
this.call_get=function(){self.get();}
if(this.parent=parent)
{this.init(data,animated,nomore);}}
Newsfeed.empty='Share something with your Subscribers.';Newsfeed.textHeight='50px';Newsfeed.duration=250;Newsfeed.prototype.htmlFeed=Newsfeeds.prototype.htmlFeed;Newsfeed.prototype.init=function(data,animated,nomore)
{var i;if(typeof data!='object'||!data)
{return false;}
for(i in data)
{if(typeof this[i]=='undefined')
{this[i]=data[i];}}
this.new_created=this.Newsfeed.new_created;this.id=data['Newsfeed']['id'];this.comments=[];this.comments_array={};if(!nomore)
{this.viewMore();}
this.view(animated);}
Newsfeed.prototype.htmlContent=function()
{if(this.Item)
{var item=this.Item;var o='<table style="border-spacing:0px;border:0px none;background:transparent;width:100%">'+'<tr>'+'<td style="vertical-align:top;text-align:left;width:0px;">'+'<img src="/images/geticon/'+item.image_id+'"/>'+'</td>'+'<td style="vertical-align:top;text-align:left; padding-left:12px;">'+'<div style="overflow:hidden;height:16px;color:#0f8cdc;">'+'<a href="/items/viewdetail/'+item.id+'">'+
item.name+'</a>'+'</div>'+'<div style="overflow:hidden;height:16px;color:#d50f17">'+
(item.price_format?item.price_format:'')+'</div>'+'<div style="overflow:hidden;height:40px;color:#969696">'+
(item.description?item.description:'')+'</div>'+'</td>'+'<td style="vertical-align:middle;text-align:left;width:0px;white-space:nowrap;color:#969696">'+'<div style="border:solid 1px #e1e1e1;width:200px;height:45px;padding-top:20px;padding-left:20px;background-image:url(\'/img/icons/promote_box.png\')">'+
this.showPromotions()+'</div>'+'</td>'+'</tr>'+'</table>';return o;}
if(this.Storefront)
{var storefront=this.Storefront;var o='<table style="border-spacing:0px;border:0px none;background:transparent;width:100%">'+'<tr>'+'<td style="vertical-align:top;text-align:left;width:0px;">'+'<img src="/images/geticon/'+storefront.image_id+'"/>'+'</td>'+'<td style="vertical-align:top;text-align:left; padding-left:12px;">'+'<div style="overflow:hidden;height:16px;color:#0f8cdc;">'+'<a href="/storefronts/shop/'+storefront.id+'">'+
storefront.name+'</a>'+'</div>'+'<div style="height:48px;color:#969696">'+
(storefront.description?storefront.description:'')+'</div>'+'</td>'+'</tr>'+'</table>';return o;}
return'';}
Newsfeed.prototype.showPromotions=function(p)
{if(typeof p=='undefined')
{p=this.Item.promotions;}
else if(this.Item)
{this.Item.promotions=p;}
if(typeof p=='undefined')
{p=0;}
P=p<=0?-p:'+'+p;P='<span style="font-size:18px;color:#0f8cdc;font-weight:bold;font-family:Arial">'+
P+'</span>'+'<span style="padding-left:10px;font-size:18px;color:#969696;text-transform:uppercase">';if(p>0)
{return P+'PROMOTION'+(p==1?'':'S')+'</span>';}
else if(p<0)
{return P+'DEMOTION'+(p==-1?'':'S')+'</span>';}
else
{return P+'PROMOTIONS</span>';}}
Newsfeed.prototype.view=function(animated)
{var res='';var j;var self=this;var desc=this.Newsfeed['description'];if(!desc)
{desc=this.Newsfeed['message'];}
res=this.htmlFeed(this.User,desc,true,this.extraContent(),this.index);this.element=jQuery(res);if(this.Newsfeed.data?(this['Newsfeed']['item_likes']&&this['Newsfeed']['item_likes']>0)||typeof this['Newsfeed']['data']['Resellers']=='object':false)
{this.likes=this.element.find('#likes');this.close_likes=this.parent.mainElement.find('#close_likes');}
this.$options=this.element.find('#o');this.$commentPost=jQuery(this.htmlFeed(this.parent.User,'writes a comment:',Newsfeeds.htmlTextarea({width:'90%',height:'40px'},'<input type="hidden" value="'+this.id+'" name="id" /><input type="image" src="/img/icons/button-submit.png" id="s" value="submit" /> <input id="r" type="image" src="/img/icons/button-cancel.png" "value="Cancel"/>'))).hide();var $comments=jQuery('<tr><td colspan="3" id="c" style="text-align:left;vertical-align:middle;padding-left:50px;"></td></tr>');this.$comments=$comments.find('#c');this.$comments.prepend(this.$commentPost);this.element.append($comments);this.X=this.element.find('#x');this.$commentText=this.element.find('#comments');this.$promote=this.element.find('#promote');this.$demote=this.element.find('#demote');this.$dpromote=this.element.find('#demote-promote');this.$promotions=this.element.find('#promotions');if(animated)
{this.element.show(this.speed);}
if(this.Comment instanceof Array)
{for(j=0;j<(this.Comment.length>1?this.Comment.length-1:this.Comment.length);j++)
{this.addComment(this.Comment[j]);}
if(this.Comment.length>j&&this.Comment.length>1&&this.more)
{this.more.appendTo(this.$comments);}}
this.addEvents();}
Newsfeed.prototype.extraContent=function()
{var o=this.htmlContent();o+='<table class="newsfeed-options"><tr>';o+='<td>';if(typeof this.Item=='object'&&this.Item&&this.Item.id)
{o+='<span style="padding-left:64px;color:#969696" id="demote-promote">';if(!this.Item.promoted)
{o+='<img id="promote" src="/img/icons/promote_icon.png" />';o+='<img id="demote" src="/img/icons/demote_icon.png" />';}
else
{o+=this.Item.promoted>0?'You have promoted this item.':'You have demoted this item.';}
o+='</span>';}
if(typeof this.Storefront=='object'&&this.Storefront&&this.Storefront.id)
{}
o+='</td><td style="white-space:nowrap;">';o+=(this.U&&(this.parent.pid=='home')?'<img src="/img/icons/newsfeed-x.gif" /> <a href="hide" id="x">hide</a> ':'');o+=(this.Newsfeed&&this.parent.User?'<img src="/img/icons/newsfeed-balloon.gif" /> <a href="" id="comments">Leave a Comment</a> ':'');o+='</td>';o+='</tr></table>'
return o;}
Newsfeed.prototype.viewMore=function()
{var self=this;if(this.type!='all')
{this.more=jQuery('<table style="width:100%;height:50px;margin-bottom:5px;background-color:#ffffff;border:solid 1px #e6e6e6;cursor:pointer"><tr><td style="text-align:center;vertical-align:middle;width:100%;background:transparent;" id="t"></td></tr></table>');}
this.textMore();return this.more;}
Newsfeed.prototype.textMore=function(loading)
{if(this.more)
{var el=this.more.find('#t');el.html(loading?'<img src="/img/spinner.gif" />':(this.parent.User?'More Comments...':'Please login to see the rest of the comments'));}}
Newsfeed.prototype.addEvents=function()
{var i;var self=this;this.element.mouseover(function(){});this.element.mouseout(function(){});if(this.X)
{this.X.click(function(){self.hide();return false;});}
if(this.$resale)
{self.$resale.click(function(){jQuery.get('/itemsic/resellItemAjax/'+self.Item.id+'/',function(){self.$resale.html('<span style="color:green;font-weight:bold;margin-right:20px;">RESELLING</span>');});return false;});}
if(this.$commentText)
{this.$commentText.click(function()
{self.$commentPost[self.$commentPost.css('display')=='none'?'show':'hide']();return false;})}
if(this.$commentPost)
{var form=this.$commentPost.find('#f');this.$commentPost.unbind('submit');this.$commentPost.find('#s').click(self.__submitComment);this.$commentPost.find('#r').click(function()
{self.$commentPost.find('textarea').val('');self.$commentPost.hide(self.speed);})}
if(this.more)
{this.addMoreEvents();}
if(this.comments.length)
{for(i=0;i<this.comments.length;i++)
{this.comments[i].addEvents();}}
if(this.Newsfeed.data?(this['Newsfeed']['item_likes']&&this['Newsfeed']['item_likes']>0)||typeof this['Newsfeed']['data']['Resellers']=='object':false)
{this.likes.click(function(){self.toggleLikes();});this.close_likes.click(function(){self.closeLike();});}
var promote=function(e)
{self.like(1);}
var demote=function(e)
{self.like(0);}
if(this.$promote)
{this.$promote.click(promote);}
if(this.$demote)
{this.$demote.click(demote);}}
Newsfeed.prototype.like=function(like)
{var self=this;var callback=function(data)
{return self.parent.updateLike(self,data,this.dislike);}
if(typeof Newsfeed.like=='function')
{if(this.Item)
{Newsfeed.like(this.Item.id,'item',like,callback);}}}
Newsfeeds.prototype.updateLike=function(data,number,dislike)
{var i;var newsfeed;for(i=0;i<this.order.length;i++)
{newsfeed=this.order[i];if(this.__updateLike(data,newsfeed))
{if(newsfeed.$dpromote)
{newsfeed.$dpromote.html(dislike?'You have demoted this item.':'You have promoted this item.');}
else
{if(newsfeed.$promote)
{newsfeed.$promote.hide();}
if(newsfeed.$demote)
{newsfeed.$demote.hide();}}
if(newsfeed.$promotions)
{newsfeed.$promotions.html(newsfeed.showPromotions(number));}}}}
Newsfeeds.likeArray=['Item'];Newsfeeds.prototype.__updateLike=function(a,b)
{var i;var key;for(i=0;i<Newsfeeds.likeArray.length;i++)
{key=Newsfeeds.likeArray[i];if(a[key]&&b[key]?a[key]['id']==b[key]['id']:false)
{return true;}}
return false;}
Newsfeed.prototype.closeLike=function()
{var lp=jQuery('#likePopup');lp.css('display','none');}
Newsfeed.prototype.toggleLikes=function()
{var lp=jQuery('#likePopup');var self=this;if(lp.css('display')=='block')
{lp.css('display','none');}else{if(typeof self['Newsfeed']['data']['Resellers']=='object')
{var users=self['Newsfeed']['data']['Resellers'];var num_users=users.length;var i=Math.floor((num_users-1)/5)+1;var lt=jQuery('#likeTitle');lt.html('Users who have made money from this sale');lp.css('background-image','url(\'/img/popup_box/n_row'+i+'.png\')');lp.css('height',(i*200)+'px');lp.css('top',(self['index']*90)+'px');lp.center({vertical:false});var res='<table style="margin-left:10px;border:none;width:500px;margin:none">';for(var i=0;i<num_users;i++)
{if(i%5==0)
{res+='<tr>';}
var u_string=users[i]['name'];if(u_string.length>15)
{u_string=u_string.substring(0,12)+'...';}
res+='<td style=";vertical-align:bottom;width:100px;height:105px"><a href="/users/homes/'+users[i]['user_id']+'"><img src="/images/geticon/'+(users[i]['image_id']==null?'no/profile':users[i]['image_id'])+'"></img></a><br /><a href="/users/homes/'+users[i]['user_id']+'">'+u_string+'</a></td>';if((i+1)%5==0)
{res+='</tr>';}}
res+='</table>';var gp=jQuery('#likeContent');gp.html(res);lp.css('display','block');}else{jQuery.getJSON("/users/get_users_likes/1/"+self['Item']['id'],function(data)
{var users=data;var num_users=users.length;var lt=jQuery('#likeTitle');lt.html('People who like this item');var i=Math.floor((num_users-1)/5)+1;lp.css('background-image','url(\'/img/popup_box/n_row'+i+'.png\')');lp.css('height',(i*200)+'px');lp.css('top',(self['index']*90)+'px');lp.center({vertical:false});var res='<table style="margin-left:10px;border:none;width:500px;margin:none">';for(var i=0;i<num_users;i++)
{if(i%5==0)
{res+='<tr>';}
var u_string=users[i]['username'];if(u_string.length>15)
{u_string=u_string.substring(0,12)+'...';}
res+='<td style=";vertical-align:bottom;width:100px;height:105px"><a href="/users/homes/'+users[i]['id']+'"><img src="/images/geticon/'+(users[i]['image_id']==null?'no/profile':users[i]['image_id'])+'"></img></a><br /><a href="/users/homes/'+users[i]['id']+'">'+u_string+'</a></td>';if((i+1)%5==0)
{res+='</tr>';}}
res+='</table>';var gp=jQuery('#likeContent');gp.html(res);lp.css('display','block');});}}}
Newsfeed.prototype.addMoreEvents=function()
{var self=this;this.more.bind('click',this.call_get);this.more.bind('mouseover',function(){self.more.css('background-color','#fafdff');});this.more.bind('mouseout',function(){self.more.css('background-color','#ffffff');});}
Newsfeed.prototype.submitComment=function(form)
{var self=this;var T=this.$commentPost.find('textarea');var submit=function(data)
{if(data)
{self.addComment(data);}
self.$commentPost.find('#r').click();T.attr('disabled',false);}
T.attr('disabled',true);jQuery.post('/users/newsfeed_comments_submit/'+this.Newsfeed.id,{id:this.id,comment:T[0].value},submit,'json');}
Newsfeed.prototype.addComment=function(data)
{if(!this.comments_array[data.id])
{var comment=new NewsfeedComment(data,this);this.comments_array[comment.id]=comment;if(this.comments.length?parseInt(comment.id)>parseInt(this.comments[this.comments.length-1].id):true)
{this.$comments.prepend(comment.element);this.$comments.prepend(this.$commentPost);this.comments.unshift(comment);}
else
{this.$comments.append(comment.element);this.comments.push(comment);}}}
Newsfeed.prototype.get=function(start,count)
{var cnt=count;var greater;var first=!this.comments.length;if(typeof start!='number'&&typeof start!='string')
{start=this.comments.length-1;greater=first;}
else
{greater=true;}
var self=this;var c;var count=this.min_count+(c=count?count:this.count);var callback=function(data)
{var i;var d;var n=data.length>c?data.length-self.min_count:data.length;for(i=0;i<n;i++)
{self.addComment(data[i],!first);}
if(self.element)
{if(!cnt&&self.more)
{if(data.length>c)
{self.more.appendTo(self.$comments);}
else
{self.more.hide();}}}
if(!cnt)
{self.textMore();}}
if(!cnt)
{self.textMore(true);}
jQuery.getJSON(this.url+'/users/newsfeed_comments_callback/'+this.id+'/'+(greater?count:-count)+'/'+(first?0:(this.comments.length>start?this.comments[start].id:0)),callback);}
Newsfeed.prototype.getComments=function()
{var id=this.comments.length?this.comments[this.comments.length-1].id:0;}
Newsfeed.prototype.hide=function()
{var self=this;var hide_callback=function(data)
{if(typeof data['error']=='undefined')
{self.element.hide(self.speed,function(e)
{self.parent.order.splice(self.index,1);});}
else
{alert(data['error']);}}
jQuery.getJSON('/users/hide_newsfeed_callback/'+this.Newsfeed.id,hide_callback);}
function NewsfeedComment(data,parent)
{var i;for(i in data)
{this[i]=data[i];}
this.url='';this.parent=parent;this.element=null;this.speed=navigator.appName.match(/Microsoft/i)?0:'medium';this.view();}
NewsfeedComment.empty='Enter your comments here';NewsfeedComment.prototype.addEvents=function()
{var self=this;this.element.bind('mouseover',function(){self.element.css('background-color','#fafdff');});this.element.bind('mouseout',function(){self.element.css('background-color','#f4f4f4');});}
NewsfeedComment.prototype.view=function()
{var regex=/((http(s?):\/\/))(\w+[^\s\)\<]+)/g;var newtext=this.comment.replace(regex,'<a href="$1$4" target="_blank">$1$4</a>');this.element=jQuery(this.htmlFeed(this.User,'writes a comment:','<div style="text-align:justify">'+newtext+'</div>'));this.element.show(this.speed);this.addEvents();return this.element;}
NewsfeedComment.prototype.htmlFeed=Newsfeeds.prototype.htmlFeed;try{if(typeof Shopping!='undefined')
{Newsfeeds.prototype.resizer=function()
{var $window=jQuery(window);var $document=jQuery(document);var documentHeight=this.documentHeight?this.documentHeight:$document.height();this.documentHeight=documentHeight;var windowHeight=$window.height();if(windowHeight==this.windowHeight)
{return;}
this.windowHeight=windowHeight;if(!this.$parent.length)
{return;}
var height=documentHeight>windowHeight?documentHeight:windowHeight;var top=this.$parent.parent().offset().top;var offset=height-top;var realHeight=this.height=offset-top+100;if(this.element)
{this.element.css('height',realHeight+'px');this.element.css('overflow-y','scroll');this.element.css('overflow-x','hidden');}
if((this.data instanceof Array)&&this.data.length)
{this.scroll();}}
Newsfeeds.prototype.getIndex=Shopping.prototype.getIndex;Newsfeeds.prototype.scroll=function(e)
{var index=this.getIndex();if(index[1]+1>this.length)
{this.get();}}
Newsfeeds.prototype.construct=function()
{var self=this;this.count*=2;this.no_more=false;jQuery(document).ready(function(){self.resizer()});jQuery(window).resize(function(){self.resizer();});this.$body=this.element;this.element.scroll(function(e){self.bodyScroll=self.element.scrollTop();self.scroll(e);});}}}catch(e){}
try{if(typeof Like=='function')
{Newsfeed.like=function(id,type,like,callback)
{var likes=new Like({type:type});likes.like(id,like,callback);return likes;}}}catch(e){}