var carouselpos = 0;
var carouselwidth = 0;

var homepagepos = 0;
var homepageheight = 0;

carouselTimeout = null;
activecarousel = 1;

myAnim1 = null;
myAnim2 = null;

function carouselmoveleft() {
	//carouselwidth = getStyle("collectionCarouselList", "width")
	carouselwidth = document.getElementById("collectionCarouselList").offsetWidth
	//alert("I got called: "+carouselwidth);
	
	myAnim1 = new YAHOO.util.Anim('collectionCarouselList', { 
		left: { to: (carouselpos-carouselwidth) }
		}, 40, YAHOO.util.Easing.easeNone);
		myAnim1.animate();
		
	myAnim2 = new YAHOO.util.Anim('collectionCarouselList2', { 
		left: { to: (carouselpos - (carouselwidth*2)) }
		}, 80, YAHOO.util.Easing.easeNone);
		myAnim2.animate();
	carouselTimeout = setTimeout("swapcarousels()", 40000);	
}

function swapcarousels() {
	clearTimeout(carouselTimeout)
	carouselwidth = document.getElementById("collectionCarouselList").offsetWidth
	if (activecarousel == 1) {
		carousel = document.getElementById("collectionCarouselList")
		carousel.style.left = carouselwidth+"px";
		myAnim1 = new YAHOO.util.Anim('collectionCarouselList', { 
		left: { to: (-(carouselwidth)) }
		}, 80, YAHOO.util.Easing.easeNone);
		myAnim1.animate();
		activecarousel = 2
	} else {
		carousel = document.getElementById("collectionCarouselList2")
		carousel.style.left = 0+"px";
		myAnim2 = new YAHOO.util.Anim('collectionCarouselList2', { 
		left: { to: (-(carouselwidth*2)) }
		}, 80, YAHOO.util.Easing.easeNone);
		myAnim2.animate();
		activecarousel = 1
	}
	carouselTimeout = setTimeout("swapcarousels()", 40000);
}


function stopcarousel() {
	//alert("I got fired")
	clearTimeout(carouselTimeout)
	carousel = document.getElementById("collectionCarouselList")
	carousel2 = document.getElementById("collectionCarouselList2")
	myAnim1.stop();
	myAnim1 = new YAHOO.util.Anim('collectionCarouselList', { 
		left: { to: (parseFloat(carousel.style.left)-20) }
		}, 1, YAHOO.util.Easing.easeOut);
		myAnim1.animate();
		
	myAnim2.stop();
	myAnim2 = new YAHOO.util.Anim('collectionCarouselList2', { 
		left: { to: (parseFloat(carousel2.style.left)-20) }
		}, 1, YAHOO.util.Easing.easeOut);
		myAnim2.animate();
}

function startcarousel() {
	carouselwidth = document.getElementById("collectionCarouselList").offsetWidth
	carousel = document.getElementById("collectionCarouselList")
	carousel2 = document.getElementById("collectionCarouselList2")
	timeperpixel = 80/(carouselwidth*2)
	distancetorun = parseFloat(carousel.style.left) + carouselwidth
	timeneeded = distancetorun*timeperpixel
	
	distancetorun2 = (carouselwidth*2)+parseFloat(carousel2.style.left)
	timeneeded2 = distancetorun2*timeperpixel
	
	//alert(timeperpixel+" "+distancetorun+" "+timeneeded)
	//alert(timeperpixel+" "+distancetorun2+" "+timeneeded2)
	
	myAnim1 = new YAHOO.util.Anim('collectionCarouselList', { 
	left: { to: (-(carouselwidth)) }
	}, timeneeded, YAHOO.util.Easing.easeNone);
	myAnim1.animate();
	
	myAnim2 = new YAHOO.util.Anim('collectionCarouselList2', { 
	left: { to: (-(carouselwidth*2)) }
	}, timeneeded2, YAHOO.util.Easing.easeNone);
	myAnim2.animate();
	
	if (timeneeded < timeneeded2) {
		carouselTimeout = setTimeout("swapcarousels()", (timeneeded*1000));
	} else {
		carouselTimeout = setTimeout("swapcarousels()", (timeneeded2*1000));
	}
}


function togglenews(newsid) {
	newsheight = document.getElementById("newsstory_"+newsid+"_inner").offsetHeight
	if (document.getElementById("newsstory_"+newsid).offsetHeight == 0) {
		var newsAnim = new YAHOO.util.Anim('newsstory_'+newsid, { 
			height: { to: (newsheight) }
			}, 0.75, YAHOO.util.Easing.easeBothStrong);
			newsAnim.animate();
			document.getElementById("newsmore_"+newsid).innerHTML = "Show Less"
	} else {
		var newsAnim = new YAHOO.util.Anim('newsstory_'+newsid, { 
			height: { to: (0) }
			}, 0.75, YAHOO.util.Easing.easeBothStrong);
			newsAnim.animate();
			document.getElementById("newsmore_"+newsid).innerHTML = "Read More"
	}
}


function getStyle(el,styleProp)
{
	var x = document.getElementById(el);
	if (x.currentStyle)
		var y = x.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	return y;
}
