// JavaScript Document

vjo.ctype('vjo.dailydeal.RightNav') //< public
.props({
	 
    //> public void selectDeal(String pLeftItemId,String pRightItemId,String pImageId,String pClassBGSel)
    selectDeal : function (pLeftItemId,pRightItemId,pImageId,pClassBGSel)
    {	
    	this.gSelectedItemId = pLeftItemId;
    	this.gSelectedImageId = pImageId;
    	
    	leftElem  = vjo.dsf.document.Element.get(pLeftItemId);
    	rightElem  = vjo.dsf.document.Element.get(pRightItemId);
    	
    	var re = rightElem.parentNode;
    	for(i=0;i<re.childNodes.length;i++){
    		re.childNodes[i].childNodes[0].className = "background_img_default";
    	}
    	rightElem.childNodes[0].className = pClassBGSel;
    	
    	var le = leftElem.parentNode;
    	for(j=0;j<le.childNodes.length;j++){
    		le.childNodes[j].style.display = "none";
    	}
    	
    	leftElem.style.display = "block";
    /*	
      	var img = vjo.dsf.document.Element.get(pImageId);
      	var calculatedRation ;
     	if(img.height>300 ||img.width>300)
      	{
      	
    		if(img.height>img.width)
    		{
    		 	var imagewidth=img.width;
      			calculatedRation = (300/img.height)*100;
     			img.height = 300;
     			img.width = (calculatedRation*imagewidth)/100;
		     }
        	else
     		{
     		 	 var imageHeight=img.height;
     			 calculatedRation = (300/img.width)*100;
      			 img.width = 300;
      			 img.height = (calculatedRation*imageHeight)/100;
            }
      	}  
      	*/
   
    },
 
     //> public void mouseover(String pLeftItemId, String pImageId, String pItemId, String cssName)   
     mouseover : function(pLeftItemId,pImageId,pItemId,cssName){
	 	var item = vjo.dsf.document.Element.get(pItemId);
	 	if(item){
        	if(item.className!=="background_img_sel" && item.className!=="motor_background_img_sel"){
        		item.className = cssName ;
        	}
        		
        	this.switchimage(pLeftItemId, pImageId);
        	
        }
        		
      },
 
    //> public void switchimage(String pLeftItemId,String pImageId) 
     switchimage : function(pLeftItemId,pImageId){
    	leftElem  = vjo.dsf.document.Element.get(pLeftItemId);
    	var le = leftElem.parentNode;
    	for(j=0;j<le.childNodes.length;j++){
    		le.childNodes[j].style.display = "none";
    	}
    	leftElem.style.display = "block";
      	var img = vjo.dsf.document.Element.get(pImageId);
      	var calculatedRation ;
     	if(img.height>300 ||img.width>300)
      	{
    		if(img.height>img.width)
    		{
    		 	var imagewidth=img.width;
      			calculatedRation = (300/img.height)*100;
     			img.height = 300;
     			img.width = (calculatedRation*imagewidth)/100;
		     }
        	else
     		{
     		 	 var imageHeight=img.height;
     			 calculatedRation = (300/img.width)*100;
      			 img.width = 300;
      			 img.height = (calculatedRation*imageHeight)/100;
            }
      	}  
        		
      },
      
      //> public void  restore()
      restore : function(){
      	this.switchimage(this.gSelectedItemId,this.gSelectedImageId);
      },
 
     //> public void mouseout(String pItemId,String cssName)  
     mouseout : function(pItemId,cssName){
     
	 	var item = vjo.dsf.document.Element.get(pItemId);
	 	if(item){
 
	 		if(item.className==="background_img_sel" || item.className==="motor_background_img_sel"){
	 		   return;
	 		} else{
        	   item.className = cssName ;
	 		}
        }
      },
      
      isMouseLeaveOrEnter : function (pItemId) {
      	 /*
      	 var handler = vjo.Registry.get(pItemId);
      	 var e = window.event;
      	 if (e.type != 'mouseout' && e.type != 'mouseover') return false; 
      	 var reltg = e.relatedTarget ? e.relatedTarget : e.type == 'mouseout' ? e.toElement : e.fromElement; 
      	 while (reltg && reltg != handler) reltg = reltg.parentNode; 
      	 return (reltg != handler);
      	 */ 
      },
 
     //> public void changeStyle(String pImageId,int pValue) 
     changeStyle : function(pImageId,pValue){
     	var ie = (document.all) ? 1 : 0;
		var p = (ie) ? "filter" : "MozOpacity";
	 	 pValue = (ie) ? "alpha(opacity="+pValue+")" : pValue/100;
	 	 img = vjo.dsf.document.Element.get(pImageId);
   		 img.style[p] = pValue;
      },
   
   //> public void activateDeal(java.util.List pDealIds,java.util.List pImageIds, String cssName) 
   activateDeal : function(pDealIds, pImageIds, cssName) {
		this.gSelectedImageId = pImageIds[0];
		this.gSelectedItemId = "itemDiv_Id" + 0;
   		var dealId;
		var path;
   		if (window.location !== undefined && window.location.pathname !== undefined) {
    		path = window.location.pathname;
    	}
    	
    	if (path !== undefined && path !== "") {
			if (path.search(/(0-9)+/)) {
				var number = path.match(/\d+/);
				if (number !== undefined && number !== "") {
					dealId = number;
				}
			}
		}
		
		if (dealId !== undefined) {
			for(i=0; i<pDealIds.length; i++) {
				if (pDealIds[i] == dealId) {
					this.gSelectedItemId = "itemDiv_Id" + i;
					this.gSelectedImageId = pImageIds[i];
					this.selectDeal("itemDiv_Id" + i, "itemId_" + i, pImageIds[i], cssName);
					return;
				}
			}
		}
   }
    
 
})
.endType();
 
/* wiki link : http://wiki.arch.ebay.com/index.php?page=V4_Yoda_VJO_UPREV */ 
vjo.ctype('vjo.dailydeal.DailyDeal') //< public
.props({
  	 //> public void hideShowDailyDeal(String toggleImgId,String rcpId)
	  hideShowDailyDeal : function(toggleImgId,rcpId){
	 	var divC =  vjo.dsf.document.Element.get(rcpId+"_c");
	 	var img =  vjo.dsf.document.Element.get(toggleImgId);
	 	var divB = vjo.dsf.document.Element.get(rcpId+"_b");
	 	
	 	if (navigator.userAgent.indexOf('Firefox/2.0') != -1) {
	 		if (divC && (divC.style.display == 'block' || divC.style.display == 'table-cell')) {
	 			divC.style.display = 'none';
	 			img.className = 'minMax_c_img';
	 		} else {
	 			divC.style.display = 'table-cell';
	 			img.className = 'minMax_o_img';
	 		}
	 	}
	 	else{
	 		if (divC && divC.style.display == 'block') {
	 			divC.style.display = 'none';
	 			img.className = 'minMax_c_img';
	 		} 
			else {
	 			divC.style.display = 'block';
	 			img.className = 'minMax_o_img';
	 		}
	 	}
	 	if (divB && divB.style.visibility == 'visible') {
	 		divB.style.visibility = 'hidden';
	 	}
	 	else{
	 		divB.style.visibility = 'visible';
	 	}
	 },	 
 
    //> public void hideShowDailyDeal(java.util.List pImageIds,int listSize)
     resizeImage : function(pImageIds, listSize){
     var calculatedRation ;
     for(i=0; i<listSize; i++){
      var img = vjo.dsf.document.Element.get(pImageIds[i]);
      if(img.height>300 ||img.width>300)
      {
      	
    	 if(img.height>img.width)
    		 {
    		 	var imagewidth=img.width;
      			calculatedRation = (300/img.height)*100;
     			img.height = 300;
     			img.width = (calculatedRation*imagewidth)/100;
		      }
       else
     		 {
     		 	 var imageHeight=img.height;
     			 calculatedRation = (300/img.width)*100;
      			 img.width = 300;
      			 img.height = (calculatedRation*imageHeight)/100;
             }
      }
    }
   },
   
   //> public void setBwsrSpficImg(com.ebay.ebox.deals.common.BrowserSpecificImageModel model)
  	 setBwsrSpficImg: function(model){
   		var isIE6 = -1;
   		var imgS = new Image();
   		var parentDiv = document.getElementById(model.parentDivId);
   		imgS.className = model.htmlClass;
   		if(navigator.userAgent!=null){
   			isIE6 = navigator.userAgent.indexOf('MSIE 6.0');
   			}
   		if(isIE6==-1){
   			imgS.src = model.imgRest;
   		}
   		else{
   			imgS.src = model.imgIE6;
   			imgS.style.filter = "alpha(opacity=50)";
   		}
   		parentDiv.appendChild(imgS);
    },
    
     //>public void bookmark()
    bookmark: function(){
	    var url = window.location.href;
	    var title = document.title;
	  	if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
	  		window.external.AddFavorite(url,title);
	  	} else if (navigator.appName == "Netscape") {
	   		 window.sidebar.addPanel(title,url);
	  	} else {
	   		 alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
	  	}
    }
})
.endType();
/* wiki link : http://wiki.arch.ebay.com/index.php?page=V4_Yoda_VJO_UPREV */ 
vjo.ctype('vjo.dailydeal.DealTracking') //< public
.props({
 
  //> public void trackPageHits(long pageId, long itemId, long dealId, String allDealIds)
	 trackPageHits:function(pageId, itemId, dealId, allDealIds) {
		// Page Impression
		
		//var guid = document.getElementById("hidGuid").value;
		var userId = document.getElementById("hidUserid").value;
		var previousUrl = document.getElementById("hidPrevUrl").value;
 
		var impEvt=_rover.createPageImpEvent(pageId);
		if(userId!=null && userId!="")	
			impEvt.getTrackData().addNvp("userid", userId);
		
		if(guid!=0)
			impEvt.getTrackData().addNvp("guid", guid);
		
		if(previousUrl!=null && previousUrl!="")	
			impEvt.getTrackData().addNvp("refer_page_url", previousUrl);
		
		if(itemId !=0)
			impEvt.getTrackData().addNvp("itemid", itemId);
			
		if(dealId!=0)
			impEvt.getTrackData().addNvp("ddi", dealId);
			
		if(allDealIds!=null && allDealIds!="")
			impEvt.getTrackData().addNvp("addi", allDealIds);
		_rover.track();
	},	  
 
	// onClick of your link Clicks for each button on the page
	//> public void trackClick(long pageId, int clickId, long itemId, long dealId)
	trackClick:function(pageId, clickId, itemId, dealId) {
   //     var clkEvt = _rover.createClickEvent(pageId+'.l'+clickId);
        //clkEvt.getTrackData().addNvp("itemid", itemId);
        //clkEvt.getTrackData().addNvp("ddi", dealId);
        //clkEvt.track();
	},
 
	 //> public void trackClkThru(long pageId, long itemId, String viewItemUrl)
	trackClkThru:function(pageId, itemId, viewItemUrl) {
        var clkThruEvt = _rover.createClickThruEvent(pageId);
        clkThruEvt.getTrackData().addNvp("itemid", itemId);
        clkThruEvt.setLoc(viewItemUrl);
        clkThruEvt.track();
	}
 
})
.endType();
//@Package vjo.dsf.typeextensions.string
 
String.prototype.has = function (pStr) { 
	return (this.indexOf(pStr) != -1); 
};
 
String.prototype.hasArg = function (pArg) {
	var a = pArg, rv = false;
	if (typeof(a) == "string")
	{
		rv = this.has(a);
	}
	else{
		var aL = a.length;
		for (var j=0; j<aL && !rv; j++)
		{
			rv = this.has(a[j]);
		}
	}
	return rv;
};
 
String.prototype.hasAny = function () {
	var a = arguments, l = a.length, rv = false;
	for (var i=0; i<l && !rv; i++)
	{
		rv = this.hasArg(a[i]);
	}
	return rv;
};
 
String.prototype.hasAll = function () {
	var a = arguments, l = a.length;
	for (var i=0; i<l; i++)
	{
		if (!this.hasArg(a[i]))
		{
			return false;
		}
	}
	return true;
};
 
String.prototype.is = function (s) { 
	return (this == s); 
};
 
