
function EbayHTMLLayer(pParent,pName,pDisabled,pCfg)
{if(!this.objType)
this.objType="EbayHTMLLayer";this.base=EbayHTML;this.base(pParent,pName,pName,pDisabled,pCfg);this.aBindEvents=new Array;this.getElem=ebHTMLLayerGetElem;this.getValue=ebHTMLLayerGetValue;this.setValue=ebHTMLLayerSetValue;}
function ebHTMLLayerGetElem(pName)
{var s=pName,d=this.oDocument.doc;if(d.getElementById)
return d.getElementById(s);else if(d.all)
return d.all(s);this.throwWarning("Not supported","getElem");}
function ebHTMLLayerGetValue(pIsText)
{if(this.eElem)
{if(pIsText)
{if(this.oDocument.oGlobals.oClient.bFirefox)
return this.eElem.textContent;else
return this.eElem.innerText;}
else
return this.eElem.innerHTML;}
else
return"";}
function ebHTMLLayerSetValue(pVal,pIsText)
{if(this.eElem)
{if(pIsText)
{if(this.oDocument.oGlobals.oClient.bFirefox)
this.eElem.textContent=pVal;else
this.eElem.innerText=pVal;}
else
this.eElem.innerHTML=pVal;}}

//21@@m7
function myclose()
{
	document.getElementById('SuperGalleryDialog').style.display="none";

}

function EbayHTMLImage(pParent,pName,pDisabled,pSource,pDisabledSource,pCfg)
{if(!this.objType)
this.objType="EbayHTMLImage";this.base=EbayHTML;this.base(pParent,pName,pName,pDisabled,pCfg);this.sEnabledSource=this.sDisabledSource=pSource;if(pDisabledSource)
this.sDisabledSource=pDisabledSource;this.getElem=ebHTMLImageGetElem;this.source=ebHTMLImageSource;this.enableBase=this.enable;this.enable=ebHTMLImageEnable;this.subscribeEvents("onclick","onmouseover","onmouseout");}
function ebHTMLImageGetElem(pName)
{return this.getDocElem(pName,'images');}
function ebHTMLImageSource(pSrc,pText)
{var im=this.eElem;if(typeof(im)=='undefined')
return;if(typeof(pSrc)=="undefined")
return(im)?im.src:"";else
{im.src=pSrc;if(pText!=null)
im.alt=pText;}}
function ebHTMLImageEnable(pEnable)
{with(this)
{enableBase(pEnable);if(sDisabledSource&&eElem)
eElem.src=(pEnable)?sEnabledSource:sDisabledSource;}}

//22@@m6

window.toPixels=function(number)
{
	return number+"px";
};

window.metaInfo=function(name,value){var tags=document.getElementsByTagName("meta");for(var idx=0;(idx<tags.length);idx++){if(tags[idx][name]==value)return tags[idx];}
return null;};window.scrollTop=function(){if(window.pageYOffset!=null)return window.pageYOffset;else if(document.documentElement&&document.documentElement.scrollTop)return Math.max(document.documentElement.scrollTop,document.body.scrollTop);else return document.body.scrollTop;};window.scrollLeft=function(){if(window.pageXOffset!=null)return window.pageXOffset;else if(document.documentElement&&document.documentElement.scrollLeft)return Math.max(document.documentElement.scrollLeft,document.body.scrollLeft);else return document.body.scrollLeft;};window.scrollWidth=function(){return Math.max(document.body.offsetWidth,document.body.scrollWidth);};window.scrollHeight=function(){var scrollHeight=Math.max(document.body.offsetHeight,document.body.scrollHeight);if(document.documentElement)return Math.max(scrollHeight,document.documentElement.offsetHeight);else return scrollHeight;};window.clientTop=function(){if(document.documentElement)return document.documentElement.clientTop;else return document.body.clientTop;};window.clientLeft=function(){if(document.documentElement)return document.documentElement.clientLeft;else return document.body.clientLeft;};window.clientWidth=function(){var documentElement=document.documentElement;if(documentElement&&documentElement.clientWidth&&window.innerWidth)return Math.min(documentElement.clientWidth,window.innerWidth);else if(documentElement&&documentElement.clientWidth)return documentElement.clientWidth;else if(window.innerWidth)return window.innerWidth;else if(document.body.clientWidth)return document.body.clientWidth;else return document.body.offsetWidth;};window.clientHeight=function(){var documentElement=document.documentElement;if(documentElement&&documentElement.clientHeight&&window.innerHeight)return Math.min(documentElement.clientHeight,window.innerHeight);else if(documentElement&&documentElement.clientHeight)return documentElement.clientHeight;else if(window.innerHeight)return window.innerHeight;else if(document.body.clientHeight)return document.body.clientHeight;else return document.body.offsetHeight;};window.browserTop=function(){return(window.innerHeight)?window.screenY+(window.outerHeight-window.innerHeight):window.screenTop;};window.browserLeft=function(){return(window.innerWidth)?window.screenX+(window.outerWidth-window.innerWidth):window.screenLeft;};window.offsetTop=function(element){for(var offsetTop=0;(element!=null);element=element.offsetParent)offsetTop+=element.offsetTop;return offsetTop;};window.offsetLeft=function(element){for(var offsetLeft=0;(element!=null);element=element.offsetParent)offsetLeft+=element.offsetLeft;return offsetLeft;};window.eventTop=function(event){if(event.pageY!=null)return event.pageY;else if(document.documentElement&&document.documentElement.scrollTop)return event.clientY+Math.max(document.documentElement.scrollTop,document.body.scrollTop);else return event.clientY+document.body.scrollTop;};window.eventLeft=function(event){if(event.pageX!=null)return event.pageX;else if(document.documentElement&&document.documentElement.scrollLeft)return event.clientX+Math.max(document.documentElement.scrollLeft,document.body.scrollLeft);else return event.clientX+document.body.scrollLeft;};window.createElement=function(name){return document.standardCreateElement?document.standardCreateElement(name):document.createElement(name);};window.containsElement=function(container,element){while((element.parentNode!=null)&&(element!=container))element=element.parentNode;return(element==container);};window.firstTagName=function(parent,tagName){for(var node=parent.firstChild;((node!=null)&&(node.tagName!=tagName));node=node.nextSibling);return node;};



