/*******************************************************************
*
* File    : JSFX_AnimatedRollovers.js © JavaScript-FX.com
*
***********************************************************************/
var FrameInterval    = 60;	/*** Time between frames in milliseconds   ***/
var BaseHref="images/";		/*** This is now only required for AnimatedGif ***/

/*** Create some global variables ***/
if(!window.JSFX)
	JSFX=new Object();
JSFX.AnimationRunning = false; /*** Global state of animation ***/
JSFX.aniTimer = null;
JSFX.AniRollovers = new Array();
JSFX.aniImageError = function()
{
	alert("JSFX_AnimatedRollover.js has detected an error\nImage not found\n" + this.src);
}

JSFX.CreateAnimationFrames = function(imgName, n, ext)
{
	this.num_frames = n;
	for(var i=0 ; i<n ; i++)
	{
		this[i]=new Image();
		this[i].src = imgName + i + ext;

		this[i].onerror=JSFX.aniImageError;
	}
}

JSFX.initAnimatedImage = function(img, ani)
{
	img.ani = new Object();
	img.ani.name  	 = ani;
	img.ani.next_on    = ani;
	img.ani.next_off   = ani;
	img.ani.index      = 0;
	img.ani.target_frame= 0;
	img.ani.state      = "CLOSED";
}

JSFX.AnimatedRollover = function(aniName, imgName, n, ext)
{
	/*** Only download this animation if we don't already have it ***/
	if(JSFX.AniRollovers[aniName] == null)
		JSFX.AniRollovers[ aniName ]= new JSFX.CreateAnimationFrames(imgName, n, ext);
}

JSFX.AnimatedGif = function(name, n)
{
	JSFX.AnimatedRollover(name, BaseHref + name + "/", n, ".gif");
}
JSFX.AnimatedJpg = function(name, n)
{
	JSFX.AnimatedRollover(name, BaseHref + name + "/", n, ".jpg");
}

JSFX.getImg = function(n, d) 
{
	var img = d.images[n];
	if(!img && d.layers)
		for(var i=0 ; !img && i<d.layers.length ; i++)
			img=JSFX.getImg(n,d.layers[i].document);
	return img;
}

JSFX.findImg = function(n, d) 
{
	var img = JSFX.getImg(n, d);

	/*** Stop emails because the image was named incorrectly ***/
	if(!img)
	{
		alert("JSFX.findImg - An Error has been detected\n"
			+ "----------------------------------\n"
			+ "You must define an image in your document\n"
			+ "<IMG SRC=\"your_image.ext\" NAME=\""+n+"\">\n"
			+ "(check the NAME= attribute of your images)");

		return(new Image());
	}

	return img;
}

JSFX.aniRolloverError = function(aniName)
{
	if(JSFX.AniRollovers[aniName])
		return false;
	else
		alert("JSFX.AnimatedRollovers - An Error has been detected\n"
			+ "----------------------------------\n"
			+ "You must define a JSFX.AnimatedRollover in your document\n"
			+ "JSFX.AnimatedRollover(\""+aniName+"\",\"your_img\", n,\".gif\")\n"
			+ "(check the spelling of your JSFX.AnimatedRollovers)");

	return true;
}

JSFX.startAnimation = function()
{
	if(!JSFX.AnimationRunning)
		JSFX.AnimateRollovers();
}

JSFX.aniOn = function(imgName, aniName)
{
	if(aniName == null)
		aniName = imgName;

	var img=JSFX.findImg(imgName, document);

	if(JSFX.aniRolloverError(aniName))
		return;

	if(img.ani == null)
		JSFX.initAnimatedImage(img, aniName);

	if(img.ani.state == "CLOSED" )
	{
		img.ani.state = "OPENING";
		img.ani.name  = aniName;
		JSFX.startAnimation();
	}
	else if ( img.ani.state == "OPEN_CLOSE"
		||  img.ani.state == "CLOSING" 
		||  img.ani.state == "CLOSE_OPEN") 
	{
		if(img.ani.name==aniName)
			img.ani.state = "OPENING";
		else
		{
			img.ani.next_on=aniName;
			img.ani.state = "CLOSE_OPEN";
		}
	}
	/*** Normally you can only set an opening image to OPEN ***/
	/*** However, here we force an already OPEN image to OPENING if we supply a different animation ***/
	else if( img.ani.state == "OPENING"
		|| img.ani.state == "OPEN")
	{
		if(aniName && img.ani.name != aniName)
		{
			img.ani.name=aniName;
			img.ani.index=0;
			img.ani.state="OPENING";
			JSFX.startAnimation();
		}
	}
}

JSFX.aniOff = function(imgName, aniName)
{
	var img=JSFX.findImg(imgName, document);

	if(aniName == null)
		aniName = img.ani.name;

	if(JSFX.aniRolloverError(aniName))
		return;

	if( img.ani.state == "OPEN")		
	{
		img.ani.name=aniName;
		img.ani.index=JSFX.AniRollovers[aniName].num_frames-1;
		img.ani.state = "CLOSING";
		JSFX.startAnimation();
	}
	else if(img.ani.state == "CLOSE_OPEN")
	{
		img.ani.next_off=null;
		img.ani.state="CLOSING"
	}
	else if( img.ani.state == "OPENING" )
	{
		img.ani.next_off = aniName;
		img.ani.state = "OPEN_CLOSE";
	}
}