String.prototype.isAny = function () {
	var a = arguments, l = a.length, rv = false, aL;
	for (var i=0; i<l && !rv; i++)
	{
		if (typeof(a[i]) == "string")
		{
			rv = (this == a[i]);
		}
		else
		{
			//It's an array (of strings)
			aL = a[i].length;
			for (var j=0; j<aL && !rv; j++)
			{
				rv = (this == a[i][j]);
			}
		}
	}
	return rv;
};
vjo.needs("vjo.dsf.typeextensions.string.Comparison");
 
vjo.ctype("vjo.dsf.client.Browser")
.props({
	init : function() {		
		this.bFirefox = this.bWebTV = this.bOpera = this.bNav = this.bIE = this.bSafari =
		this.bWin = this.bMac = this.bMacppc = this.bMactel =
		this.bActiveXSupported = this.bWinXp = this.bXpSp2 = this.bAOL = this.bVista = false;
		this.iVer = this.fVer = -1;
	    this.fMinorVer = 0;
	    this.aMimeTypes = null;
		
		var nv = navigator, agt = nv.userAgent.toLowerCase(), i = 0, ver;
	
		with (this){
			if (agt.has("webtv"))
			{
				bWebTV = true;
				i = agt.indexOf("webtv/") + 6;
			}
			else if (agt.has("firefox"))
			{
				bFirefox = true;
				i = agt.lastIndexOf("firefox") + 8;
			}
			else if (agt.has("safari"))
			{
				bSafari = true;
				i = agt.lastIndexOf("safari") + 7;
			}
			else if(typeof(window.opera)!="undefined")
			{
				bOpera = true;
				i = agt.lastIndexOf("opera") + 6;
			}
			else if (nv.appName.is("Netscape"))
			{
				bNav = true;
				i = agt.lastIndexOf("/") + 1;
			}
			else if (agt.has("msie"))
			{
				bIE = true;
				i = agt.indexOf("msie") + 4;
				if (agt.has('aol') || agt.has('america online'))
					bAOL = true;
			}
			ver = bOpera?window.opera.version():agt.substring(i);
			//ver = agt.substring(i);
			iVer = parseInt(ver);
			fVer = parseFloat(ver);
	           fMinorVer = fVer - iVer;
	
			//Operating system detection
			bWin = agt.has("win");
			bWinXp = (bWin && agt.has("windows nt 5.1"));
			bVista = (bWin && agt.has("windows nt 6.0"));
			bXpSp2 = (bWinXp && agt.has("sv1"));
			bMac = agt.has("mac");
			bMacppc = (bMac && agt.hasAny("ppc","powerpc"));
			bMactel = (bMac && agt.has("intel")); 
			
			aMimeTypes = nv.mimeTypes;
	   
			//ActiveX support
			bActiveXSupported =	(!(bMac || bMacppc) && (typeof(ActiveXObject) == 'function'));
		}	         
	}
})
.inits(function () {
	vjo.dsf.client.Browser.init();
})
.endType();	
vjo.needs("vjo.dsf.Element");
vjo.needs("vjo.dsf.client.Browser");
vjo.ctype("vjo.dsf.document.Element")
.inherits("vjo.dsf.Element")
.props({ //functionality moved to vjo.dsf.Element
	//> public void toggleHideShowRow(String,Boolean);
	toggleHideShowRow : function(psId, pbDisplay) {
		var e = this.get(psId), s, d, u = "undefined";
		var p = vjo.dsf.client.Browser.bFirefox?"table-row":"block";
		if (e)
		{
			s = e.style;
			d = s.display;
			if (typeof(pbDisplay)===u)
			{
				pbDisplay = (d === "" || d === p) ? false : true;
			}
			e.bIsShown = pbDisplay;
			s.display = (pbDisplay) ? p : "none";
		}	
	}
})
.endType();
 
 
 
 
vjo.needs("vjo.dsf.Message");
vjo.needs("vjo.dsf.document.Element");
vjo.type("vjo.darwin.core.roundedcornerpanel3.VjRoundedCornerPanel3SvcHandler")
.protos({
 
	/**
	 * @return Void
	 * @access public
	 * @param {String} psId
	 *
	*/
	constructs: function (psId) {
          this.sRoundedCornerPanel3JsCompId = psId;
    },
    
    /**
     * @return Void
	 * @access public
     * @param {vjo.dsf.MessageJsr} message
	*/
	invoke: function(message){
		var _e = vjo.dsf.document.Element;
		if( message.changeType === "HEADER_CHANGE" ) {
			var top = _e.get(message.sElemId + "_t");
			var head = _e.get(message.sElemId + "_h");
			
			head.className = message.cssClz;
			if(top){
				top.className = message.cssClz;
				}
			this.setBorderToAnchor(message.sElemId,message.cssClz);
			
		}else if( message.changeType === "FOOTER_CHANGE" ) {
			var foot = _e.get(message.sElemId + "_f");
			var bottom = _e.get(message.sElemId + "_b");
			var bClsName ;
			
			foot.className =message.cssClz;
		   if(bottom){
		   		 bClsName = bottom.className;
				if(bClsName.indexOf('c-sgf') > -1){
					bottom.className = message.cssClz;
				}else{
					bottom.className = bClsName+" "+message.cssClz;
				}
			}
		}else if( message.changeType === "SHOW_HIDE_CONTENT" ) {
			
			var obj = _e.get(message.sElemId + "_c");
			var tab = _e.get(message.sElemId );
			var clsName = tab.className;		
			if (obj.style.display=='none')
			{
				obj.style.display='';
				
				if (clsName.indexOf('c-sgfx') > -1)
				{
					clsName = clsName.replace('c-sgfx','');
				}				
			} else {
				obj.style.display = "none";
				clsName += " c-sgfx" ;
			}
			tab.className = clsName;
		}
		
	},
    
    /**
     * @return Void
	 * @access public
     * @param {String} psElemId
     * @param {String} psCssClass
	*/
	setBorderToAnchor : function(psElemId,psCssClass){
		var _e = vjo.dsf.document.Element;
		var ancGR = _e.get(psElemId + "_c-gr");
		var ancBL = _e.get(psElemId + "_c-bl");
		var ancRD = _e.get(psElemId + "_c-rd");
		var ancYL = _e.get(psElemId + "_c-yl");
		var ancGY = _e.get(psElemId + "_c-gy");
		
		if(ancGR !== null ){
			if(psCssClass === "c-gr"){
				ancGR.className="r3-gr-bdr";
			}else{
				ancGR.className="";
			}
		}
		if(ancBL !== null ){
			if(psCssClass === "c-bl"){
				ancBL.className="r3-bl-bdr";
			}else{
				ancBL.className="";
			}
		}
		if(ancRD !== null ){
			if(psCssClass === "c-rd"){
				ancRD.className="r3-rd-bdr";
			}else{
				ancRD.className="";
			}
		}
		if(ancYL !== null ){
			if(psCssClass === "c-yl"){
				ancYL.className="r3-yl-bdr";
			}else{
				ancYL.className="";

			}
		}
		if(ancGY !== null ){
			if(psCssClass === "c-gy"){
				ancGY.className="r3-gy-bdr";
			}else{
				ancGY.className="";
			}
		}
		
	}
});
vjo.ctype("vjo.dsf.document.Positioning")
.props({
	getScrollLeftTop : function() {
		var d = document, rv = [0,0], db = d.body, de = d.documentElement;
		if (db) 
		{
			rv[0] += db.scrollLeft;
			rv[1] += db.scrollTop;
		}
		if (de) 
		{
			//using xhtml1-transitional.dtd de scrolltop needs to be appended
			rv[0] += de.scrollLeft;
			rv[1] += de.scrollTop;
		}
	   return rv;
	},
	
	getOffsetLeft : function(poElem) {
		var e = poElem, l = 0;
		while (e)
		{
			l += e.offsetLeft;
			e = e.offsetParent;
		}
		return l;
	},
	
	getOffsetTop : function(poElem)	{
		var e = poElem, t = 0;
		while (e)
		{
			t += e.offsetTop;
			e = e.offsetParent;
		}
		return t;
	},
	
	getClientWidth : function()	{
		var s = self, d = document, de =  d.documentElement, w;
		if (s.innerWidth)
		{
		    w = s.innerWidth;
		}
		else if (de && de.clientWidth)
		{
		    w = de.clientWidth;
		}
		else
		{
			w = d.body.clientWidth;
		}
		return w;
	},
	
	getClientHeight : function() {
		var s = self, d = document, de =  d.documentElement, h;
		if (s.innerHeight)
		{
		    h = s.innerHeight;
		}
		else if (de && de.clientHeight)
		{
		    h = de.clientHeight;
		}
		else
		{
			h = d.body.clientHeight;
		}
		return h;
	},
	
	getEventLeftTop : function(poEvent)	{
		 //Height offset isn't exact in non-IE.  It doesn't accomodate for toolbars and
		 //status bar.  Must be calculated by outer and inner height, minus a fixed height
		 //for status bar
		 var u = "undefined", evt = window.event || poEvent,
	     xOff = (typeof(screenLeft) != u) ? screenLeft : screenX,
	     yOff = (typeof(screenTop) != u) ? screenTop : (screenY + (outerHeight - innerHeight) - 25);
	
		 return [evt.screenX - xOff,evt.screenY - yOff];
	}
})
.endType();
 
vjo.needs("vjo.dsf.client.Browser");
 
vjo.ctype("vjo.dsf.document.Shim")
.props({
 
	add : function(poNode, piHPadding, piVPadding) {
		var f, p="px",w,h,s;
		if(this.check())
		{
			w = poNode.offsetWidth;
			h = poNode.offsetHeight;
			w += piHPadding?piHPadding:0; 
			h += piVPadding?piVPadding:0;
			f = document.createElement('IFRAME');
			s = f.style;
			s.width = w + p;
	    	s.height = h + p;
	    	s.filter = "chroma(color='white')";
	    	f.frameBorder= 0;
	    	s.position = "absolute";
	    	s.left = "0"+p;
	    	s.top = "0"+p;
	    	s.zIndex="-1";
	    	s.filter="Alpha(Opacity=\"0\")";
	    	if(document.location.protocol=="https:"){
	    		f.src = "https://securepics.ebaystatic.com/aw/pics/s.gif";
	    	}
			poNode.appendChild(f);
	    	return f;	
		}
	},
	
	remove : function(poDiv,poIframe) {
		if(this.check())
		{
			//if(poIframe && poIframe.parentElement)
			//{
			//	poDiv.removeChild(poIframe);
			//}		
			if(poIframe && poIframe.parentNode)
			{
				poIframe.parentNode.removeChild(poIframe);
			}
		}
	},
	
	check : function() {
		var B = vjo.dsf.client.Browser;
		return (B.bIE || B.bFirefox);
	}
})
.endType();
 
 
vjo.needs("vjo.dsf.EventDispatcher");
vjo.needs("vjo.dsf.Message");
vjo.needs("vjo.dsf.ServiceEngine");
vjo.ctype("vjo.dsf.utils.Handlers")
.props({
	
	ED : vjo.dsf.EventDispatcher,
 
	SE : vjo.dsf.ServiceEngine,
	
	attachEvt : function(target, type, func, scope){
		return this.ED.addEventListener(target, type, func, scope);
	},
	
	detachEvt : function(target, type, hdl){
		return this.ED.removeEventListener(target, type, hdl);
	},
	
	newMsg : function(svcName){
		return new vjo.dsf.Message(svcName);
	},
	
	handle : function(msg){
		this.SE.handleRequest(msg);
	},
	
	createHdl : function(scope, func, name){
		var scp = scope,
			hdl = {};
		hdl[name] = function(){func.apply(scp, arguments);};
		return hdl;
	},
	
	attachSvc : function(svcName, func, scope){
		var t = this,
			hdl = t.createHdl(scope, func, 'invoke');
		if(t.SE && hdl){
			t.SE.registerSvcHdl(svcName, hdl);
		}		
	},
	
	attachSvcReqt : function(svcName, func, scope){
		var t = this,
			hdl = t.createHdl(scope, func, 'handleRequest');
		if(t.SE && hdl){
			t.SE.registerSvcReqtHdl(svcName, hdl);
		}		
	},
	
	attachSvcResp : function(svcName, func, scope){
		var t = this,
			hdl = t.createHdl(scope, func, 'handleResponse');
		if(t.SE && hdl){
			t.SE.registerSvcRespHdl(svcName, hdl);
		}		
	},
	
	resetSvc : function(svcName){
		this.SE.inProcHdl.svcHdls[svcName] = [];
	},
	
	resetSvcReqt : function(svcName){
		this.SE.svcReqtHdls[svcName] = [];
	},
	
	resetSvcResp : function(svcName){
		this.SE.svcRespHdls[svcName] = [];
	}
	
})
.endType();
 