DHTMLEvent=new Object();if(window.addEventListener){
DHTMLEvent.addEventListener=function(object,name,listener)
{
	return object.addEventListener(name,listener,true);
};

DHTMLEvent.removeEventListener=function(object,name,listener)
{object.removeEventListener(name,listener,true);};
}
else if(window.attachEvent){DHTMLEvent.addEventListener=function(object,name,listener){return object.attachEvent("on"+name,listener);};DHTMLEvent.removeEventListener=function(object,name,listener){object.detachEvent("on"+name,listener);};}
else{DHTMLEvent.addEventListener=function(object,name,listener){return false};DHTMLEvent.removeEventListener=function(object,name,listener){};};DHTMLEvent.target=function(event){return(event.target)?event.target:event.srcElement;};DHTMLEvent.currentTarget=function(event){return(event.currentTarget)?event.currentTarget:event.srcElement;};DHTMLEvent.originalTarget=function(event){return(event.originalTarget)?event.originalTarget:event.srcElement;};

//25@@m19

BalloonDialog=function(parent,name,config){var self=this;this.name=name;this.config=config;this.client=ebay.oGlobals.oClient;this.ie5=(this.client.bIE&&this.client.iVer==5);this.dialog=document.getElementById(this.name);this.dialog=this.dialog.parentNode.removeChild(this.dialog);this.dialog=document.body.insertBefore(this.dialog,document.body.firstChild);this.content=document.getElementById(this.name.concat("Content"));this.frame=document.getElementById(this.name.concat("Frame"));this.body=document.getElementById(this.name.concat("Body"));this.backing=this.createBacking();this.shadow=document.getElementById(this.name.concat("Shadow"));this.arrowLeft=document.getElementById(this.name.concat("ArrowLeft"));this.arrowRight=document.getElementById(this.name.concat("ArrowRight"));this.onmousemove=function(event){return self.onMouseMove(event);};this.onresize=function(){return self.resize();};this.ontimeout=function(){return self.onTimeout();};this.listener=(document.documentElement)?document.documentElement:document.body;this.timer=null;this.resizer=null;};BalloonDialog.prototype.createBacking=function(){var backing=this.backing;if(backing!=null)return backing;backing=window.createElement("iframe");backing.frameBorder=0;backing.className="backing";backing.style.display=this.client.bIE?"block":"none";return this.content.insertBefore(backing,this.content.firstChild);};BalloonDialog.prototype.load=function(content){this.body.innerHTML=content;};