JSFX.AnimateRollovers = function(d)
{	
	if(d==null)
	{
		d=document;
		JSFX.AnimationRunning = false; /*** Are there more frames that need displaying? ***/
	}

	for(var i=0 ; i<d.images.length ; i++)
	{
		var img = d.images[i];
		if(img.ani)
		{
			var ani=JSFX.AniRollovers[img.ani.name];
			if(img.ani.state == "OPENING")
			{
				/*** Increment the frame index - display the next frame ***/
				/*** when fully open, set state to "OPEN"               ***/
				if(++img.ani.index < ani.num_frames)
				{
					img.src=ani[img.ani.index].src;
					JSFX.AnimationRunning = true;
				}
				else
				{
					img.ani.index=ani.num_frames-1;
					img.ani.state = "OPEN";
				}
			}
			else if(img.ani.state == "OPEN_CLOSE")
			{
				/*** Increment the frame index - display the next frame ***/
				/*** when fully open, set state to "CLOSING"            ***/
				if(++img.ani.index < ani.num_frames)
				{
					img.src=ani[img.ani.index].src;
				}
				else
				{
					if(img.ani.next_off)
					{
						img.ani.name=img.ani.next_off;
						ani=JSFX.AniRollovers[img.ani.name];
						img.ani.next_off=null;
					}
					img.ani.index=ani.num_frames-1;
					img.ani.state = "CLOSING";
				}
				JSFX.AnimationRunning = true;
			}
			else if(img.ani.state == "CLOSING")
			{
				/*** Decrement the frame index - display the next frame ***/
				/*** when fully closed, set state to "CLOSED"           ***/
				if(--img.ani.index >= 0)
				{
					img.src=ani[img.ani.index].src;
					JSFX.AnimationRunning = true;
				}
				else
				{
					img.ani.index=0;
					img.ani.state = "CLOSED";
				}
			}
			else if(img.ani.state == "CLOSE_OPEN")
			{
				/*** Decrement the frame index - display the next frame ***/
				/*** when fully closed, set state to "OPENING"           ***/
				if(--img.ani.index >= 0)
				{
					img.src=ani[img.ani.index].src;
				}
				else
				{
					img.ani.index=0;
					img.ani.name=img.ani.next_on;
					img.ani.state = "OPENING";
				}
				JSFX.AnimationRunning = true;
			}
			else if(img.ani.state == "ROTATE_UP")
			{
				/*** Increment the frame index - display the next frame ***/
				/*** when target reached, set state to "CLOSED"        ***/
				if(img.ani.index != img.ani.target_frame)
				{
					if(++img.ani.index == ani.num_frames)
						img.ani.index = 0;
					img.src=ani[img.ani.index].src;
					JSFX.AnimationRunning = true;
				}
				else
					img.ani.state = "CLOSED";
			}
			else if(img.ani.state == "ROTATE_DOWN")
			{
				/*** Decrement the frame index - display the next frame ***/
				/*** when target reached, set state to "CLOSED"        ***/
				if(img.ani.index != img.ani.target_frame)
				{
					if(--img.ani.index < 0)
						img.ani.index = ani.num_frames-1;
					img.src=ani[img.ani.index].src;
					JSFX.AnimationRunning = true;
				}
				else
					img.ani.state = "CLOSED";
			}
		}
	}

	//NS4 recurse all layers
	if(document.layers)
	{
		for(var l=0 ; l<d.layers.length ; l++)
			JSFX.AnimateRollovers(d.layers[l].document);

		//If we are in a sub layer - no need to check the timer
		if(d!=document)
			return;
	}

	/*** Check to see if we need to animate any more frames. ***/
	if(JSFX.AnimationRunning)
	{
		if(!JSFX.aniTimer)
			JSFX.aniTimer=setInterval("JSFX.AnimateRollovers()",FrameInterval);
	}
	else
	{
		clearInterval(JSFX.aniTimer);
		JSFX.aniTimer=null;
	}
}

JSFX.aniTo = function(frameNo, imgName, aniName)
{
	var img=JSFX.findImg(imgName, document);

	if(aniName == null)
		aniName = imgName;

	if(JSFX.aniRolloverError(aniName))
		return;

	if(img.ani == null)
		JSFX.initAnimatedImage(img, aniName);

	var diff = frameNo - img.ani.index;

	img.ani.target_frame = frameNo;
	var ani=JSFX.AniRollovers[img.ani.name];

	if(Math.abs(diff) > (ani.num_frames/2))
	{
		if(diff < 0)
			img.ani.state = "ROTATE_UP";
		else
			img.ani.state = "ROTATE_DOWN";
	}
	else
	{
		if(diff > 0)
			img.ani.state = "ROTATE_UP";
		else
			img.ani.state = "ROTATE_DOWN";
	}
	JSFX.startAnimation();
}

JSFX.aniUpto = function(frameNo, imgName, aniName)
{
	var img=JSFX.findImg(imgName, document);

	if(aniName == null)
		aniName = imgName;

	if(JSFX.aniRolloverError(aniName))
		return;

	if(img.ani == null)
		JSFX.initAnimatedImage(img, aniName);

	img.ani.target_frame = frameNo;
	img.ani.state       = "ROTATE_UP";
	JSFX.startAnimation();
}

JSFX.aniDownto = function(frameNo, imgName, aniName)
{
	var img=JSFX.findImg(imgName, document);

	if(aniName == null)
		aniName = imgName;

	if(JSFX.aniRolloverError(aniName))
		return;

	var img=JSFX.findImg(imgName, document);

	if(img.ani == null)
		JSFX.initAnimatedImage(img, aniName);

	img.ani.target_frame = frameNo;
	img.ani.state       = "ROTATE_DOWN";
	JSFX.startAnimation();
}

JSFX.aniStop = function(imgName)
{
	var img=JSFX.findImg(imgName, document);
	img.ani.state = "CLOSED";
}

function openpopup(){
var popurl="quote.html"
winpops=window.open(popurl,"","width=670,height=600,status,scrollbars,resizable,")
}

function openpopupCat(){
var popurl="../quote.html"
winpops=window.open(popurl,"","width=670,height=600,status,scrollbars,resizable,")
}