vjo.ctype("vjo.dsf.utils.Object").
props({
 
	//> public JsObj hitch(JsObj,String);
	hitch : function(poControl, psMethod) {
		var fcn;
		if(typeof psMethod == "string")
		{
			fcn = poControl[psMethod];
		} else
		{
			fcn = psMethod;
		}
		return function(){return fcn.apply(poControl, arguments);};
	},
	
	//>public JsObj extend(String,String);
	extend : function(psSubClass, psBaseClass) {
	   function inheritance() {}
	   inheritance.prototype = psBaseClass.prototype;
	
	   psSubClass.prototype = new inheritance();
	   psSubClass.prototype.constructor = psSubClass;
	   psSubClass.baseConstructor = psBaseClass;
	   psSubClass.superClass = psBaseClass.prototype;
	}
})
 
 
vjo.needs("vjo.dsf.utils.Object");
 
vjo.ctype("vjo.dsf.utils.Timer")
.protos({
	timer : null,
	isRunning : false,
	interval : null,
 
	onTick : function(){},
	onStart : null,
	onStop : null,
	
	constructs : function(intvl) {
		this.interval = intvl;
	},
 
	setInterval : function(ms) {
			var t = this;
			if (t.isRunning){
				window.clearInterval(timer);
			}
			t.interval = ms;
			// TODO -- adapt hitch function .. think ej2 has utility for this as well
			if(t.isRunning){
				t.setInt();
				//t.timer = window.setInterval(vjo.dsf.utils.Object.hitch(t, "onTick"), t.interval);
			}
			//if (t.isRunning) timer = window.setInterval(dojo.lang.hitch(t, "onTick"), t.interval);
	},
	
	start : function() {
			var t = this;
			if (typeof t.onStart == "function"){
			 t.onStart();
			}
			t.isRunning = true;
			t.setInt();
			//t.timer = window.setInterval(vjo.dsf.utils.Object.hitch(t, "onTick"), t.interval);
	},
	
	stop : function(){
			var t = this;
			if (typeof t.onStop == "function"){
				t.onStop();
			}
			t.isRunning = false;
			window.clearInterval(t.timer);
	},
	
	setInt : function(){
		var t = this;
		t.timer = window.setInterval(vjo.dsf.utils.Object.hitch(t, "onTick"), t.interval);
	}	
})
.endType();
 
 
vjo.ctype("vjo.dsf.window.utils.VjWindowUtils")
.props({
	getBrowserWindowHeight : function()	{
	    var s = self;
	    var d = document;
	    var de = d.documentElement;
	    if (s.innerHeight){
	    // all except Explorer
	        return s.innerHeight;
	    }else if (de && de.clientHeight){
	    // Explorer 6 Strict Mode
	        return de.clientHeight;
	    }
	    return d.body.clientHeight;
	},
	
	getBrowserWindowWidth : function() {
	    var s = self;
	    var d = document;
	    var de =  d.documentElement;
	    if (s.innerWidth){
	    // all except Explorer
	        return s.innerWidth;
	    }else if (de && de.clientWidth){
	    // Explorer 6 Strict Mode
	        return de.clientWidth;
	    }
	    return d.body.clientWidth;
	},
	
	getScrollXY : function() {
	  var scrOfX = 0, scrOfY = 0;
	  if( typeof( window.pageYOffset ) == 'number' ) {
	    //Netscape compliant
	    scrOfY = window.pageYOffset;
	    scrOfX = window.pageXOffset;
	  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
	    //DOM compliant
	    scrOfY = document.body.scrollTop;
	    scrOfX = document.body.scrollLeft;
	  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
	    //IE6 standards compliant mode
	    scrOfY = document.documentElement.scrollTop;
	    scrOfX = document.documentElement.scrollLeft;
	  }
	  return [ scrOfX, scrOfY ];
	},
	toPixels : function(number) { 
		return number + "px"; 
	},
 
	scrollTop : function() {
 
		if (window.pageYOffset != null) { return window.pageYOffset; }
 
		if (document.documentElement) { return Math.max(document.documentElement.scrollTop,document.body.scrollTop); }
		else { return document.body.scrollTop; }
 
	},
 
	scrollLeft : function() {
 
		if (window.pageXOffset != null) { return window.pageXOffset; }
 
		if (document.documentElement) { return Math.max(document.documentElement.scrollLeft,document.body.scrollLeft); }
		else { return document.body.scrollLeft; }
 
	},
 
	scrollWidth : function() {
		if (document.documentElement) { return document.documentElement.scrollWidth; }
		else { return Math.max(document.body.scrollWidth,document.body.offsetWidth); }
	},
 
	scrollHeight : function() {
		if (document.documentElement) { return document.documentElement.scrollHeight; }
		else { return Math.max(document.body.scrollHeight,document.body.offsetHeight); }
	},
 
	clientTop : function() {
		if (document.documentElement) { return document.documentElement.clientTop; }
		else { return document.body.clientTop; }
	},
	
	clientLeft : function() {
		if (document.documentElement) {  return document.documentElement.clientLeft; }
		else { return document.body.clientLeft; }
	},
	
	clientWidth : function() {
		var documentElement = document.documentElement;
		if (documentElement && 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; }
	},
 
	clientHeight : function() {
		var documentElement = document.documentElement;
		if (documentElement && 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; }
	},
 
	browserTop : function() {
		return (window.innerHeight)?window.screenY + (window.outerHeight - window.innerHeight):window.screenTop;
	},
 
	browserLeft : function() {
		return (window.innerWidth)?window.screenX + (window.outerWidth - window.innerWidth):window.screenLeft;
	},
 
	eventTop : function(event) {

 
		if (event.pageY != null) { return event.pageY; }
 
		if (document.documentElement) { return event.clientY + Math.max(document.documentElement.scrollTop,document.body.scrollTop); }
		else { return event.clientY + document.body.scrollTop; }
 
	},
 
	eventLeft : function(event) {
 
		if (event.pageX != null) { return event.pageX; }
 
		if (document.documentElement) { return event.clientX + Math.max(document.documentElement.scrollLeft,document.body.scrollLeft); }
		else { return event.clientX + document.body.scrollLeft; }
 
	},
 
	offsetTop : function(element) {
		var clientTop = (document.documentElement && document.documentElement.clientTop)?document.documentElement.clientTop:0;
		for (var offsetTop = 0;(element != null);element = element.offsetParent) { offsetTop += element.offsetTop; }
		return offsetTop + clientTop;
	},
	
	offsetLeft : function(element) {
		var clientLeft = (document.documentElement && document.documentElement.clientLeft)?document.documentElement.clientLeft:0;
		for (var offsetLeft = 0;(element != null);element = element.offsetParent) { offsetLeft += element.offsetLeft; }
		return offsetLeft + clientLeft;
	},
	
	//> public void openWindow(String,String,vjo.dsf.window.utils.JsWindowFeatures);
	openWindow : function(url,name,features) {
 
		var parameters = new Array();
 
		var WindowUtils = vjo.dsf.window.utils.VjWindowUtils;
 
		features.top = WindowUtils.browserTop() + Math.round((WindowUtils.clientHeight() - features.height)/2) + 25;
		features.left = WindowUtils.browserLeft() + Math.round((WindowUtils.clientWidth() - features.width)/2);
	
		for (var key in features) parameters.push(key.concat("=",features[key]));
		return window.open(url,name,parameters.join(","),true);
 
	}
 
})
.endType();
 
 
vjo.needs("vjo.dsf.utils.Timer");
vjo.needs("vjo.dsf.utils.Handlers");
vjo.type("vjo.darwin.core.overlaypanel.VjOverlayPanelController")
.singleton()
.protos({
    H : vjo.dsf.utils.Handlers,
    
    /**
	 * @return Void
	 * @access public
	*/
  	constructs : function(){
	  	var t = this,H = t.H;
	    t.aOlps = [];
	    t.sIsActivated = false;
	    H.attachEvt(window,'resize',t.initResize,t);
	    
	    //[BUGDB00548884] Optimiaztion in OverlayPanel
		var lazyInit = function(){
		    t.initCloseOnMouseOut(); //[e559] new timer for all closing on mouseout olps
		};
		window.setTimeout(lazyInit, 500);
		
	    t.openAtZIndex = 5000;   //[e559] moved from VjOverlayPanelEvtHandlers
    },
    
    /**
	 * @return Void
	 * @access public
	 * @param {com.ebay.darwin.component.core.overlaypanel.OverlayPanel} poOverlayPanel
	*/
    registerOverlayPanel : function( poOverlayPanel ){
    	var t = this;
        t.aOlps[t.aOlps.length] = poOverlayPanel;
    } ,
    
    /**
	 * @return Void
	 * @access public
	*/
    initCloseOnMouseOut : function(){
    	var t = this;
        t.oCloseTimer = new vjo.dsf.utils.Timer(100);
        var tCT= t.oCloseTimer;
        tCT.onTick = function(){
        	var i = 0, arr = t.aOlps, len = arr.length;
            while(i < len){
            	var olp = arr[i];
            	if(olp.bCloseOnMouseOut){
            		olp.tryCloseOnMouseOut();
            	}
              	i++;
            }
        };
        tCT.start();
    },
    
    //[e559] wrapping zIndex access into a function
    /**
	 * @return Long
	 * @access public
	*/
    zIndex : function(){
        var o = this.openAtZIndex;
    	o += 1;
    	return o;
    },
    
    /**
	 * @return Void
	 * @access public
	*/
    requireResize : function(){
        this.sIsActivated = true;
    },
    
    //added so that OverlayPanel could be re-rendered not bound to a window resize event
    //olpCmpId is optional, if given, the overlay with this id will be re-rendered only, otherwise, all registered overlay will be re-rendered
    
    /**
	 * @return Void
	 * @access public
	 * @param {String} olpCmpId
	*/
    forceResize : function(olpCmpId){
    	var t = this, i = 0;
    	for(; i < t.aOlps.length; i++){
    	    var tO = t.aOlps[i];
    		if(olpCmpId && tO.sOverlayDivId == olpCmpId){
	    	   tO.onResize();
	    	   break;
    		}
    		else{
    		   tO.onResize();
    		}
    	}
    },
    
    /**
	 * @return Void
	 * @access public
	*/
    initResize : function(){
    	var t = this,H=t.H;
        H.detachEvt(window,'resize',t.initResize);
        H.attachEvt(window,'resize',t.requireResize, t);
        t.requireResize();
        t.oResizeTimer = new vjo.dsf.utils.Timer();
        var tRT=t.oResizeTimer;
        tRT.interval = 500;
        tRT.onTick = function(){
        var bA=t.sIsActivated;
           if (bA){
              for(var i=0 ; i<t.aOlps.length ; i++){
                var tO=t.aOlps[i];
                if(tO.bAdjustSize && tO.bPanelOpen){
                   tO.onResize();
                }
              }
              bA = false;
           }
        };
        tRT.start();
    },
    
    /**
	 * @return Void
	 * @access public
	*/
    resizeOlps : function(){
    	var i = 0,
    		t = this;
        for (; i<t.aOlps.length; i++){
          var tO=t.aOlps[i];
           if(tO.bPanelOpen){
              tO.onResize();
           }
        }       
    }
})
.inits(function(){
 	vjo.darwin.core.overlaypanel.VjOverlayPanelController = new vjo.darwin.core.overlaypanel.VjOverlayPanelController();
});
vjo.needs("vjo.dsf.Message");
vjo.type("vjo.darwin.core.overlaypanel.VjOverlayPanelOpenSvcHandler")
.protos({
 
	/**
	 * @return Void
	 * @access public
	 * @param {String} psId
	 *
	*/
	constructs: function (psId) {
          this.sOverlayPanelJsCompId = psId;
    },
    
    /**
     * @return Void
	 * @access public
     * @param {com.ebay.dsf.resource.html.event.handler.JsHandlerObjectEnum} message
	*/
	invoke: function(message){
		var panel = vjo.Registry.get(this.sOverlayPanelJsCompId),
		   mO = message.bOver,
		   LS = message.leftOffset,
		   TS = message.topOffset,
		   mL = message.left,
		   mT = message.top,
		   pAC = panel.aAnchorCoor;
		panel.fSetNotchLocation = message.fSetNotchLocation;
		panel.oSetNotchLocationOverrider = message.oSetNotchLocationOverrider;
		var como = true;
		if(typeof(mO)!="undefined"){
			como = mO;
		}
		panel.bCloseOnMouseOut = como;
		panel.setAnchorName(message.sAnchorId);
		//[e559] allowing message set with leftOffset, topOffset & initial position
		// the left/top offset will be effective till the panel get's closed
		panel.iTmpLftOfset = LS ? LS : 0;
		panel.iTmpTopOfset = TS ? TS : 0;
		pAC = (mL && mT) ? {x: mL, y: mT} : false;
		
		if(message.bResetPosition){
			panel.bPanelOpen = false;
		}
		panel.onOpenOverlayPanel(pAC || false);
		message.returnData = false;
		return message;
	}
});
vjo.needs("vjo.dsf.Message");
vjo.type("vjo.darwin.core.overlaypanel.VjOverlayPanelCloseSvcHandler")
.protos({
 
	/**
	 * @return Void
	 * @access public
	 * @param {String} psId
	 *
	*/
	constructs: function (psId) {
          this.sOverlayPanelJsCompId = psId;
    },
    
    /**
     * @return Void
	 * @access public
     * @param {com.ebay.dsf.resource.html.event.handler.JsHandlerObjectEnum} message
	*/
	invoke: function(message){
		var panel = vjo.Registry.get(this.sOverlayPanelJsCompId);
		panel.onClosePanel(message.getCheckState?message.getCheckState():false);
		return message;
	}
});
 