BalloonDialog.prototype.open=function(top,left,width,height,origin)
{	//alert (width+','+height);
	this.top=top;
	this.left=left;
	this.width=width;
	this.height=height;
	this.origin=origin;
	this.active=true;
	this.borderWidth=(!this.ie5)?2:0;this.borderHeight=(!this.ie5)?2:0;
	this.scrollTop=window.scrollTop();
	this.scrollLeft=window.scrollLeft();
	this.clientWidth=window.clientWidth();
	this.clientHeight=window.clientHeight();
	this.clientBottom=this.scrollTop+this.clientHeight;
	this.clientRight=this.scrollLeft+this.clientWidth;
	this.dialog.style.display="none";
	this.backing.style.width="auto";
	this.backing.style.height="auto";
	this.shadow.style.width="auto";
	this.shadow.style.height="auto";
	this.frame.style.width="auto";
	this.frame.style.height="auto";
	this.resizes=4;this.resize();
};
BalloonDialog.prototype.resize=function()
{
	this.dialog.style.display="block";var widthLeft=this.clientRight-(this.left+(this.body.offsetWidth+27));var widthRight=(this.left-(this.body.offsetWidth+27))-this.scrollLeft;if(!this.config.isIEQuirksMode&&!this.config.isFirefoxQuirksMode){this.frameHeight=Math.min(this.body.offsetHeight+(this.frame.clientHeight?(this.frame.offsetHeight-this.frame.clientHeight):this.borderHeight),this.clientHeight,this.height);this.frame.style.height=window.toPixels(this.frameHeight-this.borderHeight);}
if(widthLeft>=0)this.openLeft();else if(widthRight>=0)this.openRight();else if(widthRight>widthLeft)this.openRight();else this.openLeft();if(!this.config.isIEQuirksMode&&!this.config.isFirefoxQuirksMode){this.frameHeight=Math.min(this.body.offsetHeight+(this.frame.clientHeight?(this.frame.offsetHeight-this.frame.clientHeight):this.borderHeight),this.clientHeight,this.height);this.frame.style.height=window.toPixels(this.frameHeight-this.borderHeight);}
this.offsetTop=Math.max(Math.min(this.top-this.origin,this.clientBottom-this.frame.offsetHeight-this.shadow.offsetTop),this.scrollTop);this.arrowTop=Math.min(this.top-this.offsetTop,this.frame.offsetHeight-27);this.frame.scrollTop=0;this.shadow.style.width=window.toPixels(this.frame.offsetWidth);this.shadow.style.height=window.toPixels(this.frame.offsetHeight);this.dialog.style.top=window.toPixels(this.offsetTop);this.dialog.style.left=window.toPixels(this.offsetLeft);this.backing.style.width=window.toPixels(this.content.offsetWidth);this.backing.style.height=window.toPixels(this.content.offsetHeight);this.arrow.style.top=window.toPixels(this.arrowTop);var element=(document.documentElement)?document.documentElement:document.body;DHTMLEvent.removeEventListener(this.listener,"mousemove",this.onmousemove);DHTMLEvent.addEventListener(this.listener,"mousemove",this.onmousemove);if(this.resizes--)this.resizer=window.setTimeout(this.onresize,100);else this.setTimeout(this.config.timeout,true);
};

BalloonDialog.prototype.openLeft=function(){this.arrow=this.arrowLeft;this.arrow.style.display="block";this.arrowRight.style.display="none";this.offsetLeft=Math.max(this.left,this.scrollLeft);if(this.config.isIEQuirksMode){this.IEQuirksAdjust(this.clientRight-this.arrowLeft.offsetWidth-this.offsetLeft);}else if(this.config.isFirefoxQuirksMode){this.FirefoxQuirksAdjust(this.clientRight-this.arrowLeft.offsetWidth-this.offsetLeft);}else{this.frameWidth=Math.min(this.body.offsetWidth+(this.frame.clientWidth?(this.frame.offsetWidth-this.frame.clientWidth):this.borderWidth),this.clientRight-this.arrowLeft.offsetWidth-this.offsetLeft-this.shadow.offsetLeft,this.width);this.frame.style.width=window.toPixels(this.frameWidth-this.borderWidth);}};BalloonDialog.prototype.openRight=function(){this.arrow=this.arrowRight;this.arrow.style.display="block";this.arrowLeft.style.display="none";this.offsetRight=Math.min(this.left,this.clientRight);if(this.config.isIEQuirksMode){this.IEQuirksAdjust(this.offsetRight-this.arrowRight.offsetWidth-this.scrollLeft);}else if(this.config.isFirefoxQuirksMode){this.FirefoxQuirksAdjust(this.offsetRight-this.arrowRight.offsetWidth-this.scrollLeft);}else{this.frameWidth=Math.min(this.body.offsetWidth+(this.frame.clientWidth?(this.frame.offsetWidth-this.frame.clientWidth):this.borderWidth),this.offsetRight-this.arrowRight.offsetWidth-this.scrollLeft,this.width);this.frame.style.width=window.toPixels(this.frameWidth-this.borderWidth);}
this.offsetLeft=Math.max(this.offsetRight-this.dialog.offsetWidth,0);};BalloonDialog.prototype.IEQuirksAdjust=function(Hoffset){var Voffset=this.clientHeight;var hasHScrollBar=Hoffset<this.body.offsetWidth?true:false;var hasVScrollBar=Voffset<this.body.offsetHeight?true:false;if(hasHScrollBar){this.frame.style.width=window.toPixels(Hoffset);this.frame.style.height=window.toPixels(this.body.offsetHeight+(this.frame.offsetHeight-this.frame.clientHeight));}
if(hasVScrollBar)
this.frame.style.height=window.toPixels(Voffset);};BalloonDialog.prototype.FirefoxQuirksAdjust=function(Hoffset){this.clientBottom=this.scrollTop+this.clientHeight-11;Hoffset-=2;var Voffset=this.clientHeight-2;var hasHScrollBar=Hoffset<this.body.offsetWidth?true:false;var hasVScrollBar=Voffset<this.body.offsetHeight?true:false;if(hasHScrollBar&&!hasVScrollBar){this.frame.style.width=window.toPixels(Hoffset);if(Voffset-16<this.frame.offsetHeight)
this.frame.style.height=window.toPixels(Voffset-16);}
else if(hasVScrollBar&&!hasHScrollBar){if(window.scrollWidth()-window.clientWidth()>0)
this.frame.style.height=window.toPixels(Voffset-16);else
this.frame.style.height=window.toPixels(Voffset);}
else if(hasVScrollBar&&hasHScrollBar){this.frame.style.width=window.toPixels(Hoffset);this.frame.style.height=window.toPixels(Voffset-16);}
else{this.frame.style.width=window.toPixels(this.body.offsetWidth);}};BalloonDialog.prototype.close=function(){this.active=false;this.dialog.style.display="none";window.clearTimeout(this.timer);window.clearTimeout(this.resizer);DHTMLEvent.removeEventListener(this.listener,"mousemove",this.onmousemove);if(this.onclose)this.onclose();};BalloonDialog.prototype.setTimeout=function(timeout,active){this.active=active;window.clearTimeout(this.timer);this.timer=(timeout)?window.setTimeout(this.ontimeout,timeout):null;return false;};BalloonDialog.prototype.onTimeout=function(event){this.close();};BalloonDialog.prototype.onMouseMove=function(event){var eventTarget=DHTMLEvent.target(event);if(window.containsElement(this.link,eventTarget))return this.setTimeout(this.timeout,true);else if(window.containsElement(this.frame,eventTarget))return this.setTimeout(this.timeout,true);else if(window.containsElement(this.arrow,eventTarget))return this.setTimeout(this.timeout,true);var xorg=window.offsetLeft(this.arrow)-window.eventLeft(event);var yorg=window.offsetTop(this.arrow)-window.eventTop(event);if((Math.abs(xorg)<25)&&(Math.abs(yorg)<25))return this.setTimeout(this.timeout,true);else if(this.active)return this.setTimeout(this.config.mouseout,false);};BalloonDialog.prototype.hideSelects=function(){this.selects=new Array();var dialogTop=window.offsetTop(this.dialog);var dialogLeft=window.offsetLeft(this.dialog);var dialogBottom=dialogTop+this.dialog.offsetHeight;var dialogRight=dialogLeft+this.dialog.offsetWidth;var selects=document.getElementsByTagName("select");for(var idx=0;(idx<selects.length);idx++){var select=selects[idx];var selectTop=window.offsetTop(select);var selectLeft=window.offsetLeft(select);var selectBottom=selectTop+select.offsetHeight;var selectRight=selectLeft+select.offsetWidth;if((selectTop>dialogBottom)||(selectBottom<dialogTop))continue;else if((selectLeft>dialogRight)||(selectRight<dialogLeft))continue;select.style.visibility="hidden";this.selects[this.selects.length]=select;}};BalloonDialog.prototype.showSelects=function(){for(var idx=0;(idx<this.selects.length);idx++){this.selects[idx].style.visibility="inherit";}};

