﻿
function GetNodes()
{
	function TraverseNodes(obj)
	{
		var objcount = 0;
		obj._nodes = [];
		obj._attributes = [];
		
		for(var i1 = 0; i1 < obj.attributes.length; i1++)
		{
			if(obj.attributes[i1].nodeType == 2 && obj.attributes[i1].nodeName != null && obj.attributes[i1].nodeName != "")
			{
				obj._attributes[ obj.attributes[i1].nodeName] =  obj.attributes[i1].nodeValue;
				
				
			}
		}
		for(var i1 = 0; i1 < obj.childNodes.length; i1++)
		{
			
			var tagname = obj.childNodes[i1].tagName;
			if(obj.childNodes[i1].nodeType == 1 && tagname.indexOf("/") != 0 )
			{
					obj._nodes[objcount] = obj.childNodes[i1];
					if(obj.childNodes[i1].id != "" && obj.childNodes[i1].id != null)
					{
						obj._nodes[obj.childNodes[i1].id] = obj.childNodes[i1];
					}
					obj._nodes[objcount]._parentnode = obj;
					objcount++;
					TraverseNodes(obj.childNodes[i1]);

			}
		}
	}
	TraverseNodes(document.body);
}

function ClickSpinnerControl(objsrc, atcount)
{
	var obj1 =  document.getElementById(objsrc);
	obj1.animationtype = 2;
	this.animationtype
	obj1.gotoptr = atcount;
	var len = (atcount -  obj1.ptr);
	if(Math.abs(len) > (obj1._nodes.length/2))
	{
		if(len < 0)
		{
			len = (obj1._nodes.length + len);
		}
		else
		{
			len = (obj1._nodes.length - len) * -1;
		}
	}

	obj1.gotoang = len * obj1.ang;



	obj1.timeleft = obj1.gototime;
	var date = new Date();
	obj1.time1 = date.getTime();
	//obj1.intervalid = setInterval("document.getElementById('"+ objsrc + "').Animation();", 10);
}