vjo.needs("vjo.dsf.client.Browser");
vjo.needs("vjo.dsf.document.Element");
vjo.needs("vjo.dsf.document.Positioning");
vjo.needs("vjo.dsf.document.Shim");
vjo.needs("vjo.dsf.utils.Handlers");
vjo.needs("vjo.dsf.Message");
vjo.needs("vjo.dsf.utils.Object");
vjo.needs("vjo.dsf.utils.Timer");
vjo.needs("vjo.dsf.window.utils.VjWindowUtils");
vjo.needs("vjo.darwin.core.overlaypanel.VjOverlayPanelController");
vjo.needs("vjo.darwin.core.overlaypanel.VjOverlayPanelOpenSvcHandler");
vjo.needs("vjo.darwin.core.overlaypanel.VjOverlayPanelCloseSvcHandler");
vjo.type("vjo.darwin.core.overlaypanel.VjOverlayPanel")
.inherits("vjo.dsf.utils.Timer")
.protos({
    //optimization for finding domain
	H : vjo.dsf.utils.Handlers,
	B : vjo.dsf.client.Browser,
	PC : vjo.darwin.core.overlaypanel.VjOverlayPanelController,
	E : vjo.dsf.document.Element,
	S : vjo.dsf.document.Shim,
	O : vjo.dsf.utils.Object,
	M : vjo.dsf.Message,
	P : vjo.dsf.document.Positioning,
	W : vjo.dsf.window.utils.VjWindowUtils,
	
    /**
	 * @return Void
	 * @access public
	 * @param {com.ebay.darwin.component.core.overlaypanel.OverlayPanelJsModel} overlayJsModel
	*/
	constructs: function(overlayJsModel){
		//[e559] naming shortened to reduce js weight
		var t = this,
		E = t.E;
		t.sOverlayDivId = overlayJsModel.overlayCompId;
		var sId = t.sOverlayDivId;
		t.sOlpId = overlayJsModel.cmpWrapperId;
		//[e559] hold nodes in adv to speed up opening
		t.oOlp = E.get(sId);
		t.oCntnt = E.get(sId+'olpcontent');
		t.oShdw = E.get(sId+'olpshadow');
		t.oArr = E.get(sId+'olparrow');
		
		//[e573]enhancement for vertical pointers
		t.pVt = overlayJsModel.pointerVertical;
		t.sArrowVTL = overlayJsModel.arrowVTL;
		t.sArrowVTR = overlayJsModel.arrowVTR;
		t.sArrowVBL = overlayJsModel.arrowVBL;
		t.sArrowVBR = overlayJsModel.arrowVBR;
		
		t.sArrowTL = overlayJsModel.arrowTL;
		t.sArrowTR = overlayJsModel.arrowTR;
		t.sArrowBR = overlayJsModel.arrowBR;
		t.sArrowBL = overlayJsModel.arrowBL;
		//[e559] merged same value assignements in 1 line
		t.iLastLeft = t.iLastTop = t.mouseState = -1;
		t.initDx = t.initDy = t.top = t.left = t.iTmpLftOfset = t.iTmpTopOfset = 0;
		t.bShownInCenter = overlayJsModel.isShownInCenter;
		//[e559] const offset holds value from java bean, while temp ones will come from open msg, and expires after close
		t.iCnstLftOfset = overlayJsModel.leftOffset;
		t.iCnstTopOfset = overlayJsModel.topOffset;
		//[e559] new attr for open msg to pass x, y position without anchor id
		t.aAnchorCoor = false;
		t.sHAlgn = overlayJsModel.horizontalAlign || false;
		t.sVAlgn = overlayJsModel.verticalAlign || false;
		t.iShdwOfset = overlayJsModel.shadowOffset;
		t.iOpDlay = overlayJsModel.openDelay;
		t.iClsDlay = overlayJsModel.closeDelay;
		t.bCloseOnMouseOut = overlayJsModel.isCloseOnMouseOut;
		t.bHasMask = overlayJsModel.hasMask;
		//[e559] js name shortened to reduce weight
		t.sOpMaskServId = overlayJsModel.openMaskServiceName;
		t.sClsMaskServId = overlayJsModel.closeMaskServiceName;
		t.sPostOpServId = overlayJsModel.postOpenedServiceName;
		t.sPostClsServId = overlayJsModel.postClosedServiceName;
		t.bAdjustSize = overlayJsModel.adjustSize;
		
		//[e559] merge init assignment together
		t.fSetNotchLocation = t.oSetNotchLocationOverrider = t.closeByButton = t.bPanelOpen = t.bCheckState= false;
		
		//optimization for finding domain
		t.sOpenServiceName = 'OPEN_OVERLAY_PANEL' + sId;
		t.sCloseServiceName = 'CLOSE_OVERLAY_PANEL' + sId;
		t.bSelfRegistry = overlayJsModel.selfRegistry;
		t.bPromote2Body = overlayJsModel.promote2Body;
	    //t.oHeader = E.get(sId+'olpctenttitle');
	    t.oWHeader = E.get(sId+'olpctnhd');
		t.oCntn = E.get(sId+'_cnt_n');
		t.oCntntBox = E.get(sId+'olpctnbox');
		t.oCloseBtn = E.get(sId+'closebtn');
		t.oCloseLink = E.get(sId+'closelink');
		t.sJsId = overlayJsModel.cmpJsId;
		t.bHeaderDraggable = overlayJsModel.headerDraggable;
		t.bDraggable = overlayJsModel.draggable;
		t.bHasCloseBtn = overlayJsModel.hasCloseBtn;
		t.bHasCloseLink = overlayJsModel.hasCloseText;
		t.icmpWidth = overlayJsModel.cmpWidth;
		t.sCmpOpacity = overlayJsModel.cmpOpacity;
		
		t.PC.registerOverlayPanel(t);
		//[e559]
		//drag timer moved into startDrag method
		//mouseOutClose timer moved into VjOverlayPanelController, centralized 1.
		
		//[e559]
		//create iframe at the very beginning
		if(!t.oIFrame && t.oOlp){
			t.oIFrame =  vjo.dsf.document.Shim.add(t.oOlp);
		//[e559] combined to aAnchorCoor
		//this.coor = false;
		}
		
		// register event
		if (t.bSelfRegistry) {
			t.init();
		}
 
		if(t.bPromote2Body){
			//var body = (t.B.bIE)?document.body:window;
			t.H.attachEvt(window, 'load', t.promote2body, t);
		}
		
	},
	  
   /**
     * optimization for finding domain
	 * @return Void
	 * @access public
	 */
	init : function() {
	    var t = this,H = t.H,
	    open = new vjo.darwin.core.overlaypanel.VjOverlayPanelOpenSvcHandler(t.sJsId),
	    close = new vjo.darwin.core.overlaypanel.VjOverlayPanelCloseSvcHandler(t.sJsId);
		H.attachSvcReqt(t.sOpenServiceName,open.invoke, open);
		H.attachSvcReqt(t.sCloseServiceName,close.invoke, close);
		
		if((t.bDraggable && !t.bHeaderDraggable)  && t.oWHeader){
			H.attachEvt(t.oWHeader, 'mousedown', t.startDrag, t);
			//t.H.attachEvt(t.oWHeader, 'mouseup', t.stopDrag, t);
		}
		
		if(t.oOlp &&  t.oOlp.firstChild){
			var sO = t.oOlp.firstChild;
			sO.setAttribute('style',t.sCmpOpacity);
		}
		
		if(t.bDraggable && t.oWHeader && t.oWHeader.firstChild) {
			var ss = t.oWHeader.firstChild;
			t.setStyle(ss,'cursor','move');
			//t.setStyle(t.oHeader,'cursor','move');
		}
		
		if(t.bHeaderDraggable && t.oCntn){
			H.attachEvt(t.oCntn, 'mousedown', t.startDrag, t);
			//t.H.attachEvt(t.oCntn, 'mouseup', t.stopDrag, t);
			t.setStyle(t.oCntn,'cursor','move');
		}
		
		if(t.bCloseOnMouseOut && t.oCntntBox){
			H.attachEvt(t.oCntntBox, 'mouseover', t.panelMouseOver, t);
			H.attachEvt(t.oCntntBox, 'mouseout', t.panelMouseOut, t);
		}
		
		//TODO check if there's a close link
		if (t.bHasCloseBtn && t.oCloseBtn){
			H.attachEvt(t.oCloseBtn, 'click', t.onClosePanel, t);
		}
		
		if(t.bHasCloseLink && t.oCloseLink){
			H.attachEvt(t.oCloseLink, 'click', t.onClosePanel, t);
			H.attachEvt(t.oCloseLink,'mouseover',t.closeLinkMouseOver,t);
			H.attachEvt(t.oCloseLink,'mouseout',t.closeLinkMouseOut,t);
		}
		
		//if(t.bPromote2Body){
		//	H.attachEvt(body, 'load', t.promote2body, t);
		//}
		
		if (t.icmpWidth!==0 && t.oOlp){
			t.setStyle(t.oOlp,'width',(t.icmpWidth+'PX'));
		}
	},
	
	/**
	 * @JsReturnType void
	 * @JsJavaAccessToJs private
	 * @JsParamType div vjo.dsf.document.ElementJsr
	 * @JsParamType key String
	 * @JsParamType value String
	*/
	setStyle:function(div,key,value){
		div.style[key] = value;
	},
	
	/**
	 * @JsReturnType void
	 * @JsJavaAccessToJs private
	*/
	closeLinkMouseOut:function(){
		this.oCloseLink.style.textDecoration = 'none';
	},
	
	/**
	 * @JsReturnType void
	 * @JsJavaAccessToJs private
	*/
	closeLinkMouseOver:function(){
		this.oCloseLink.style.textDecoration = 'underline';
	},
	
	/**
	 * @JsReturnType void
	 * @JsJavaAccessToJs public
	 * @JsParamType promote boolean
	*/
	promote2body: function(promote){
	    var t = this;
		if(promote){
			t.E.promoteToBody(t.sOlpId);
		}
	},
	
	/**
	 * @JsReturnType void
	 * @JsJavaAccessToJs private
	*/
	onResize: function(){
		var t = this;
		if(t.bPanelOpen){
			if(!t.bDragged){
			   t.bPanelOpen = false;
			}
			t.openOverlayPanel();
		}
	},
	
	/**
	 * @JsReturnType void
	 * @JsJavaAccessToJs public
	 * @JsParamType coordinates Object
	*/
	onOpenOverlayPanel: function(coordinates){
		var t = this;
		t.aAnchorCoor = coordinates?coordinates:false;
		t.openTimer = (t.iOpDlay <= 0)?t.openOverlayPanel():window.setTimeout(t.O.hitch(t, "openOverlayPanel"), t.iOpDlay);
	},
	
	/**
	 * @JsReturnType void
	 * @JsJavaAccessToJs public
	*/
	openOverlayPanel: function(){
	   var t = this,
	   	   openedInfo = false;
	   
	   //[e559] clear open timer
	   if(t.openTimer){
	   	   window.clearTimeout(t.openTimer);
	   	   t.openTimer = null;
	   }
	   
	   if (!t.bPanelOpen){
            t.bPanelOpen = true;
	   		openedInfo = t.render();
	   		if (t.bHasMask) {
	           t.openMask();
	       }
		   
		   var postOpenedMsg = new t.M(t.sPostOpServId);
		   if(openedInfo){
		   	  postOpenedMsg.clientContext = {x: openedInfo[0], y: openedInfo[1], w: openedInfo[2], h: openedInfo[3]};
			  t.H.handle(postOpenedMsg);
		   }
	   }
	},
	
	//BUGDB00516040, contentDiv missing
   /**
	 * @JsReturnType void
	 * @JsJavaAccessToJs public
	*/
	openMask : function(){
		var t = this,
			maskMsg = new t.M(t.sOpMaskServId),
			cnt = t.oCntnt;
        
        try {
            var formElement = cnt?cnt.getElementsByTagName("form")[0]:{name:''}; 
            maskMsg.clientContext = {formName : formElement.name || formElement.id};
        }catch (e){
        }
        
        t.H.handle(maskMsg);
	},
	
    /**
	 * @JsReturnType void
	 * @JsJavaAccessToJs private
	 * @JsParamType origin float
	 * @JsParamType alignment String
     * @JsParamType pad float
	 * @JsParamType offset float
	*/
	align : function(origin, alignment, pad, offset){
		return  origin+
				((alignment=='right'||alignment=='bottom')?pad:0)+
				((alignment=='middle')?(pad/2):0)+
				offset;
	},
	
	//[e559] internal used to return the sum of const & temp left/top offset
   /**
	 * @JsReturnType float
	 * @JsJavaAccessToJs public
	*/
	getLeftOffset : function(){
	    var t = this;
		return t.iCnstLftOfset+t.iTmpLftOfset;
	},
	
   /**
	 * @JsReturnType float
	 * @JsJavaAccessToJs public
	*/
	getTopOffset : function(){
	    var t = this;
		return t.iCnstTopOfset+t.iTmpTopOfset;
	},
	
   /**
	 * @JsReturnType Object
	 * @JsJavaAccessToJs public
	*/
	render : function(){
		var t = this,
		    E = t.E,
		    B = t.B,
			P = t.P,
			W = t.W,
			anc = E.get(t.sAnchorName),
			coordinates = {x:0, y:0},
			openedInfo = false,
			AC = t.aAnchorCoor,
			LS = t.getLeftOffset(),
			TS = t.getTopOffset(),
			SS = t.iShdwOfset;
			
		if(!t.bShownInCenter){
			if(AC){ //[e559] skipped coor calculation if x,y pos is given in open msg
				coordinates.x = AC.x+LS;
				coordinates.y = AC.y+TS;
//				t.aAnchorCoor = false; //reset for next open request
			}
			else{ //[e559] coor calculation flow updated to turn IE
				coordinates.x = (B.bIE&&B.fVer<7)?P.getOffsetLeft(anc)+1:P.getOffsetLeft(anc);
				coordinates.y = P.getOffsetTop(anc);
				//[e559] refactored to align method
				coordinates.x = t.align(coordinates.x, t.sHAlgn, anc?anc.offsetWidth:0,LS);
				coordinates.y = t.align(coordinates.y, t.sVAlgn, anc?anc.offsetHeight:0,TS);
			}
		}
		
		var olp = t.oOlp,
			olpS = olp.style;
		if (olpS) {
			olpS.visibility = 'visible';
			//[e559] commented out these 2 lines, IE6 consumes a lot time doing these change even if there's no such change needed
			//olpS.display = 'block';
			//olpS.position = 'absolute';
			
			//[e559] moved static zIndex from EvtHandler to Controller, making more sense
			olpS.zIndex = t.PC.zIndex();
			if(olpS.zIndex===0){//TODO, why need this?
				t.promote2body();
			}
		}
		
		//[e559] using ?: instead of if/else
		openedInfo = t.fSetNotchLocation ? t.fSetNotchLocation(t.oSetNotchLocationOverrider, t, olp, coordinates) : t.setNotchLocation(olp, coordinates);
		
		t.oShdw.style.height=W.toPixels(t.oCntnt.offsetHeight+2);
		
		if(t.oIFrame){//[e559] reduced local vars w, h
			var s = t.oIFrame.style;
				s.width = W.toPixels(olp.offsetWidth+SS);
	    		s.height = W.toPixels(olp.offsetHeight+SS+2);
		}
		else{//for 2nd & subsequent opening [merged from e557_caboose manually]
			t.oIFrame = t.S.add(olp, SS, SS+2);
		}
		
		return openedInfo;
	},
	
	/**
	 * @JsReturnType void
	 * @JsJavaAccessToJs public
	 * @JsParamType sAnchorName String
	 *
	*/
	
	setAnchorName: function(sAnchorName){
		this.sAnchorName= sAnchorName;
	},
	
	/**
	 * @JsReturnType void
	 * @JsJavaAccessToJs public
	 * @JsParamType sDivId String
	 *
	*/
	setBubbleDivId: function(sDivId){
		this.sOverlayDivId = sDivId;
	},
	
	/**
	 * @JsReturnType void
	 * @JsJavaAccessToJs public
	 * @JsParamType pbCheckState boolean
	*/
	onClosePanel: function(pbCheckState){
		var t = this,CD = t.iClsDlay;
		t.bCheckState = pbCheckState;
		t.closeTimer = (CD <= 0)?t.closePanel():window.setTimeout(t.O.hitch(t, 'closePanel'), CD);
	},
	
	/**
	 * @JsReturnType void
	 * @JsJavaAccessToJs public
	 *
	*/
	closePanel: function(){
		//[e559] using t for this to reduce js size
		var t = this,cT=t.closeTimer;
		//[e559] clear close timer
		if(cT){
			window.clearTimeout(cT);
			cT = null;
		}
		
		if(t.bCheckState && t.mouseState == 1){
			t.bCheckState = false;
			return;
		}
		t.hidePanel();
		if (t.mouseState == 1) {
			t.closeByButton = true;
		}
		t.bDragged = false;
	},
	
	/**
	 * @JsReturnType void
	 * @JsJavaAccessToJs private
	 * @JsParamType olp com.ebay.darwin.component.core.overlaypanel.OverlayPanel
	 * @JsParamType oCoordinates Object
	*/
	setNotchLocation: function(olp, oCoordinates){
		//[e559] using iX & iY to hold x,y value from oCoordinates to reduce references depth.
		// using iScrollX & iScrollY to hold x,y value from aScrollLocation ro reduce references depth.
		// merged var declarations to 1 line, var names shortened
		var t = this,
			W = t.W,
			olpS = olp.style,
			iX = oCoordinates.x,
			iY = oCoordinates.y,
			iW = olp.offsetWidth,
			iH = olp.offsetHeight,
			iScreenW = W.getBrowserWindowWidth(),
			iScreenH = W.getBrowserWindowHeight(),
			aScollLoc = W.getScrollXY(),
			iScrollX = aScollLoc[0],
			iScrollY = aScollLoc[1],
			arr = t.oArr;
			
		if (!t.bShownInCenter) {
			//[e573]enhancement for vertical pointers
			if(t.pVt){
				var xLoc=iX-iScrollX,
					yLoc=iY-iScrollY,
	            	finalX=0,
	            	finalY=0,
	            	arrH = 21,
	            	sAuto = 'auto',
					iAdj = 5,
					bTop = true,
					bLeft = false,
			        B = t.B,
					iGuard = 1; //keep pointer away from mouse, decrease chance of flashing
	            
	            if(!B.bIE){
	           		iAdj += 16;
           		}
	            //calc Y
			    if((yLoc-iH-arrH)<0){
	            	finalY = iY+arrH+iGuard;
					bTop = false;
	            }
	            else{
		 			finalY = iY-iH-arrH-iGuard;
	            }
	            
	            //calc X
	            if(iX - iW/2 < 0){
	            	finalX = 0;	            		
	            }else if(iX + iW/2 + iAdj > iScreenW){
	            	finalX = iScreenW - iW - iAdj;	            	
		        	bLeft = true;
	            }else{
		        	finalX = iX - (iW/2);
		        }
		        
		        //pointer
		        if(arr){
	        		arr.style.left = W.toPixels(  iX - finalX - ( bLeft ? arr.offsetWidth + iGuard : -iGuard ) );		        
	        	}
		        if(bTop){
		        	t.setArrDivStyle(arr, bLeft ? t.sArrowVBL : t.sArrowVBR, sAuto, W.toPixels(-arrH));
		        }else{
			        t.setArrDivStyle(arr, bLeft ? t.sArrowVTL : t.sArrowVTR, W.toPixels(-arrH), sAuto);
		        }		        
			}else{
				//[e559] shortened value assignment
				var xLoc=iX-iScrollX,
					yLoc=iY-iScrollY,
					arrH=arr?21:0,
					arrW=arr?21:0,
					arrS=arr?14:0,//arrow div space
	            	finalX=0,
	            	finalY=0,
	            	finalW=iW+arrW,
	            	finalH=iH,
	            	sAuto = 'auto',
					iAdj = 0,
					bLeft = false;
	            
	            //[e559] added bLeft for the veritical positioning flow below
	            if((xLoc+iW+arrW)<iScreenW || iW>iScreenW || (t.sHAlgn&&t.sHAlgn!='middle')){
	            	finalX = iX+arrW;
					bLeft = true;
	            }
	            else{
	                if((xLoc-iW-arrW) < 0){//show @ x center when there's no space for left or right orientation, & there's no arrow.
		 				finalX = (iScreenW/2-iW/2)+iScrollX+t.getLeftOffset();
		 			}
		 			else{
		 			 	finalX = iX-iW-arrW;
		 			}
	            }
	            
	            //[e559] merged left/right orientations' vertical positioning logic flow
	            if((yLoc+iH)<iScreenH){
		        	finalY = iY-arrS;
		            t.setArrDivStyle(arr, bLeft?t.sArrowTL:t.sArrowTR, W.toPixels(arrS), sAuto);
		        }
		        else if((yLoc+arrS)>iH){
		        	finalY = iY-iH+arrS;
		        	finalY -= t.getTopOffset()*2;//[e569] reverse topOffset if opening in opposite direction, 4 ngvi none-covering lnk need
		            t.setArrDivStyle(arr, bLeft?t.sArrowBL:t.sArrowBR, sAuto, W.toPixels(arrS));
		        }
		        else{
		        	if(yLoc<(iScreenH/2) && (iH<iScreenH)){
		        		iAdj = (iY+iH)-(iScrollY+iScreenH);
		        		finalY = iY-iAdj-arrS;
		        		t.setArrDivStyle(arr, bLeft?t.sArrowTL:t.sArrowTR, W.toPixels(arrS+iAdj), sAuto);
		        	}
		        	else{
		        		iAdj = iScrollY-(iY-iH+arrS);
		        		finalY = iScrollY;
		        		t.setArrDivStyle(arr, bLeft?t.sArrowBL:t.sArrowBR, W.toPixels(yLoc-arrS), sAuto);
		        	}
		        }
	        }//[e573]
		}
		else{
			finalX = (iScreenW/2-iW/2)+iScrollX+t.getLeftOffset();
			finalY = iScreenH/2-iH/2;
			finalY = finalY>0?finalY:0;
			finalY = finalY+iScrollY+t.getTopOffset();
		}
	    //[e559] merged top assignment using finalY
	    olpS.left = W.toPixels(finalX);
        olpS.top = W.toPixels(finalY);
		
		return [finalX, finalY, finalW, finalH];
	},
	
	/**
	 * @JsReturnType void
	 * @JsJavaAccessToJs private
	 * @JsParamType arrowDiv vjo.dsf.ElementJsr
	 * @JsParamType cssClz String
	 * @JsParamType topValue String
	 * @JsParamType bottomValue String
	*/
	setArrDivStyle: function(arrowDiv, cssClz, topValue, bottomValue){
		if(arrowDiv){
              arrowDiv.className = cssClz;
              arrowDiv.style.top = topValue;
              arrowDiv.style.bottom = bottomValue;
        }
	},
	
	/**
	 * @JsReturnType void
	 * @JsJavaAccessToJs public
	 * @JsParamType event com.ebay.dsf.resource.html.event.handler.JsHandlerObjectEnum
	 *
	*/
	startDrag: function(pEvent){
		var t = this,
			P = t.P,
			W = t.W,
			olp = t.oOlp,
			SR = t.bSelfRegistry,
			H = t.H,
			db = document.body;
		
		if (!t.bMonitorDrag){
			t.bMonitorDrag = true;
			t.bDragged = true;
			
			var event = pEvent.nativeEvent;
			if(SR){
				event = pEvent.nativeEvent || pEvent;
			}
			var mouseY = W.eventTop(event),
			mouseX = W.eventLeft(event);
	
			//[e559] replaced Bubble anchor util with Positioning
			t.initDx = P.getOffsetLeft(olp) - mouseX;
			t.initDy = P.getOffsetTop(olp) - mouseY;
			//[e559] merged assignement
			t.top = t.iLastTop = mouseY;
			t.left = t.iLastLeft = mouseX;
			
			//[e559] switched to addEventListener, eliminated method handle creation
			t.fOnMouseMoveHdl = H.attachEvt(db, 'mousemove', t.onMouseMove, t);//can't bind with window, has to be document.body
			t.fOnMouseUpHdl = H.attachEvt(db, 'mouseup', t.onMouseUp, t);
			
			if(olp){
				olp.onselectstart = olp.onmousedown = function(){return false;};
			}
			//[e559] defered timer construction till drag started
			t.interval = 50;
			t.onTick = function(){
				t.monitorMouseDrag();
			};
			t.start();
		}
		if(SR){
				var target = event.target || event.srcElement;
				H.attachEvt(target, 'mouseup', t.stopDrag, t);
		}
	},
	
	/**
	 * @JsReturnType void
	 * @JsJavaAccessToJs public
	 * @JsParamType event com.ebay.dsf.resource.html.event.handler.JsHandlerObjectEnum
	 *
	*/
	onMouseMove: function(pEvent) {
		var t = this,
			W = t.W;
			
		if (t.bMonitorDrag){
			var event = window.event?window.event:pEvent;
			//[e559] replaced self eventTop/eventLeft methods with VjWindowUtils's, does the same thing
			var topValue = W.eventTop(event),
				leftValue = W.eventLeft(event);
			if (topValue>=0 &&  leftValue>=0) {
				t.top = topValue;
				t.left = leftValue;
			}
		}
	},
	
	/**
	 * @JsReturnType void
	 * @JsJavaAccessToJs public
	 * @JsParamType event com.ebay.dsf.resource.html.event.handler.JsHandlerObjectEnum
	 *
	*/
	onMouseUp: function(event) {
		var t = this,
		    H = t.H,
		    db = document.body;
		if (t.bMonitorDrag){
			//[e559] fixed handler unremoved issue
			H.detachEvt(db, 'mousemove', t.fOnMouseMoveHdl);
			H.detachEvt(db, 'mouseup', t.fOnMouseUpHdl);
			t.stopDrag();
		}
	},
	
	/**
	 * @JsReturnType void
	 * @JsJavaAccessToJs public
	 *
	*/
	monitorMouseDrag: function(){
		if (this.bMonitorDrag){
			var t = this,
			P = t.P,
			W = t.W;
			
			if ((t.left!=t.iLastLeft) || (t.top!=t.iLastTop)){
				var dx = t.left-t.iLastLeft,
					dy = t.top-t.iLastTop;	
				t.iLastLeft = t.left;
				t.iLastTop = t.top;
				//[e559] replaced VjAnchorUtil with Positioning lib function
				var olp = t.oOlp,
					olpS = olp.style,
					x = P.getOffsetLeft(olp),
					y = P.getOffsetTop(olp);
	
				olpS.left = W.toPixels(x+dx);
				olpS.top = W.toPixels(y+dy);
			}
		}
	},
	
	/**
	 * @JsReturnType void
	 * @JsJavaAccessToJs public
	 *
	*/
	stopDrag: function(){
		var t = this;
		t.bMonitorDrag = false;
		var olp = t.oOlp;
		if (olp) {
			olp.onselectstart = olp.onmousedown = null;
		}
		//[e559] added to stop the timer
		t.stop();
	},
	
	/**
	 * @JsReturnType void
	 * @JsJavaAccessToJs public
	 *
	*/
	panelMouseOver: function(){
		this.mouseState = 1;
	},
	
	/**
	 * @JsReturnType void
	 * @JsJavaAccessToJs public
	 *
	*/
	panelMouseOut: function(){
		this.mouseState = 0;
	},
	
   /**
	 * @JsReturnType void
	 * @JsJavaAccessToJs public
	 *
	*/
	tryCloseOnMouseOut: function(){
		var t = this;
		if (t.mouseState === 0) {
			t.mouseState = -1;
			if (!t.closeByButton) {
				t.hidePanel();
			} else {
				t.closeByButton = false;
				t.mouseState = -1;
			}
		}
	},
	
	/**
	 * @JsReturnType void
	 * @JsJavaAccessToJs public
	*/
	hidePanel: function(){
		//[e559] shortened var names
		var t = this,
		    H = t.H,
			M = t.M,
			olp = t.oOlp,
			olpS = olp.style;
		//olp.style.display = "none"; can't use due to magellandialog dependency
		olpS.visibility = 'hidden';
		olpS.left = '-1600px'; //set only left
		t.bPanelOpen = false;
		
		//[e559] clean temp offset when closing the panel
		t.iTmpLftOfset = t.iTmpTopOfset = 0;
		
		if (t.bHasMask) {
			H.handle(new M(t.sClsMaskServId));
		}
		if(t.sPostClsServId){
			H.handle(new M(t.sPostClsServId));
		}
		//[e563] delay iframe collection to page unload
		if(t.oIFrame){//[e559] clean up the oIFrame
			if(!t.fCleanUp){
				t.fCleanUp = function(){
					t.S.remove(t.oOlp, t.oIFrame);
					t.oIFrame = null;
				};
				H.attachEvt(window, 'unload', t.fCleanUp, t);
			}
		}
	},
	
	/**
	 * @JsReturnType void
	 * @JsJavaAccessToJs public
	 * @JsParamType sContentTitle String
	*/
	setContentTitle: function(sContentTitle){
		var t = this,tcnt=t.oTitlCntnr;
		//[e559] get title container only once
		if(!tcnt){
			tcnt = t.E.get(t.sOverlayDivId + "olpcontenttitle");
		}
		if(tcnt){
			tcnt.innerHTML = sContentTitle;
		}
	}
});
 
