TradeMe.namespace("ImageLoader");TradeMe.ImageLoader=function(a,b){this._init(a,b)};TradeMe.ImageLoader.prototype={_init:function(b,c){this._imgSrc=b;for(p in c){this[p]=c[p]}var a=new Image();if(this.onStart){this.onStart()}jQuery(a).bind("load",this,this.onLoad);jQuery(a).bind("error",this,this.onError);a.src=this._imgSrc},getImageSrc:function(){return this._imgSrc}};TradeMe.namespace("GalleryPhotoController");TradeMe.GalleryPhotoController=function(){this.init()};TradeMe.GalleryPhotoController.prototype={init:function(){this._iniDomPointers();this._iniEvents()},_iniDomPointers:function(){this._scrollLeftControllers=jQuery("img.galleryPhotoScrollLeft");this._scrollRightControllers=jQuery("img.galleryPhotoScrollRight")},_iniEvents:function(){this._scrollLeftControllers.bind("click",this,this._onScrollLeftClick);this._scrollRightControllers.bind("click",this,this._onScrollRightClick);this._scrollLeftControllers.mouseover(this._onScrollHover);this._scrollRightControllers.mouseover(this._onScrollHover);this._scrollLeftControllers.mouseout(this._onScrollHover);this._scrollRightControllers.mouseout(this._onScrollHover)},_onScrollHover:function(a){if(this.src.indexOf("_hover.gif")>0){this.src=this.src.replace(/_hover.gif/,".gif")}else{this.src=this.src.replace(/.gif/,"_hover.gif")}},_onScrollLeftClick:function(b){if(b.data.imageLoader){b.data.imageLoader.destroy()}var d=b.data._getPhotoIDs(b.target);var f=b.data._getImage(b.target);var c=b.data._getGvImagePathUrl(f);var a=b.data._getCurrentPhotoID(f);var i=b.data._getPreviousPhotoID(a,d);var j=b.data._getPhotoUrl(i,c);var h=b.data._getPhotoCounterText(d,i);var g=b.data._getPhotoCounter(b.target);b.data.imageLoader=b.data._loadImage(j,document.getElementById(f.attr("id")),h,g)},_onScrollRightClick:function(b){if(b.data.imageLoader){b.data.imageLoader.destroy()}var d=b.data._getPhotoIDs(b.target);var f=b.data._getImage(b.target);var c=b.data._getGvImagePathUrl(f);var a=b.data._getCurrentPhotoID(f);var h=b.data._getNextPhotoID(a,d);var i=b.data._getPhotoUrl(h,c);var g=b.data._getPhotoCounterText(d,h);var j=b.data._getPhotoCounter(b.target);b.data.imageLoader=b.data._loadImage(i,document.getElementById(f.attr("id")),g,j)},_loadImage:function(d,a,c,b){return new TradeMe.ImageLoader(d,{image:a,photoCounterText:c,photoCounter:b,_thread:null,onStart:function(){this.onLoadStart._oScope=this;this._thread=setTimeout(this.onLoadStart,600)},onLoadStart:function(){if(this!=arguments.callee._oScope){return arguments.callee.apply(arguments.callee._oScope,arguments)}var g=jQuery(this.image.parentNode.parentNode).offset();var e=document.createElement("div");e.style.cssText="position:absolute;width:236px;height:177px;z-index:100;opacity: 0.6;-moz-opacity: 0.6;filter: alpha(opacity=60);background-color:#000;";if(jQuery.browser.msie&&jQuery.browser.version>5){e.style.top=(g.top-2)+"px";e.style.left=(g.left-2)+"px"}else{e.style.top=(g.top+1)+"px";e.style.left=(g.left+1)+"px"}document.body.appendChild(e);this.divMask=e;var f=new Image();f.src="/images/NewSearchCards/GVIcons/loadingText.PNG";f.style.cssText="position:absolute;z-index:101;";f.style.top=(g.top+67)+"px";f.style.left=(g.left+55)+"px";document.body.appendChild(f);this.imgLoadingText=f},onLoad:function(f){if(f.data._thread!=null){f.data.image.src=f.data.getImageSrc();f.data.photoCounter.innerHTML=f.data.photoCounterText;f.data.destroy()}},onError:function(f){},destroy:function(){if(this.divMask){document.body.removeChild(this.divMask);this.divMask=null}if(this.imgLoadingText){document.body.removeChild(this.imgLoadingText);this.imgLoadingText=null}if(this._thread!=null){clearTimeout(this._thread);this._thread=null}}})},_getPhotoIDs:function(a){try{var c=jQuery(a).parent("td:first").children(":first-child");return c.attr("value").split(";")}catch(b){return[]}},_getCurrentPhotoID:function(a){var b=a.attr("src").split("/");return b[b.length-1].replace(".jpg","")},_getPreviousPhotoID:function(a,c){for(var b=0;b<c.length;b++){if(a==c[b]){return(b==0)?c[c.length-1]:c[b-1]}}return c[0]},_getNextPhotoID:function(a,c){for(var b=0;b<c.length;b++){if(a==c[b]){return(b==c.length-1)?c[0]:c[b+1]}}return c[0]},_getPhotoUrl:function(d,a){var b=d.substring(d.length-2,d.length-1);if(b=="0"){b=""}var c=d.substring(d.length-1,d.length);return a+"/"+b+c+"/"+d+".jpg"},_getGvImagePathUrl:function(a){var b=a.attr("src").split("/");return b.slice(0,b.length-2).join("/")},_getImage:function(b){try{var a=jQuery(b).parents("div:first");return a.find("img.galleryImage:first")}catch(c){return null}},_getPhotoCounter:function(a){try{var c=jQuery(a).parents("td:first");return document.getElementById(c.find("div:first").attr("id"))}catch(b){return null}},_getPhotoCounterText:function(b,c){for(var a=0;a<b.length;a++){if(c==b[a]){return((a+1)+"/"+b.length)}}}};new TradeMe.GalleryPhotoController();