//26@@m24

function SuperGallery(pBase,config){
var self=this;
this.objType="SuperGallery";
this.base=EbayBaseControl;
this.base(pBase,"SuperGallery");
this.config=config;
this.onopen=function(){return self.onOpen();};
this.onclose=function(){return self.onClose();};
this.onmouseout=function(event){return self.onMouseOut(event);};
this.body=document.getElementById("SuperGalleryDialogBody");
this.image=document.getElementById("SuperGalleryDialogImage");
this.thumbs=document.getElementById("SuperGalleryDialogThumbs");
this.thumblayer=document.getElementById("SuperGalleryThumbLayer");
this.slider=document.getElementById("SuperGallerySlider");
this.paginationUp=document.getElementById("paginationUp");
this.paginationDown=document.getElementById("paginationDown");
this.sliderUp=document.getElementById("ArrowUp");
this.sliderDown=document.getElementById("ArrowDown");
this.onloadimage=function(event){return self.onLoadImage(event);};
this.onloaderror=function(){return self.onLoadError();};
this.onloadticker=function(){return self.showProgress();};
this.onscrolldown=function(){return self.onScrollDown();};
this.onscrollup=function(){return self.onScrollUp();};
this.onimgload=function(){return self.shrinknShowSSImage();};
this.onload=function(){return self.preCache();};
this.dialog=new BalloonDialog(this,"SuperGalleryDialog",config);
this.dialog.onclose=this.onclose;
};

SuperGallery.prototype.setDelay=function(event,link,gallery,top,left)
{
	this.link=link;
	this.gallery=gallery;
	this.top=window.offsetTop(this.link)+top;
	this.left=window.offsetLeft(this.link)+left;
	window.clearTimeout(this.timer);
	this.timer=window.setTimeout(this.onopen,this.config.mouseover);
	DHTMLEvent.removeEventListener(this.link,"mouseout",this.onmouseout);
	DHTMLEvent.addEventListener(this.link,"mouseout",this.onmouseout);
	return false;
};

SuperGallery.prototype.onMouseOut=function(event)
{
	window.clearTimeout(this.timer);
	DHTMLEvent.removeEventListener(this.link,"mouseout",this.onmouseout);
	return false;
};