function MakeSpinner(objsrc, holdtime, slidetime, gototime, prodw, radius, zdip, width, height, zoomfactor, autoanimate, atptr)
{

	var obj1 = document.getElementById(objsrc);
	obj1.holdtime = holdtime;
	obj1.slidetime = slidetime;
	obj1.gototime = gototime;
	obj1.prodw = prodw;

	if(atptr != null)
	{
		obj1.ptr = atptr;
	}
	else
	{
		obj1.ptr = 0;
	}

	obj1.radius = radius;
	obj1.zdip = zdip;

	var pi2 = Math.PI * 2.0;

	//normalize images
	var woffset = prodw/2;
	var mx = width / 2;
	
	var my = height / 2;
	

	obj1.atang = 0;
	obj1.ang = pi2 / obj1._nodes.length;
	obj1.mx = mx;
	obj1.my = my;
	obj1.zoomfactor = zoomfactor;
	
	for(var i1 = 0; i1 < obj1._nodes.length; i1++)
	{
		var i3 = (obj1.ptr + i1) % obj1._nodes.length;
		var a1 = (obj1.ang * i1) + obj1.atang;
		var cos1 = Math.cos(a1);
		var sin1 = Math.sin(a1);
		var zoom = (cos1 +obj1.zoomfactor)/ (obj1.zoomfactor + 1);
		var zdip1 = cos1 * zdip;
		var xloc = sin1 * radius;
		var zindex = Math.floor((cos1 + 1.0) * 100) + 1;
		var i2 = prodw / width;
		var hoffset = (height * i2) / 2;
		obj1._nodes[i3].woffset = woffset;
		obj1._nodes[i3].hoffset = hoffset;
		//add in 3d

		obj1._nodes[i3]._nodes[1]._nodes[0].style.width = (prodw * zoom) + "px";
		obj1._nodes[i3]._nodes[1].style.width = (prodw * zoom) + "px";
		obj1._nodes[i3]._nodes[1].style.top = "0px";
		obj1._nodes[i3]._nodes[1].style.left = "-" + Math.floor((prodw * zoom)/ 2) + "px";
		obj1._nodes[i3].style.position = "absolute";
		obj1._nodes[i3].style.zIndex = zindex;
		obj1._nodes[i3].style.left = (mx - woffset + xloc) + "px";
		obj1._nodes[i3]._nodes[0].style.cssText = "height: " + (my - hoffset + zdip1) + "px";

	}

	
	
	var date = new Date();
	obj1.time1 = date.getTime();
	
	obj1.animationtype = 0;//0 for hold, 1 for in trans, 2 opposit trans
	obj1.timeleft = holdtime;
	
	
	obj1.Animation = function()
	{
		var date = new Date();
		var time2 = date.getTime();
		var interval = time2 - this.time1;
		
		this.timeleft -= interval;
		//goto other transition.
		if(this.timeleft < 0)
		{
			this.timeleft = 0;
		}

		//hold times
		if(this.animationtype == 0)
		{
		
		}
		else if(this.animationtype == 1)
		{
			//slide pictures

			var t =  this.timeleft /this.slidetime;
			//Cubic Bezier for slide animation
			var it = (1 - t);
			var p0 = (it * it * it) * -1;
			var p1 = ((it * it) * t * 3) * -0.999000999000999;
			var p2 = (it * (t * t) * 3) * -0.03333333333333;

			
			var trans = (p0 + p1 + p2);

			for(var i1 = 0; i1 < this._nodes.length; i1++)
			{

				var i3 = (this.ptr + i1) % this._nodes.length;
				var a1 = (this.ang * i1) + (this.ang * trans);
				var cos1 = Math.cos(a1);
				var sin1 = Math.sin(a1);

				var zoom = (cos1 +this.zoomfactor)/ (this.zoomfactor + 1);
				var zdip1 = cos1 * this.zdip;
				var xloc = sin1 * this.radius;
				var zindex = Math.floor((cos1 + 1.0) * 100) + 1;

				var i2 = this.prodw / this._nodes[i1].offsetWidth;
				
				//add in 3d
				this._nodes[i3]._nodes[1]._nodes[0].style.width = (this.prodw * zoom) + "px";
				this._nodes[i3]._nodes[1].style.width = (this.prodw * zoom) + "px";
				this._nodes[i3].style.position = "absolute";
				this._nodes[i3].style.left = (this.mx - this._nodes[i3].woffset + xloc) + "px";
				this._nodes[i3].style.zIndex = zindex;
				this._nodes[i3]._nodes[1].style.top = "0px";
				this._nodes[i3]._nodes[1].style.left = "-" + Math.floor((prodw * zoom)/ 2) + "px";
				this._nodes[i3]._nodes[0].style.cssText = "height: " + (this.my - this._nodes[i3].hoffset + zdip1) + "px";
				
			}




		}
		else if(this.animationtype == 2)
		{
			//slide pictures

			var t =  this.timeleft /this.gototime;
			//Cubic Bezier for slide animation
			var it = (1 - t);
			var p0 = (it * it * it) * -1;
			var p1 = ((it * it) * t * 3) * -0.999000999000999;
			var p2 = (it * (t * t) * 3) * -0.03333333333333;

			
			var trans = (p0 + p1 + p2);

			for(var i1 = 0; i1 < this._nodes.length; i1++)
			{

				var i3 = (this.ptr + i1) % this._nodes.length;
				var a1 = (this.ang * i1) + (this.gotoang * trans);
				var cos1 = Math.cos(a1);
				var sin1 = Math.sin(a1);

				var zoom = (cos1 +this.zoomfactor)/ (this.zoomfactor + 1);
				var zdip1 = cos1 * this.zdip;
				var xloc = sin1 * this.radius;
				var zindex = Math.floor((cos1 + 1.0) * 100) + 1;

				var i2 = this.prodw / this._nodes[i1].offsetWidth;
				
				//add in 3d
				this._nodes[i3]._nodes[1]._nodes[0].style.width = (this.prodw * zoom) + "px";
				this._nodes[i3]._nodes[1].style.width = (this.prodw * zoom) + "px";
				this._nodes[i3].style.position = "absolute";
				this._nodes[i3].style.left = (this.mx - this._nodes[i3].woffset + xloc) + "px";
				this._nodes[i3].style.zIndex = zindex;
				this._nodes[i3]._nodes[1].style.top = "0px";
				this._nodes[i3]._nodes[1].style.left = "-" + Math.floor((prodw * zoom)/ 2) + "px";
				this._nodes[i3]._nodes[0].style.cssText = "height: " + (this.my - this._nodes[i3].hoffset + zdip1) + "px";
				
			}


		}



		if(this.timeleft == 0)
		{
			if(this.animationtype == 0)
			{
				if(this.autoanimate)
				{
					this.animationtype = 1;
					this.timeleft = this.slidetime;
				}
			}
			else if(this.animationtype == 1)
			{
				this.ptr = (this.ptr + 1) % this._nodes.length;
				this.animationtype = 0;
				this.timeleft = this.holdtime;
				if(!this.autoanimate)
				{
					clearInterval(this.intervalid);
				}

				//look for afterload
			
				if(this._nodes[this.ptr]._attributes["afterrotate"] != null)
				{
					eval(this._nodes[this.ptr]._attributes["afterrotate"] );
				}
			}
			else if(this.animationtype == 2)
			{
				this.ptr = this.gotoptr;
				this.animationtype = 0;
				this.timeleft = this.holdtime;
				if(!this.autoanimate)
				{
					this.animationtype = -1;
					//clearInterval(this.intervalid);
				}

				//look for afterload
			
				if(this._nodes[this.ptr]._attributes["afterrotate"] != null)
				{
					eval(this._nodes[this.ptr]._attributes["afterrotate"] );
				}
			}

			
		
		}
	
		this.time1 = time2;
	
	
	
	};

	obj1.autoanimate = autoanimate;
	if(!autoanimate)
	{
		obj1.animationtype = -1;
	}
	
	obj1.intervalid = setInterval("document.getElementById('"+ objsrc + "').Animation();", 10);
	
}

function AboutSmallDogRollOver(obj1)
{
	obj1._nodes[1].style.display = "block";

}
function AboutSmallDogRollOut(obj1)
{
	obj1._nodes[1].style.display = "none";
}

function HideInnerNodes(objsrc)
{
	obj1 = document.getElementById(objsrc);
	
	for(i1 = 0; i1 < obj1._nodes.length; i1++)
	{
		obj1._nodes[i1].style.display = "none";
	}
	
}
function ShowNode(objsrc)
{
	obj1 = document.getElementById(objsrc);
	obj1.style.display = "block";
}



function ShowTag(htmlobj, onclicktxt)
{
	var obj1 = document.getElementById("producttag");
	var obj2 = document.getElementById("producttaginfo");

	obj2.innerHTML = htmlobj;
	obj1.style.display = "block";
	obj2.style.display = "block";

	var x1 =  (window.event.clientX- 200);
	var y1 = (window.event.clientY - 100) 
	if(x1 < 0) x1 = 0;
	if(x1 > 480) x1 = 480;

	obj1.style.left = x1 + "px";
	obj1.style.top =  y1 + "px";

	obj2.style.left =  x1 + "px";
	obj2.style.top =  y1 + "px";

	obj1.onClick = onclicktxt;
	obj2.onClick = onclicktxt;

}









