// JavaScript Document
/* This code shrinks an object till the point when it reaches 0 width / height ...
and opens another page */
// Copyrighted by AB, 2010

// Variables declare
	var w; var h; var x; var y; var w_org; var h_org; var x_org; var y_org; var hm; var wm; var pix_step; var ws; var t; var cycle; var object; var link_set;
// Main function
function animatedLink(id, eql, shr, ms, page)
{
// Variables initial
// basic
	object = document.getElementById(id);
	link_to = page;
	w = w_org = object.clientWidth; 
	h = h_org = object.clientHeight;
	x = x_org = object.offsetLeft;
	y = y_org = object.offsetTop;	
// derived
	if (w < h)
	{
		hm = w * 0.02;		// minimum height
		wm = w * 0.1;		// minimum width;
		ws = w * 0.3;	// shrinking parameters
		pix_step = w * 0.5;		// cycle step
		t = Math.round(ms / (w + (w - ws)) * pix_step);		
	}
	else
	{
		hm = h * 0.02;		// minimum height
		wm = h * 0.1;		// minimum width;
		ws = h * 0.3;	// shrinking parameters
		pix_step = h * 0.5;
		t = Math.round(ms / (h + (h - ws)) * pix_step);  
	}
	if (t < 20) {t = 20;}		// cycle time limits
	link_set = "off";
// Execution
// object sides equalization (2D)
	if (!eql)
	{
		egl = 0;
		if (!shr) {link_set = "on";}
	}
	else 
	{
		if (w > h)
		{
			x = x + ((w - h) / 2);
			w = h;
			object.style.width = w + 'px';
			object.style.left = x + 'px';
		}
		else if (w < h)
		{
			y = y + ((h - w) / 2);
			h = w;
			object.style.height = h + 'px';
			object.style.top = y + 'px';
		}
	}
// object shrinking
	if (!shr)
	{
		shr = 0;
		link_set = "on";
	}
	else
	{	
		cycle = setInterval("shrinkTimer()", t);
	}
// link to another page (if shrinking interval disabled)
	if ((!eql && !shr) || link_set == "on")
	{
		self.open(link_to);						// new window
		object.style.height = h_org + 'px';		// restoring original values
		object.style.width = w_org + 'px';		// -- || --
		object.style.left = x_org + 'px';		// -- || --
		object.style.top = y_org + 'px';		// -- || --
		object.style.opacity = 0.5;			// mark opened
	}
}
// Shrinking
function shrinkTimer ()
{	
	var h_mem = 0; var w_mem = 0;
// shrinking height
	if (h > hm)
	{
		h_mem = h;		// saving height
		h = h - pix_step;		// reducing height
		if (h < hm) h = hm; 	// low limit
		// 'y' axis calculate
		y = y + ((h_mem - h) / 2);		
	}
// shrinking width (after height reaches 'shrink width')
	if (h < ws )
	{
		w_mem = w;		// saving width
		w = w - pix_step;		// reducing width
		if (w < wm) w = wm;		// low limit
		// 'x' axis calculate
		x = x + ((w_mem - w) / 2);		
	}
// size and position modification
	object.style.height = h + 'px';
	object.style.width = w + 'px';
	object.style.left = x + 'px';
	object.style.top = y + 'px';
// cycle end
	if (w <= wm && h <= hm)
	{
		clearInterval(cycle);					// interval finish
		self.open(link_to);						// new window
		object.style.height = h_org + 'px';		// restoring original values
		object.style.width = w_org + 'px';		// -- || --
		object.style.left = x_org + 'px';		// -- || --
		object.style.top = y_org + 'px';		// -- || --
		object.style.opacity = 0.5;			// mark opened
	}
}



		

	
	
	