SuperGallery.prototype.onOpen=function()
{
	this.SGContent();
	this.bigImages=new Array(this.gallery.nImgs);
	this.dialog.link=this.link;
	
	var iHeight = this.gallery.iHeight;
	var iWidth = this.gallery.iWidth;

//	alert (iHeight +','+  iWidth);

	//alert (this.config.isIEQuirksMode)
//	if(this.config.isIEQuirksMode)
//	{
//		this.dialog.body.style.width=window.toPixels((this.gallery.enableThumbs=="true"&&(this.gallery.nImgs>1))?504:420);
//	}
//	else
	{
	//alert (this.config.host+this.gallery.id)
//	myImage = new Image();
//	myImage.src = this.config.host+this.gallery.id;
	
	//alert('t')
	//img_resize(iHeight,iWidth)

	var myheight = iHeight; 
	var mywidth = iWidth;

	//alert (myheight +','+  mywidth);

	var i = img_resize(iHeight,iWidth);

	i = i.split('_');
	
	if (i[0] != 0)
	{
		myheight = i[0];
	}	

	if (i[1] != 0)
	{
		mywidth  = i[1];
	}

	mywidth = eval(mywidth+"+15");

	myheight = eval(myheight+"+25");

	//alert ('test == '+i[1]+'=='+mywidth)

	this.dialog.body.style.width=window.toPixels((this.gallery.enableThumbs=="true"&&(this.gallery.nImgs>1))?510:mywidth);

	//this.dialog.body.style.height=window.toPixels(myheight);
	//alert (this.dialog.body.style.width+' --test');
	}
	
	document.getElementById('SuperGalleryDialogImage').style.height = myheight+'px';
	
	document.getElementById('SuperGalleryDialogImage').style.width = mywidth+'px';

	this.dialog.open(this.top,this.left,this.config.width,this.config.height,this.config.origin);
	this.slider.style.top=window.toPixels(0);
	DHTMLEvent.removeEventListener(this.link,"mouseout",this.onmouseout);
	this.loader=new Object();
	this.loader.index=0;
	this.loader.elapsed=0;
	this.preCache();
};

SuperGallery.prototype.preCache=function()
{
	this.loaded=false;
	this.loader.image=new Image();
	this.loader.start=new Date().getTime();
	var index=this.loader.index+1;
	//this.gallery.id='mdc_best/pcat-ts/products-large1/s_product_sample_1-blowup-1.jpg';
	//var bigImgUrl=this.config.host+this.gallery.id+"_"+index+"_"+this.gallery.version+"_1.jpg";
	var bigImgUrl=this.config.host+this.gallery.id;
	this.loader.tick=Math.max(Math.round(this.loader.elapsed/16),250);
	this.loader.timeout=window.setTimeout(this.onloaderror,Math.max(32*this.loader.tick,30000));
	this.loader.image.onload=this.onloadimage;
	this.loader.image.onerror=this.onloaderror;
	this.loader.image.onabort=this.onloaderror;
	if(this.gallery.nImgs>1&&this.gallery.enableThumbs=="true")
	this.showProgress();

	//alert (bigImgUrl);
	//bigImgUrl = '../../../bhptemp.mypcat.com/mdc_best/pcat-ts/products-large1/s_product_sample_1-blowup-1.jpg';
	this.loader.image.src=bigImgUrl;
	//this.loader.image.height = 300;
	//alert (this.loader.image.height);
/*
	this.loader.image.height ="200px";
	this.loader.image.width ="200px";	*/
};

SuperGallery.prototype.showProgress=function()
{
	if(this.loader.index<this.gallery.nImgs)
	{
		var str="progressLyr"+this.loader.index;
		var oProgressLyr=document.getElementById(str);
		oProgressLyr.style.top=window.toPixels(oProgressLyr.offsetTop+10);
		if(oProgressLyr.offsetHeight>10)
		oProgressLyr.style.height=window.toPixels(oProgressLyr.offsetHeight-10);
		if(oProgressLyr.offsetHeight>4)
		this.loader.ticker=window.setTimeout(this.onloadticker,this.loader.tick);
	}
};

SuperGallery.prototype.onLoadImage=function(event)
{
	this.loaded=true;
	window.clearTimeout(this.loader.ticker);
	window.clearTimeout(this.loader.timeout);

	if(this.loader.index==0&&(this.gallery.nImgs==1||this.gallery.enableThumbs!="true"))
	{
		var imgId=document.getElementById("imgBig");
		imgId.src=this.loader.image.src;

// 		if (imgId.width > 500 )
// 		{
// 			imgId.width = 500;
// 		}
// 		else if (imgId.height > 500 )
// 		{
// 			imgId.height = 500;
// 		}
	 
		//alert (this.gallery.iHeight +'======'+this.gallery.iWidth);

		var i = img_resize(this.gallery.iHeight, this.gallery.iWidth);
		i = i.split('_');
		var myheight = i[0];
		var mywidth  = i[1];
	
		imgId.width = mywidth ;
		imgId.height = myheight;

		this.onBigImgload();
	}
	else
	{
		if(this.loader.index<this.gallery.nImgs)
		{
			var str="progressLyr"+this.loader.index;
			var oProgressLyr=document.getElementById(str);
			oProgressLyr.style.top=window.toPixels(64);
			oProgressLyr.style.height=window.toPixels(0);
			oProgressLyr.style.display="none";	this.bigImages[this.loader.index]=this.loader.image.src;
			if(this.loader.index==0)
			{
				var imgId=document.getElementById("imgBig");
				imgId.src=this.loader.image.src;
				this.onBigImgload();
			}
			else
			{
				this.onLoadDone();
			}
		}
	}
};