vjo.needs("vjo.dsf.Message");
vjo.type("vjo.darwin.core.overlaypanel.VjOverlayPanelMessage")
.inherits("vjo.dsf.Message")
.protos({
 
	/**
	 * @return Void
	 * @access public
	 * @param {String} name
	 * @param {String} src
	 *
	*/
	constructs: function(name, src){
	    var t = this;
		t.base.call(t,name);
		t.request = t.response = {};
		t.sAnchorId = t.sBubbleId = "";
		t.bCheckState = false;
	},
	
	/**
	 * @return Void
	 * @access public
	 * @param {String} sId
	*/
	setBubbleId: function(sId){
		this.sBubbleId = sId;
	},
	
	/**
	 * @return String
	 * @access public
	*/
	getBubbleId: function(){
		return this.sBubbleId;
	},
	
	/**
	 * @return Void
	 * @access public
	 * @param {String} sId
	*/
	setAnchorId: function(sId){
		this.sAnchorId = sId;
	},
	
	/**
	 * @return String
	 * @access public
	*/
	getAnchorId: function(){
		return this.sAnchorId;
	},
	
	/**
	 * @return Boolean
	 * @access public
	*/
	getCheckState: function(){
		return this.bCheckState;
	}
});
vjo.needs("vjo.dsf.Message");
vjo.needs("vjo.darwin.core.overlaypanel.VjOverlayPanelMessage");
vjo.needs("vjo.dsf.window.utils.VjWindowUtils");
vjo.type("vjo.darwin.core.overlaypanel.VjOverlayPanelEvtHandlers")
.props({
	M : vjo.darwin.core.overlaypanel.VjOverlayPanelMessage,
	/**
	 * @return vjo.darwin.core.overlaypanel.VjOverlayPanelMessageJsr
	 * @access public
	 * @param {String} messageId
	 * @param {String} anchorId
	*/
	handleOpenEvent: function(messageId, anchorId){
		var message = new this.M(messageId);
		message.setAnchorId(anchorId);
		return message;
	},
	
	/**
	 * @return vjo.darwin.core.overlaypanel.VjOverlayPanelMessageJsr
	 * @access public
	 * @param {String} messageId
	 * @param {String} anchorId
	*/
	handleOpenEventXY: function(messageId, x, y){
		var message = new this.M(messageId);
		message.left = x;
		message.top = y;
		message.resetPosition = false;
		return message;
	},
 
	/**
	 * @return vjo.darwin.core.overlaypanel.VjOverlayPanelMessageJsr
	 * @access public
	 * @param {String} messageId
	 * @param {com.ebay.dsf.resource.html.event.handler.JsHandlerObjectEnum} pEvent
	*/
	handleOpenEventByLoc: function(messageId, pEvent){
		var e = pEvent.nativeEvent,
			W = vjo.dsf.window.utils.VjWindowUtils,
			x = W.eventLeft(e),
			y = W.eventTop(e);
		return this.handleOpenEventXY(messageId, x, y);
	},
	
	/**
	 * @return vjo.darwin.core.overlaypanel.VjOverlayPanelMessageJsr
	 * @access public
	 * @param {String} messageId
	*/
	handleCloseEvent: function(messageId){
		var message = new this.M(messageId);
		return message;
	},
	
	/**
	 * @JsReturnType vjo.darwin.core.overlaypanel.VjOverlayPanelMessageJsr
	 * @JsJavaAccessToJs public
	 * @JsParamType messageId String
	 * @JsParamType checkState Boolean
	*/
	handleCloseEventWithCheck: function(messageId, checkState){
		var message = new this.M(messageId);
		message.bCheckState = checkState;
		return message;
	}
});
 
