﻿self.WD = {
	addEvent:function(obj, evType, fn)
	{ 
		if (obj.addEventListener)
		{  
			obj.addEventListener(evType, fn, false);  return true; 
		}
		else if (obj.attachEvent)
		{   
			var r = obj.attachEvent("on"+evType, fn); 	
			WD.EventCache.add(obj, evType, fn);
			return r;
		}
		else 
		{
			//Mac IE5 sucks here
			return false;
		} 
	}
}

WD.EventCache = function()
{
	var listEvents = [];
	
	return {
		listEvents : listEvents,
	
		add : function(node, sEventName, fHandler, bCapture){listEvents[listEvents.length] = arguments;},
		
		flush : function(){
			var i, item;
			for(i = listEvents.length - 1; i >= 0; i = i - 1)
			{
				item = listEvents[i];				
				if(item[0].removeEventListener){item[0].removeEventListener(item[1], item[2], item[3]);};			
				if(item[1].substring(0, 2) != "on"){	item[1] = "on" + item[1];};				
				if(item[0].detachEvent){item[0].detachEvent(item[1], item[2]);};				
				item[0][item[1]] = null;
			};
		}
	};
}();


WD.addEvent(window,"unload",WD.EventCache.flush);

for(i in self.WD)
{
 if(self[i]==null)
	{
		self[i] = self.WD[i];//synchronize for faster deelopement
	}
}


function CatchERR(a,b,c)
{
 if(window.debug)
	{
		alert( a + "\n" + b + "\n\n" + c + "\n\n" + CatchERR.caller);
	}
	else
	{
		window.status  = ( a + "\n" + b + "\n\n" + c + "\n\n" + CatchERR.caller);
	}
 CatchERR = function(){return true;}
 return true;;
}

window.onerror = CatchERR;

var flag = addEvent(self,"load",auction_pageload);
function auction_pageload()
{
 if(document.getElementById("adlink")){init_adlink();};
}

	


/*hp_event*/
function init_adlink()
{
	var obj = document.getElementById("adlink");
	var lis = obj.getElementsByTagName("li");
	var a = new Array();
	for(var i=0;i<lis.length;i++)
	{
		if( lis[i].parentNode.parentNode == obj)
		{
			var o = lis[i];
			o.style.position="absolute";
			o.style.top = 0;
			if(a.length>=1)
			{
				o.style.top = "-5000px";
			}
			o.style.left = 0;
			o.style.zIndex = (999 - i);
			a[a.length] =o;
			
		}
	}
	if(a.length<2){return;};
	
	obj.stop=false;
	addEvent(obj ,"mouseover",function(){obj.stop=true;});
	addEvent(obj ,"mouseout",function(){obj.stop=false;})
	
	obj.timer = setTimeout("void(0)",0);
	var rotator = function()
	{
		clearTimeout(obj.timer );
		var y = parseInt(a[0].style.top);
		var ey = 0-a[0].offsetHeight;
		if( y > ey && !obj.stop)
		{
			a[0].style.top = (y-1) + "px";
			a[1].style.top = (y-1) + a[0].offsetHeight + "px";
			obj.timer  = setTimeout(rotator,0);
		}
		else
		{
			if(obj.stop)
			{
				clearTimeout(obj.timer );
				a[0].style.top =  "0px";
				a[1].style.top =  "-5000px";
				obj.timer  = setTimeout(rotator,500);				
			}
			else
			{
				a[0].style.top = "-5000px";
				a[1].style.top = 0;				
				var first = a[0];				
				a = a.slice(1,a.length);
				a[a.length] = first;
				var duration = 3;
				if( obj.getAttribute("duration") && !isNaN(obj.getAttribute("duration"))	 )
				{
					duration = parseInt(obj.getAttribute("duration") );
				}
				duration = Math.max(3,duration);
				obj.timer  = setTimeout(rotator,duration * 1000);	
			}
		}
		
		
		
	}
	obj.timer  = setTimeout(rotator,100);

}