SuperGallery.prototype.onLoadDone=function()
{	
	this.loader.index=this.loader.index+1;
	this.loader.finish=new Date().getTime();
	this.loader.elapsed=Math.max(this.loader.finish-this.loader.start,1);
	
	//alert (this.loader.index +'======='+ this.gallery.nImgs +'-------'+this.loaded +'--'+this.loader.elapsed)

	if(this.loader.index<this.gallery.nImgs)
	return window.setTimeout(this.onload,1);
	else if(!this.loaded)
	this.setBigImgTxt(this.config.error);
	//alert ("going to set error")
};

SuperGallery.prototype.onLoadError=function(){window.clearTimeout(this.loader.ticker);window.clearTimeout(this.loader.timeout);if((this.gallery.enableThumbs=="true")&&(this.gallery.nImgs>1)){var str="progressLyr"+this.loader.index;var oProgressLyr=document.getElementById(str);oProgressLyr.style.display="block";oProgressLyr.style.top=window.toPixels(0);oProgressLyr.style.left=window.toPixels(0);oProgressLyr.style.height=window.toPixels(64);}
this.onLoadDone();};SuperGallery.prototype.onClose=function(){var oSurvey=ebay.oDocument.oPage._getControl("KeyFlow.Exit.Survey");if(oSurvey)
oSurvey.enable();};

SuperGallery.prototype.SGContent=function()
{
	this.setBigImgTxt(this.config.loading);
	if(this.gallery.enableThumbs=="true"&&this.gallery.nImgs>1)
	{
		this.thumbs.style.display="";
		this.slider.innerHTML=this.getThumbLayerContent();
		//alert (this.slider.innerHTML);
		if(this.config.isIEQuirksMode)
		this.thumblayer.style.width=window.toPixels(79);
		if(this.gallery.nImgs<=4)
		{	
			this.paginationUp.style.display="none";
			this.paginationDown.style.display="none";
			this.thumblayer.style.marginTop=window.toPixels(41);
		}
		else
		{
			this.paginationUp.style.display="block";
			this.paginationDown.style.display="block";
			this.thumblayer.style.marginTop=window.toPixels(19);
		}
	
		this.images=this.slider.getElementsByTagName("div");
		this.images[0].className="outerThumbDiv selected";
		var setThumbOpacity="";
		var opacity=0.7;
		for(var i=0;i<this.gallery.nImgs;i++)
		{
			setThumbOpacity=document.getElementById("progressLyr"+i);
			setThumbOpacity.style.filter="alpha(opacity="+parseInt(100*opacity)+")";
			setThumbOpacity.style.opacity=opacity;
		}
		this.selected=0;this.scrollEnable(0);
		this.dialogHandlers();
	}
	else
	{
		this.thumbs.style.display="none";
	}
	this.oBigImg=new EbayHTMLImage(this,'imgBig');
	this.oBigImg._registerEvent("onclick","parent.showViewItem");
	this.oBigImg.showViewItem=parent.showViewItem;
	this.oBigImg.bind();
};


SuperGallery.prototype.scrollEnable=function(scrollIndex)
{
	this.scrollIndex=scrollIndex;	
	var i=scrollIndex+4;
	this.sliderUp.disabled=(scrollIndex<=0);
	this.sliderUp.src=(this.sliderUp.disabled)?this.config.coreImgHost+"buttons/btnpreviousNA.gif":this.config.coreImgHost+"buttons/btnprevious.gif";
	this.paginationUp.style.cursor=(this.sliderUp.disabled)?"default":"pointer";
	this.sliderDown.disabled=(i>=this.gallery.nImgs);
	this.sliderDown.src=(this.sliderDown.disabled)?this.config.coreImgHost+"buttons/btnnextNA.gif":this.config.coreImgHost+"buttons/btnnext.gif";
	this.paginationDown.style.cursor=(this.sliderDown.disabled)?"default":"pointer";
	this.sliderTop=-this.images[scrollIndex*3].offsetTop;
};