vjo.type("vjo.darwin.app.common.mask.MaskHandlers")
.props({
	/**

	 * @JsReturnType void
	 * @JsJavaAccessToJs public
	 * @JsParamType psId String
	 * @JsParamType psMsg com.ebay.dsf.resource.html.event.handler.JsHandlerObjectEnum
	 * @JsServiceHandler
	 */
	
	openService : function (psId, psMsg) {
		var ctrl = vjo.Registry.get(psId);
		if (ctrl) ctrl.show(psMsg.clientContext);
	},
	
	
	/**
	 * @JsReturnType void
	 * @JsJavaAccessToJs public
	 * @JsParamType psId String
	 * @JsParamType psMsg com.ebay.dsf.resource.html.event.handler.JsHandlerObjectEnum
	 * @JsServiceHandler
	 */
	 
	closeService : function (psId, psMsg) {
		var ctrl = vjo.Registry.get(psId);
		if (ctrl) ctrl.hide();
	}
 
});

 
vjo.needs("vjo.dsf.window.utils.VjWindowUtils");
vjo.needs("vjo.dsf.EventDispatcher");
vjo.needs("vjo.dsf.utils.Timer");
vjo.needs("vjo.darwin.app.common.mask.MaskHandlers");
vjo.type("vjo.darwin.app.common.mask.Mask")
 
