
var finderById=function(it){return it.id==this;}
var finderByAuctionId=function(it){return it.auctionID==this;}
Page=WL.Class(Object,function()
{this.auctionInfo=[];this.productInfo=[];var expires=new Date();expires.addMonths(1);this.soundCookie=new WL.Objects.Cookie("sound",expires.toString(CultureInfo.Date.formatPatterns.rfc1123));},function(type)
{var overCont=null;var offsetfrommouse=[10,10];var pageXY={x:0,y:0};var holdMove=false;type.main=function()
{window.setInterval(updateRemain,1000);updateRemain();doUpdateInfo();WL.attachListener(document,"mousemove",previewMove);}
type.getAuctionInfo=function(id){return this.auctionInfo.find(finderById.bind(id));}
type.getProductInfo=function(id){return this.productInfo.find(finderByAuctionId.bind(id));}
type.item_click=function(c_id)
{var c=WL.Utils.$(c_id);if(c!=null&&c.nodeType==1)
{var info=window.page.getAuctionInfo(parseInt(c.attributes["auctionID"].value));if(info!=null)
{if(info.state==AUCTION_STATE.Started)
{if(window.userID==0)
{WL.Utils.$("auctionid").value=info.id;WL.Utils.$("bidvalue").value=info.nextBidValue;WL.popup_show(WL.Utils.$("cont_login"));}
else if(info.winnerID!=window.userID)
window.auctionManagerAPI.makeBid(info.id,info.nextBidValue,on_makeBid.bind(this));}
else
if(info.state==AUCTION_STATE.Sold&&info.winnerID!=0&&info.winnerID==window.userID)
{WL.navigate("cart.aspx");}}}}
var on_makeBid=function(result)
{if(result.error)
{WL.alert(result.errorInfo?result.errorInfo.toString():"Make bid failed");return;}
this.auctionInfo.replaceIf(finderById.bind(result.info.id),result.info);this.updateAuctionInfo();}
var doUpdateInfo=function()
{var ids=[];for(var i=0;i<window.page.auctionInfo.length;++i)
ids.push(window.page.auctionInfo[i].id);window.auctionManagerAPI.getAuctionInfo(ids,on_getAuctionInfo.bind(window.page),true);}
var on_getAuctionInfo=function(result)
{if(!result.error){this.auctionInfo=result.list;this.updateAuctionInfo();}
window.setTimeout(doUpdateInfo,3000);}
var playSound=function()
{var sound=WL.Utils.$("in_sounds").value;if(sound!='off'){WL.Utils.$("divSound").innerHTML="<embed autoplay='true' height='0' width='0' id='sound' src='Files/"+sound+"' >";}}
type.highlightAuction=function(id,count)
{var auctionFrame=document.getElementById(id);if(count%2==0){auctionFrame.className='auction-item auction-item-selected';}
else{auctionFrame.className='auction-item auction-item-notselected';}
count--;if(count>0){window.setTimeout("window.page.highlightAuction('"+id+"',"+count+")",250);}}
type.onSoundChanged=function()
{var sound=WL.Utils.$("in_sounds").value;this.soundCookie.remove("sound");this.soundCookie.set("",sound);}
var previousPrice;type.updateAuctionInfo=function()
{var nodes=WL.Utils.$("auction_list").childNodes;for(var i=0;i<nodes.length;++i)
if(nodes[i].nodeType==1)
{var info=window.page.getAuctionInfo(parseInt(nodes[i].attributes["auctionID"].value));if(info!=null)
{if(info.state==AUCTION_STATE.Started)
{nodes[i].childNodes[3].innerHTML="$"+info.currentPrice.toMoney();nodes[i].childNodes[7].innerHTML=info.winner;try
{if(previousPrice==null)
previousPrice=new Array(WL.Utils.$("auction_list").childNodes.length);if(previousPrice[i]==null)
previousPrice[i]=info.currentPrice;if(previousPrice[i]!=info.currentPrice)
{previousPrice[i]=info.currentPrice;playSound();window.setTimeout("window.page.highlightAuction('"+nodes[i].id+"', 6)",250);}}
catch(e){}
var btn=nodes[i].childNodes[6].firstChild.control;if(info.winnerID!=0&&info.winnerID==window.userID)
{btn.setCssClass("winning_button");btn.setRID(112);}
else
{var time=new WL.Objects.Time(Math.floor((info.dateStop.valueOf()-WL.Utils.getServerTime().valueOf())/1000));if(time.getTotalSeconds()>12)btn.setCssClass("button");btn.setText(String.format("{0} ${1}",WL.S(111),info.nextBidValue.toMoney()));}}
else
{if(nodes[i].childNodes[4].style.display!="none")
{nodes[i].childNodes[3].innerHTML="$"+info.currentPrice.toMoney();nodes[i].childNodes[7].innerHTML=info.winner;nodes[i].childNodes[4].style.display="none";nodes[i].childNodes[5].style.display="";nodes[i].childNodes[5].innerHTML=WL.SHTML(info.state==AUCTION_STATE.Sold?290:291);if(info.winnerID!=0&&info.winnerID==window.userID)
{var btn=nodes[i].childNodes[6].firstChild.control;btn.setCssClass("winning_button");btn.setRID(112);}
else
nodes[i].childNodes[6].style.visibility="hidden";}}}}}
var updateRemain=function()
{var btn_class=(new Date().getSeconds()%2)!=0?"button":"default_button";var nodes=WL.Utils.$("auction_list").childNodes;for(var i=0;i<nodes.length;++i)
if(nodes[i].nodeType==1)
{var info=window.page.getAuctionInfo(parseInt(nodes[i].attributes["auctionID"].value));if(info!=null&&info.state==AUCTION_STATE.Started)
{var time=new WL.Objects.Time(Math.floor((info.dateStop.valueOf()-WL.Utils.getServerTime().valueOf())/1000));if(time.getTotalSeconds()<=0)
nodes[i].childNodes[4].innerHTML=WL.SHTML(289);else
nodes[i].childNodes[4].innerHTML=time.toString();if(time.getTotalSeconds()<=12)
{if(window.userID==0||info.winnerID!=window.userID)
{var btn=nodes[i].childNodes[6].firstChild.control;btn.setCssClass(btn_class);}}}}}
var previewMove=function(e)
{e=WL.getEvent(e);var previewCont=WL.Utils.$("preview");var cont=e.target;while(cont){if(cont.className&&cont.className=="auction-item-img")break;cont=cont.parentNode;}
if(overCont!=cont)
{overCont=cont;}
else
{if(cont==null||previewCont.style.display=="none")pageXY=WL.Utils.getMouseCoords(e);else
{var offset=WL.Utils.getEventElementOffset(e,cont);var dx=offsetfrommouse[0]*2;var dy=offsetfrommouse[1]*2;if(WL.Utils.isPointInRange(offset.left,offset.top,dx,dy,cont.offsetWidth-dx,cont.offsetHeight-dy))
pageXY=WL.Utils.getMouseCoords(e);}}
if(previewCont.style.display!="none")
{var el=e.target;while(el){if(el==previewCont){stopHidePreview();return;}el=el.parentNode;}
if(cont!=null)
window.page.showPreview(parseInt(cont.parentNode.attributes["auctionID"].value),e);else
hidePreviewDelay();}
else
{if(cont!=null)
showPreviewDelay(parseInt(cont.parentNode.attributes["auctionID"].value));else
stopShowPreview();}}
var stopShowPreview=function(){if(window.page.showCookie){window.clearTimeout(window.page.showCookie);window.page.showCookie=null;}}
var stopHidePreview=function(){if(window.page.hideCookie){window.clearTimeout(window.page.hideCookie);window.page.hideCookie=null;}}
type.showPreview=function(auctionID,e)
{stopShowPreview();stopHidePreview();var productInfo=this.getProductInfo(auctionID);if(productInfo!=null)
{var preview=WL.Utils.$("preview");if(preview.auction!=productInfo.auctionID)
{try{WL.Utils.$("previewTitle").innerHTML=productInfo.title;}
catch(e){WL.Utils.$("previewTitle").innerHTML="Invalid HTML";}}
if(preview.style.display=="none")
preview.style.display="block";if(preview.auction!=productInfo.auctionID)
{preview.auction=productInfo.auctionID;var fc=WL.Utils.$$("previewImage").getFullImageContainer();WL.Utils.setNew(fc.style,"cursor","pointer");fc.onclick=WL.navigate.bindWA(WL,"auction.aspx?auction="+productInfo.auctionID);WL.Utils.$$("previewImage").setSize(375,0);WL.Utils.$$("previewImage").setImagesList(productInfo.images);}
var pos=getContPosition();preview.style.left=pos.x+"px";preview.style.top=pos.y+"px";}}
var showPreviewDelay=function(auctionID)
{if(!window.page.showCookie)
window.page.showCookie=window.setTimeout(window.page.showPreview.bindWA(window.page,auctionID),500);}
var hidePreview=function(){WL.Utils.setNew(WL.Utils.$("preview").style,"display","none");}
var hidePreviewDelay=function()
{if(!window.page.hideCookie)
window.page.hideCookie=window.setTimeout(hidePreview,1000);}
var getContPosition=function()
{var body=WL.Utils.getBody();var sbody=WL.Utils.getScrollBody();var xcoord=offsetfrommouse[0];var ycoord=offsetfrommouse[1];var cont_width=WL.Utils.$("preview").offsetWidth;var cont_height=WL.Utils.$("preview").offsetHeight;if(WL.browser.ie)
{var docwidth=body.scrollLeft+body.clientWidth;var docheight=body.clientHeight;}
else
{var docwidth=window.pageXOffset+window.innerWidth-15;var docheight=window.innerHeight;}
if(docwidth-pageXY.x<cont_width+2*offsetfrommouse[0])
xcoord=pageXY.x-xcoord-cont_width;else
xcoord+=pageXY.x;if(docheight-pageXY.y<cont_height+2*offsetfrommouse[1])
ycoord+=pageXY.y-Math.max(0,(2*offsetfrommouse[1]+cont_height+pageXY.y-docheight-sbody.scrollTop));else
ycoord+=pageXY.y;return{x:Math.max(0,xcoord),y:Math.max(0,ycoord)};}});