SuperGallery.prototype.dialogHandlers=function()
{this.oDivThumbObj=new Array();for(var i=0;i<this.gallery.nImgs;i++){var divId="divThumb"+i;this.oDivThumbObj[i]=new EbayHTMLLayer(this,divId);this.oDivThumbObj[i].thumbClick=function()
{if(this.selectedThumb!=this.parent.selected){this.parent.setBigImgTxt(this.parent.config.loading);var id=this.selectedThumb+1;var selThumbDiv=document.getElementById("divThumb"+this.selectedThumb);var prevSelThumbDiv=document.getElementById("divThumb"+this.parent.selected);selThumbDiv.className="outerThumbDiv selected";prevSelThumbDiv.className="outerThumbDiv";this.parent.selected=this.selectedThumb;var imgId=document.getElementById("imgBig");if(this.parent.bigImages[this.selectedThumb]==null)
{var bigImageUrl=this.parent.config.host+this.parent.gallery.id+"_"+id+"_"+this.parent.gallery.version+"_1.jpg";imgId.onload=this.parent.onBigImgload;imgId.onerror=this.parent.onBigImgloadError;imgId.onabort=this.parent.onBigImgloadError;imgId.src=bigImageUrl;}
else
{imgId.src=this.parent.bigImages[this.selectedThumb]
this.parent.onBigImgload();}
return false;}}
this.oDivThumbObj[i].subscribeEvents("onclick");this.oDivThumbObj[i]._registerEvent("onclick","thumbClick");this.oDivThumbObj[i].selectedThumb=i;this.oDivThumbObj[i].bind();}};SuperGallery.prototype.setBigImgTxt=function(text){var bImgDiv=document.getElementById("bImgDiv");bImgDiv.style.display="none";var imgId=document.getElementById("imgBig");imgId.style.width="";imgId.style.height="";var bImgTxt=document.getElementById("bImgTxt");bImgTxt.innerHTML=text;bImgTxt.style.display="block";};

SuperGallery.prototype.onBigImgload=function()
{
	var bImgTxt=document.getElementById("bImgTxt");
	var bImgDiv=document.getElementById("bImgDiv");
	var bImg=document.getElementById("imgBig");

	var control=ebay.oDocument._getControl("SuperGallery");
	if(control.gallery.isSuperSz==1)
	{
		bImgDiv.className="hiddenimg";
		bImgTxt.style.display="block";
		bImgDiv.style.display="block";
		control.bTimer=window.setTimeout(control.onimgload,100);
	}
	else
	{
		bImgTxt.style.display="none";
		bImgDiv.style.display="block";
		if(this.selected==0)
		this.onLoadDone();
	}
};

SuperGallery.prototype.shrinknShowSSImage=function(){window.clearTimeout(this.bTimer);var bImgTxt=document.getElementById("bImgTxt");var bImgDiv=document.getElementById("bImgDiv");var bImg=document.getElementById("imgBig");var imgW=bImg.width;var imgH=bImg.height;var scale=1.0;if((imgW>=imgH)&&(imgW>400))
scale=400/imgW;else if((imgH>400)&&(imgH>=imgW))
scale=400/imgH;bImg.style.width=window.toPixels(scale*imgW);bImg.style.height=window.toPixels(scale*imgH);bImgDiv.className="imgvisible";bImgTxt.style.display="none";bImgDiv.style.display="block";if(this.selected==0)
this.onLoadDone();}
SuperGallery.prototype.onBigImgloadError=function(){var bImgTxt=document.getElementById("bImgTxt");var bImgDiv=document.getElementById("bImgDiv");bImgTxt.innerHTML="Error loading the image";bImgTxt.style.display="none";bImgDiv.style.display="block";};

SuperGallery.prototype.showViewItem=function(){

//alert (this.parent.gallery.vItemlnk)


if (this.parent.gallery.vItemlnk)
{
	window.open(this.parent.gallery.vItemlnk, 'blowup', 'toolbar=no,location=yes,directories=yes,status=no,scrollbars=yes,resizable=yes,width="300",height="300",copyhistory=no');
}	


//document.location.href=this.parent.gallery.vItemlnk;

};

SuperGallery.prototype.getThumbLayerContent=function()
{
var outPut="";
var id=0;
var thumbImg;
for(var i=0;i<this.gallery.nImgs;i++){
	id=i+1;
	thumbImg=this.config.host+this.gallery.id+"_"+id+"_"+this.gallery.version+"_0.jpg";
	
	outPut=outPut+"<div class='outerThumbDiv' name='divThumb"+i+"' id='divThumb"+i+"' ><div class='thumbnail' ><img src='"+thumbImg+"' id='imgThumb"+i+"' name='imgThumb"+i+"'"+"onload='onSuperGalleryThumb("+i+");'"+" /></div><div class='pLayer' id='progressLyr"+i+"'></div></div>";
	}
	
return outPut;
};