.protos({
	/**
	 * @JsReturnType void
	 * @JsJavaAccessToJs public
	 * @JsParamType psId String
	 * @JsParamType psOpacity String
	 */
	constructs : function (psId,psOpacity) {
		var t = this;
		t.eElem = document.getElementById(psId);
		t.iOpacity = (psOpacity) ? parseFloat(psOpacity) : 0;
		t.showing = false;
		t.zIndex = 100;
		t.sIsActivated = false;
		t.oTimer = false;
		t.ED = vjo.dsf.EventDispatcher;
	},
		
	/**
	 * @JsReturnType boolean
	 * @JsJavaAccessToJs public
	 * @JsEventHandler
	 */
	show : function(ctx) {
		var t = this;
		if (t.showing) return;
		else t.showing = true;
 
		t.formName = (ctx)?ctx.formName:"";		
		t.zIndex = (ctx && ctx.overlayPanelIndex)?ctx.overlayPanelIndex:t.zIndex;
		
		t.render();
 
		t.disableSelects();
 
		t.startResizeListener();
	},
 
	render : function(){
		var t = this;
		t.VjWindowUtils = vjo.dsf.window.utils.VjWindowUtils;
		
		var offsetWidth = t.VjWindowUtils.scrollWidth();
		var offsetHeight = t.VjWindowUtils.scrollHeight();
		
		t.setStyle("display","block");
		t.setStyle("width",t.VjWindowUtils.toPixels(offsetWidth));
		t.setStyle("height",t.VjWindowUtils.toPixels(offsetHeight));
		t.setStyle("opacity",t.iOpacity);
		t.setStyle("filter","alpha(opacity="+parseInt(100*t.iOpacity)+")");
		t.setStyle("background","#cccccc");		
		t.setStyle("zIndex", t.zIndex);
	},
 
	/**
	 * @JsReturnType boolean
	 * @JsJavaAccessToJs public
	 * @JsEventHandler
	 */
	hide : function() {
		var t = this;
		if (!t.showing) return;
		else t.showing = false;
 
		t.setStyle("display","none");
 
		t.setStyle("width",t.VjWindowUtils.toPixels(0));
		t.setStyle("height",t.VjWindowUtils.toPixels(0));
 
		t.enableSelects();
 
		t.stopResizeListener();
	},
	
	disableSelects : function() {
 
		this.disabledSelects = new Array();
 
		var selects = document.body.getElementsByTagName("select");
		for (var idx = 0;(idx < selects.length);idx++) {
			
			var select = selects[idx];
			if (select.disabled) continue;
			
			var formName = (select.form)?select.form.name:null;
			if (formName == this.formName) continue;
			
			select.disabled = true;
			this.disabledSelects.push(select);
 
		}
	},
	
	enableSelects : function() {
		var selects = this.disabledSelects;
		for (var idx = 0;(idx < selects.length);idx++) {
			selects[idx].disabled = false;
		}
	},
	
	setStyle : function(name,value) {
		var e = this.eElem;
		if (!e || !e.style) { return; }
		e.style[name] = value;
	},
	
	requireResize : function(){
        this.sIsActivated = true;
    },
    
	startResizeListener : function(){
    	var t = this;
		t.ED.addEventListener(window,'resize',t.requireResize, t);
		
    	if(!t.oTimer){
	        t.oTimer = new vjo.dsf.utils.Timer();
	        t.oTimer.interval = 500;
	        t.oTimer.onTick = function(){
	           if (t.sIsActivated){
	           	  t.render();
		          t.sIsActivated = false;
	           }
	        };
	    }
        t.oTimer.start();
    },
    
    stopResizeListener : function(){
    	var t = this;
		t.ED.removeEventListener(window,'resize',t.requireResize, t);
		
    	if(t.oTimer){
    		t.oTimer.stop();
    	}
    }
 
});
 
 
 
