/************** Zoom effect JS ****************/

// init arrays
var scrollers = Array;
scrollers['headerimage_recycle'] = { timer: null };
//scrollers['featureslide'] = { timer: null };
var curSlide = 1;

// easing
function cubicInOut(t, b, c, d)
{
	if ((t/=d/2) < 1) return c/2*t*t*t + b;
	return c/2*((t-=2)*t*t + 2) + b;
}

// easing
function sineInOut(t, b, c, d)
{
	return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
}
		
// perform the move	
function move(scroll,container)
{
	if (scroll.time > scroll.duration)
	{
		clearInterval(scrollers[container].timer);
		scrollers[container].timer = null;
	}
	else
	{	
		element = document.getElementById(scroll.container);
		element.scrollLeft = cubicInOut(scroll.time, scroll.begin, scroll.change, scroll.duration);
		scroll.time++;
	}
}

// initialise the move
function startMove(container,pos,duration)
{	
	if (scrollers[container].timer != null)
	{
		clearInterval(scrollers[container].timer);
		scrollers[container].timer = null;
	}
	
	start = document.getElementById(container).scrollLeft;
	end = pos;
	begin = document.getElementById(container).scrollLeft;	
										
	scrollers[container].time = 0;
	scrollers[container].begin = begin;
	scrollers[container].change = end - start;
	scrollers[container].duration = duration;
	scrollers[container].container = container;
	scrollers[container].timer = setInterval(function(){move(scrollers[container],container);}, 15);
}


function getImgPath(e,state)
{
    if (!(imgSRC = getPattern(document.getElementById(e).childNodes[0].currentStyle.backgroundImage, "\"(.*)_(.*)\.gif\"")))
	    imgSRC = getPattern(document.getElementById(e).childNodes[0].currentStyle.filter, "src='(.*)_(.*)\.gif',");
	if (state)
	    return imgSRC + "_on.gif";
	else
		return imgSRC+"_off.gif";
	//return imgSRC+".png";
}





// set active tabs
function setNavClass(navID)
{
	if(/MSIE (5\.5|6\.)/.test(navigator.userAgent))
	{
	    fixElement('hn_recycle_page1', getImgPath('hn_recycle_page1', false));
	    fixElement('hn_recycle_page2', getImgPath('hn_recycle_page2', false));
	    fixElement('hn_recycle_page3', getImgPath('hn_recycle_page3', false));
		fixElement(navID,getImgPath(navID,true));	
	}
	else
	{
	    document.getElementById('hn_recycle_page1').className = 'off';
	    document.getElementById('hn_recycle_page2').className = 'off';
	    document.getElementById('hn_recycle_page3').className = 'off';	
		document.getElementById(navID).className = 'on';	
	}
}

// change the navigation (perform all functions)
function changeNav(nav)
{
    if (nav == 1) {

        if (document.getElementById('headerimage_recycle') != null)
		{
		    startMove('headerimage_recycle', 0, 40);
		    setNavClass('hn_recycle_page1');
		    window.location.hash = '#page1';
		} 
		return false;
	}
	if (nav == 2)
	{
	    if (document.getElementById('headerimage_recycle') != null)
		{
		    startMove('headerimage_recycle', 948, 40);
		    setNavClass('hn_recycle_page2');
		    window.location.hash = '#page2';
		}
		return false;
	}
	if (nav == 3)
	{
	    if (document.getElementById('headerimage_recycle') != null)
		{
		    startMove('headerimage_recycle', 1896, 40);
		    setNavClass('hn_recycle_page3');
		    window.location.hash = '#page3';
		}
		return false;
	}	
}


function fixElement(e,imgSrc)
{
	element = document.getElementById(e).childNodes[0];
	if (imgSrc)
	{
    	element.style.backgroundImage = "none";
		element.style.backgroundColor = "transparent";
		element.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" +
		imgSrc + "',sizingMethod='crop')";
	}
}

function getPattern(inputString,regPat)
{
//alert("PAT: "+regPat);
//alert("INP: "+inputString);
	var reg=new RegExp(regPat,"i");
	var ar = reg.exec(inputString);
 	if(ar!=null){
 	// alert("MATCH: "+ar[1]);
 	 return ar[1];
 	}
	return null;
}