SuperGallery.prototype.onSlideNext=function(event){var i=Math.min(((this.scrollIndex)+4),(Math.max(this.gallery.nImgs-4,0)));this.scrollEnable(i);window.setTimeout(this.onscrolldown,this.config.timer);};SuperGallery.prototype.onScrollDown=function(){this.slider.style.top=window.toPixels(Math.max(this.slider.offsetTop-this.config.pixels,this.sliderTop));if((this.slider.offsetTop-this.sliderTop)>this.config.pixels)window.setTimeout(this.onscrolldown,this.config.timer);else this.slider.style.top=window.toPixels(this.sliderTop);};SuperGallery.prototype.onSlidePrev=function(){this.scrollEnable(Math.max(this.scrollIndex-4,0));window.setTimeout(this.onscrollup,this.config.timer);};SuperGallery.prototype.onScrollUp=function(){this.slider.style.top=window.toPixels(Math.min(this.slider.offsetTop+this.config.pixels,this.sliderTop));if((this.sliderTop-this.slider.offsetTop)>this.config.pixels)window.setTimeout(this.onscrollup,this.config.timer);else this.slider.style.top=window.toPixels(this.sliderTop);};

function onSlidePrev(event){
var control=ebay.oDocument._getControl("SuperGallery");
return(control)?control.onSlidePrev(event):false;
};

function onSlideNext(event){
var control=ebay.oDocument._getControl("SuperGallery");
return(control)?control.onSlideNext(event):false;
};


//function onGalleryPlus(event,itemId,nImgs,isSuperSz,version,enableThumbs,vItemlnk)
function onGalleryPlus(event,itemId, iHeight, iWidth)
{

//var img_path = itemId.split(".(.*?)/");

var iHeight = iHeight;
var iWidth = iWidth;

myImage = new Image();
myImage.src = itemId;
var myheight = myImage.height;
var mywidth  = myImage.width;

var img_path = itemId.replace('http://','');
img_path = img_path.split(/\//);

var img_host  = 'http://'+img_path[0];

var img_url = '';
for(i=1; i < img_path.length; i++)
{
	img_url = img_url+'/'+img_path[i]; 
}	
	
/*
img_path[0] = img_path[0]+'.com';
img_path[1] = '/'+img_path[1];*/

//alert (itemId) get image size and do next step

var vItemlnk = '';
document.getElementById('imgBig').style.cursor ='default';

if ((myheight > 500) || (mywidth >500))
{
	vItemlnk = itemId;
	document.getElementById('imgBig').style.cursor ='pointer';
}	


var oSurvey=ebay.oDocument.oPage._getControl("KeyFlow.Exit.Survey");
if(oSurvey)
oSurvey.disable();
event.cancelBubble=true;
var control=ebay.oDocument._getControl("SuperGallery");
if((control==null)||(control.dialog.active))
return false;
var link=DHTMLEvent.currentTarget(event);
while(link&&(link.onmouseover==null))
link=link.parentNode;
if(link==null)
return false;
if(link.active)return false;
var control=ebay.oDocument._getControl("SuperGallery");
if(control==null)return false;

control.config.host = img_host; 

//alert (vItemlnk +' Amit Pratap')
var nImgs = 1;
var version =0;	
var gallery=new Array();
gallery.id=img_url;
gallery.nImgs=1;
gallery.isSuperSz='';
gallery.enableThumbs='false';
gallery.version=0;

gallery.iHeight =iHeight;
gallery.iWidth =iWidth;
 

if(version=="")gallery.version=1;

if(gallery.version>500)gallery.nImgs=parseInt(nImgs)+1;

gallery.vItemlnk=vItemlnk;

if(link.className=="galleryplus")
control.setDelay(event,link,gallery,(link.height/2),(link.width/2));
else
control.setDelay(event,link,gallery,5,10);return false;
};


function onSuperGalleryThumb(idx){var image=document.getElementById("imgThumb"+idx);if(image==null)return;if((image.width>64)&&(image.width>=image.height))image.width=(64/image.width)*image.width;else if((image.height>64)&&(image.height>=image.width))image.height=(64/image.height)*image.height;image.onload=null;image.style.position="relative";image.style.top=window.toPixels(Math.floor((64-image.height)/2));image.style.left=window.toPixels(Math.floor((64-image.width)/2));};var cfg=ebay.oDocument.getConfig("SuperGallery");if(document.compatMode=="BackCompat"){if(ebay.oGlobals.oClient.bIE)
cfg.isIEQuirksMode=true;else if(ebay.oGlobals.oClient.bFirefox)
cfg.isFirefoxQuirksMode=true;}
if(cfg)new SuperGallery(ebay.oDocument.oPage,cfg);



function img_resize (iHeight,iWidth)
{

	//alert ('test' + iHeight+','+iWidth)
	var myheight = iHeight;
	var mywidth  = iWidth;
	
	var _dheight = 500;
	var _dwidth = 500;

	if(myheight > _dheight || mywidth > _dwidth)
	{
		if(myheight > mywidth)
		{
			var temp = myheight/_dheight;

			var new_width = mywidth / temp;
			new_width = parseInt(new_width);

			myheight = _dheight;
			mywidth = new_width;
		}
		else
		{
			var temp = mywidth/_dwidth;

			var new_height = myheight / temp;
			new_height = parseInt(new_height);

			myheight = new_height;
			mywidth = _dwidth;
		}
	}

	return (myheight+'_'+mywidth);
}