vjo.needs("vjo.dsf.client.Browser");
vjo.needs("vjo.dsf.document.Element");
vjo.needs("vjo.dsf.ServiceEngine");
vjo.needs("vjo.dsf.utils.Handlers");
vjo.needs("vjo.darwin.core.overlaypanel.VjOverlayPanelController");
vjo.needs("vjo.darwin.core.overlaypanel.VjOverlayPanelEvtHandlers");
vjo.type("vjo.darwin.core.previewbox.PreviewBox")
.protos({
	
	/**
	 * @JsReturnType void
	 * @JsJavaAccessToJs public
	 * @JsParamType poJsModel com.ebay.darwin.component.core.previewbox.PreviewBoxJsModel
	 */
	constructs : function(poJsModel){
		var t = this,
			E = vjo.dsf.document.Element,
			m = poJsModel;
			
			t.H = vjo.dsf.utils.Handlers;
			t.sCmpId = m.cmpId;
			t.sPBOpenSvcId = m.previewBoxOpenServName;
			t.sPBLoadSvcId = m.loadServName;
			t.sOlpPostOpenSvcId = m.overlayPanelPostOpenedServName;
			t.sStartThrSvcId = m.throbberOpenServName;
			t.sStopThrSvcId = m.throbberCloseServName;
			t.sOlpJsId = m.overlayPanelJsRefId;
			
			t.sOlpId = m.overlayPanelId;
			t.oOlp = E.get(t.sOlpId);
			t.oOlpN = E.get(m.overlayPanelNorthId);
			
			t.oThrPh = E.get(m.throbberPlaceHolderId);
			t.oImgPh = E.get(m.imagePlaceHolderId);
			t.oImgCtrlPh = E.get(m.imageControlPlaceHolderId);
			t.oPriInfoPh = E.get(m.primaryItemInfoPlaceHolderId);
			t.oAddInfoPh =  E.get(m.additionalItemInfoPlaceHolderId);
			t.oActionPh = E.get(m.callToActionPlaceHolderId);
			t.oThrArea = E.get(m.throbberAreaId);
			t.oImgArea = E.get(m.imageAreaId);
			t.oImgCtrlArea = E.get(m.imageControlAreaId);
			t.oPriInfoArea = E.get(m.primaryItemInfoAreaId);
			t.oAddInfoArea =  E.get(m.additionalItemInfoAreaId);
			t.oActionArea = E.get(m.callToActionAreaId);
			
			t.bForgive = false;
			t.sOpenServiceName =  m.openServiceName;
			t.sPostOpenServiceName = m.postOpenServiceName;
			t.sCloseServiceName = m.closeServiceName;
			t.sPostCloseServiceName = m.postCloseServiceName;
			t.iOpenDelay = m.openDelay;
			t.iCloseDelay = m.closeDelay;
			
			t.aPaddings = m.paddings;
			t.iMaxWidth = m.maxWidth || 9999;
			t.iWidthPadding = 0;
			if(t.aPaddings){
				t.iWidthPadding = t.aPaddings[1] + t.aPaddings[3];
			}
			
			t.H.attachSvcReqt(t.sPBOpenSvcId, t.appear, t);
	},
	
	appear : function(message){
		var t = this;		
		if(t.closeTimer){window.clearTimeout(t.closeTimer);}
		if(t.openTimer){window.clearTimeout(t.openTimer);}
		t.message = message;
		t.openTimer = (t.iOpenDelay <= 0)?t.openOverlay():window.setTimeout(vjo.dsf.utils.Object.hitch(t, 'openOverlay'), t.iOpenDelay);		
	},
	
	openOverlay : function(){
		var t = this;
		if(t.message.bRerender){
			t.render();	
			return false;
		}
		var msg = vjo.darwin.core.overlaypanel.VjOverlayPanelEvtHandlers.handleOpenEvent(t.message.messageId, t.message.anchorId);
		t.H.attachSvcReqt(t.sOlpPostOpenSvcId, t.fillOverlay, t);
		if(t.sPBLoadSvcId){
			t.H.attachSvcReqt(t.sPBLoadSvcId, t.loadOverlay, t);
		}
						
		t.H.handle(msg);
		t.H.resetSvcReqt(t.sOlpPostOpenSvcId);
		t.H.resetSvcReqt(t.sPBLoadSvcId);
	},
	
	loadOverlay : function(message){
		var t = this,
			d = message.clientContext;
			
		if(d.sThrArea){
			t.oThrArea.innerHTML = d.sThrArea;
		}
		if(d.sImgArea){
			t.oImgArea.innerHTML = d.sImgArea;
		}
		if(d.sImgCtrlArea){
			t.oImgCtrlArea.innerHTML = d.sImgCtrlArea;
		}
		if(d.sPriInfoArea){
			t.oPriInfoArea.innerHTML = d.sPriInfoArea;
		}
		if(d.sAddInfoArea){
			t.oAddInfoArea.innerHTML = d.sAddInfoArea;
		}
		if(d.sActionArea){
			t.oActionArea.innerHTML = d.sActionArea;
		}
		
		if(t.sStopThrSvcId){
			t.H.handle(t.H.newMsg(t.sStopThrSvcId));
		}
		
		t.fillOverlay(null);
	},
	
	fillOverlay : function(message){
		var t = this;
		if(!t.oOlpJsRef){
			t.oOlpJsRef = vjo.Registry.get(t.sOlpJsId);
		}
		
		t.installArea(t.oThrPh, t.oThrArea);
		t.installArea(t.oImgPh, t.oImgArea);
		t.installArea(t.oImgCtrlPh, t.oImgCtrlArea);
		t.installArea(t.oPriInfoPh, t.oPriInfoArea);
		t.installArea(t.oAddInfoPh, t.oAddInfoArea);
		t.installArea(t.oActionPh, t.oActionArea);
		
		if(t.sStartThrSvcId && message){
			t.H.handle(t.H.newMsg(t.sStartThrSvcId));
		}
		
		t.render();
		
		return false;
	},
	
	render : function(){
		var t = this, 
			max = t.unpad(t.oOlpN.offsetWidth + 4);
		
		max = t.getMax(t.oImgPh, max, true);
		max = t.getMax(t.oImgCtrlPh, max, false);
		max = t.getMax(t.oPriInfoPh, max, false);
		max = t.getMax(t.oAddInfoPh, max, false);
		max = t.getMax(t.oActionPh, max, false);
		
		// BUGDB00548322
		if( t.oImgPh){
        	var imgTable = t.oImgPh.getElementsByTagName("TABLE");
        	if( imgTable && imgTable.length > 0){
        		var tableWidth = imgTable[0].clientWidth;
        		if( tableWidth && Number(tableWidth) > 300){
        			var tablePadding = (Number(tableWidth) - 300)/2 - 4;
        			if( tablePadding > 0){
        				imgTable[0].style.paddingRight = tablePadding + 'px';
        				imgTable[0].style.paddingLeft  = tablePadding + 'px';
        			}
        		}
        	}
		}
				
		//BUGDB00564317
		var B = vjo.dsf.client.Browser;
		var bIE6 = B.bIE && B.iVer < 7;
		var width = t.oOlpN.offsetWidth;
		var width = bIE6 ? width + 10 : width + 4;
		
		if(t.oOlp && t.oOlpJsRef && max > width){
			t.adjust(t.pad(max));
		}
		
		//BUGDB00554198 begin
		var B = vjo.dsf.client.Browser;
		if( B.bIE && B.iVer < 7){
		   t.oOlp.style.width = (t.oOlp.offsetWidth + 'px');
		}
		//BUGDB00554198 end
		  
		if(t.oOlpJsRef){
			t.oOlpJsRef.render();
		}
	},
	
	prepareArea : function(poArea){
		if(poArea && poArea.parentNode){
			poArea.parentNode.removeChild(poArea);
			poArea.style.display = 'block';
		}
	},
	
	installArea : function(poPlaceHolder, poArea){
		var t = this;
		if(poPlaceHolder && poArea){
			t.prepareArea(poArea);
			t.cleanArea(poPlaceHolder);
			poPlaceHolder.appendChild(poArea);
		}
	},
	
	cleanArea : function(poPlaceHolder){
		var area = poPlaceHolder.firstChild,
			areaS = area?area.style:false;
		if(area){
			poPlaceHolder.removeChild(area);
			if(areaS){
				areaS.display = 'none';
			}
			document.body.appendChild(area);
		}
	},
	
	adjust : function(width){
		var t = this,
			B = vjo.dsf.client.Browser,
			bIE6 = B.bIE && B.iVer < 7;
		width = bIE6 ? width + 10 : width + 4;
		t.oOlp.style.width = width + 'px';
		t.oOlpJsRef.render();
	},
	
	getMax : function(poPh, max, hasImg){
		var t = this,
			n = poPh,
			m = 0;
			
		if(n.nodeType != 1){
			return 0;
		}
		
		if(hasImg && n.nodeName.toUpperCase() == 'IMG'){
			m = parseInt(n.width, 10);
			m = m > max ? m : max;
			if(m > t.iMaxWidth){
				var w = parseInt(n.width, 10),
					h = parseInt(n.height, 10),
					l = t.unpad(t.iMaxWidth);
					
				if(w > l){
					h = (l/w)*h;
					w = l;
				}
				n.width = w;
				n.height = h;
				m = t.iMaxWidth;
			}else{
				
			}
		}
		else{
			m = parseInt(n.offsetWidth, 10);
			m = m > max ? m : max;
			m = m > t.iMaxWidth ? t.iMaxWidth : m;
		}
		
		var i = 0,
			L = n.childNodes.length;
		while(i < L){
			var cM = t.getMax(n.childNodes[i], m, hasImg);
			m = m > cM ? m : cM;
			i++;
		}
		
		
		return m;
	},
	
	pad : function(val){
		return val +this.iWidthPadding-4;
	},
	
	unpad : function(val){
		return val - this.iWidthPadding;
	},
	
	/**
	 * @return void
 	 * @access public
 	 * @JsParamType pEvent com.ebay.dsf.resource.html.event.handler.JsHandlerObjectEnum
	 */
	onMouseoutClose: function(pEvent){
		this.bForgive = false;
		this.disappear(pEvent);
	},
		
	/**
	 * @JsReturnType boolean
	 * @JsJavaAccessToJs public
	 * @JsParamType pEvent com.ebay.dsf.resource.html.event.handler.JsHandlerObjectEnum
	 * @JsEventHandler
	 */
	forgive: function(event){
		this.bForgive = true;
	},
				
	/**
	 * @return vjo.dsf.MessageJsr
	 * @access public
	 * @param {com.ebay.dsf.resource.html.event.handler.JsHandlerObjectEnum} pEvent
	 * @JsEventHandler
	 */
	disappear: function(pEvent){
		var t = this;
		if(t.closeTimer){window.clearTimeout(t.closeTimer);}
		if(t.openTimer){window.clearTimeout(t.openTimer);}
		t.closeTimer = (t.iCloseDelay <= 0)?t.closeOlpPanel():window.setTimeout(vjo.dsf.utils.Object.hitch(t, "closeOlpPanel"), t.iCloseDelay);
	},
	
	/**
	 * @return vjo.dsf.MessageJsr
	 * @access public
	 * @JsEventHandler
	 */
	closeOlpPanel:function(){
		var t = this, oOlp = t.oOlp;
		
		if( oOlp && oOlp.style){
			if(oOlp.style.visibility == 'visible'){
				if(!t.bForgive){
					var message = new vjo.darwin.core.overlaypanel.VjOverlayPanelMessage(t.sCloseServiceName);
					message.bCheckState = true;
					vjo.dsf.ServiceEngine.handleRequest(message);
				}else{
					t.bForgive = false;
				}
			}
		}		
	}
 
});
vjo.needs("vjo.dsf.Message");
vjo.type("vjo.darwin.core.previewbox.PreviewBoxEvtHandlers")
.props({
	
    /**
	 * @JsReturnType vjo.darwin.core.overlaypanel.VjOverlayPanelMessageJsr
	 * @JsJavaAccessToJs public
	 * @JsParamType messageId String
	 * @JsParamType anchorId String
	 * @JsParamType openOlpSvcId String
	*/
	handleOpenEvent: function(messageId, anchorId, openOlpSvcId){
		var message = new vjo.dsf.Message(messageId);
		message.messageId = openOlpSvcId;
		message.anchorId = anchorId;
		return message;
	}
});
 
	vjo.needs("vjo.dsf.Element");
	vjo.needs("vjo.Registry");
	vjo.needs("vjo.dsf.EventDispatcher");
	vjo.needs("vjo.dsf.client.Browser");
	vjo.type("vjo.darwin.core.filmstrip2.FilmStrip2")
	.protos({
 
	/**
	 * @JsReturnType void
	 * @access public
	 * @param {com.ebay.darwin.component.core.filmstrip2.FsJsModel} psJsModel
	 * @JsEventHandler
	 */
     constructs : function ( psJsModel ) {
	    var ot = this, t = psJsModel, ED = vjo.dsf.Element;
	    ot.sId = t.id;
	    ot.iPgItmNo = t.pgItmNo;
	    ot.iTotItms = t.totItms;
	    ot.bBusy = false;
	    ot.sType = t.type;
	    ot.isPgn = t.pgn;
	    ot.isVertical = t.vert;
	    ot.iCurPg = t.curPg;
	    ot.iGotoPg = t.curPg;
	   	ot.sp = t.speed; // delay speed !!!!! number of px moved in 100 milisecond
	   	ot.spx = t.imageSize; // width of item!!! TD width!!!
	    ot.o = ED.get(ot.sId+"_s");
	    ot.n = ED.get(ot.sId+"_n");
	    ot.p = ED.get(ot.sId+"_p");
	    ot.nxt = t.nextAlt;
	    ot.prv=t.prevAlt;
		//vjo.darwin.core.filmstrip2.FilmStrip2.adjustFS(ot.sId, ot.isVertical);
	    ot.regPgnEvents();
	},
 
	/**
	 * @JsReturnType void
	 * @JsJavaAccessToJs public
	 * @JsParamType isNext boolean
	 * @JsEventHandler
	 */
	handleNextPrev : function (isNext) {
		var s = this.iGotoPg + (isNext ? 1 : -1);
		this.calcPx(s);
	},
 
	/**
	 * @JsReturnType void
	 * @JsJavaAccessToJs public
	 * @JsParamType event com.ebay.dsf.resource.html.event.handler.JsHandlerObjectEnum
	 * @JsEventHandler
	 */
	handleGoto : function(event)
	{
		var id = event.src.id;
		var pg = parseInt(id.substring(id.lastIndexOf('_')+1),10);
		// pg = pg - this.iCurPg;
		this.calcPx(pg);
	},
	
	/**
	 * @JsReturnType void
	 * @JsJavaAccessToJs public
	 * @JsParamType event com.ebay.dsf.resource.html.event.handler.JsHandlerObjectEnum
	 * @JsEventHandler
	 */
	handleHoverPgn : function (event) {
	  var el = event.src; // Element ? event.srcElement : event.target;
	  if( el.className === "fs2-st-n" ) {
	    el.className = "fs2-st-h";
	  } else if ( el.className === "fs2-st-h" ) {
	    el.className = "fs2-st-n";
	  }
	},
 
	/**
	 * @JsReturnType void
	 * @JsJavaAccessToJs public
	 * @JsParamType event com.ebay.dsf.resource.html.event.handler.JsHandlerObjectEnum
	 * @JsParamType b boolean
	 * @JsEventHandler
	 */
	handleHover : function (event,b) {
		var c = event.src.className;
		var t = this;
		if( c.indexOf("-a") !== -1 &&  b ) {
			event.src.className = c.replace("-a","-h");
			event.src.title =    (event.src.id.indexOf("_n") !== -1) ?     t.nxt :  t.prv ;
		} else if ( c.indexOf("-h") !== -1 &&  !b ) {
			event.src.className = c.replace("-h","-a");
		}
		if(c.indexOf("-i") !== -1) { event.src.title = "" ; }		
	},
 
	/**
	 * @JsReturnType void
	 * @JsParamType s Integer
	 * @JsEventHandler
	 */
	calcPx : function (s) {
		var ot = this , l = -1;
		var b = ot.iPgItmNo;
		var n = (s - 1) * b;
	
		// if falls in last page
		var d = ot.iTotItms - n;
		var fd = (d < b) ? n - b + d : n;
	
		if( n < 0 || n > ot.iTotItms || ot.bBusy ) {
			return;
		}
	
		ot.bBusy = true;
		var slidePx = fd * ot.spx;
		ot.iGotoPg = s;
	
		// depending on shift Next(+ve) or Previous(-ve), add or
		// subtract
		l = l - slidePx;
		if (ot.iGotoPg > ot.iCurPg) { // Next
			ot.slideNextPrev(l, true);
		} else {  // Previous
			ot.slideNextPrev(l, false);
		}
	},
 
 
	/**
	 * @JsReturnType void
	 * @JsParamType sldPx Integer
	 * @JsParamType isNext boolean
	 * @JsEventHandler
	 */
	slideNextPrev : function(sldPx, isNext)
	{
		var ts = this, l = ts.getOffset();
	
		if(isNext && l - ts.sp > sldPx
					&& l > sldPx && ts.sType === "SCROLL") {
			ts.move( (l - ts.sp) );
			setTimeout(function() { ts.slideNextPrev( sldPx, isNext );},100);
	
		} else if( !isNext && l + ts.sp <= sldPx
					&& l < sldPx && ts.sType === "SCROLL") {
			ts.move( (l + ts.sp) );
			setTimeout(function() { ts.slideNextPrev( sldPx, isNext );},100);
	
		} else {
			ts.move( sldPx );
			ts.bBusy = false;
			ts.hltPgn();
			ts.iCurPg = ts.iGotoPg;
		}
	},
 
	move : function(spx) {
		var t = this.o.style;
		if(this.isVertical){
			t.top = spx + "px";
		} else {
			t.left = spx + "px";
		}
		this.changeBtnState();
	},
 
	getOffset : function()
	{
		var t = this.o.style;
		if(this.isVertical){
			return (t.top !== "")? parseInt(t.top,10) : -1 ;
		} else {
			return (t.left !== "")? parseInt(t.left,10) : -1 ;
		}
	},
 
	hltPgn : function()
	{
		if( ! this.isPgn ) {
			return;
		}
		var DE = vjo.dsf.Element;
		DE.get( this.sId + "_pgn_" + this.iCurPg).className = "fs2-st-n";
		DE.get( this.sId + "_pgn_" + this.iGotoPg).className = "fs2-st-a";
	},
 
	regPgnEvents : function() {
	
		var ED = vjo.dsf.EventDispatcher, t = this,  totPg = parseInt( t.iTotItms/ t.iPgItmNo,10);
		var hov =  function(event) { t.handleHover(event,true); };
		var hou =  function(event) { t.handleHover(event,false); };		
		ED.add(  t.sId + "_n", 'mouseover', hov, t  );
		ED.add(  t.sId + "_p", 'mouseover', hov, t  );
		ED.add(  t.sId + "_n", 'mouseout', hou, t  );
		ED.add(  t.sId + "_p", 'mouseout', hou, t  );
		
		if( ! this.isPgn ) {
			return;
		}
	
		totPg += ( t.iTotItms % t.iPgItmNo === 0 ) ? 0 : 1 ;
		var fn = function(event) { t.handleHoverPgn(event); };
		var gt = function(event) { t.handleGoto(event); };
		for( var i = 1; i <= totPg; i++ ) {
			ED.add(  t.sId + "_pgn_" + i , 'mouseover', fn, t  );
			ED.add(  t.sId + "_pgn_" + i , 'mouseout', fn, t  );
			ED.add(  t.sId + "_pgn_" + i , 'click', gt, t  );
		}
	},
 
	changeBtnState : function()
	{
			var t = this, ofs = t.getOffset();
			var d = (t.iPgItmNo - t.iTotItms) * t.spx;
			if( t.isVertical ) {
			    t.n.className = ( ofs <= d ) ? "fs2-i-b" : t.n.className.replace('-i','-a');
			    t.p.className = ( ofs < -1 ) ? t.p.className.replace('-i','-a') : "fs2-i-t";
			} else {
			    t.n.className = ( ofs <= d ) ? "fs2-i-r" : t.n.className.replace('-i','-a');
			    t.p.className = ( ofs < -1 ) ? t.p.className.replace('-i','-a') : "fs2-i-l";
		    }
	}
 
})
 
 
.props ({
	  adjustFS : function (idx, isVert) {
	  var ED = vjo.dsf.Element;
	  var tbl = ED.get(idx + "_s");
	  var tblCl = ED.get(idx +"_pa");
	  var tblCr = ED.get(idx +"_na");
	  /*if( ! isVert ) {
		  var h = parseInt(tbl.offsetHeight,10);
		  tblCl.style.height = h + "px";
		  tblCr.style.height = h + "px";
	  }*/
	}
});
 
