var TweenGallery	=	null;	
var clicks			=	1;
var productGroup1	=	null;

//global vars for the gallery
var numPages		=	5;
var maxDistance		=	-2700;
				
function MoveGallery(MoveLeft)
{
	var distance	=	0;
	var modifier	=	900;
	
	//calculate the distance to move the object
	distance		=	(!MoveLeft) ? parseInt(productGroup1.style.left) - modifier : parseInt(productGroup1.style.left) + modifier;		
	
	//set the function to use
	TweenGallery.func	=	eval(Tween.backEaseOut);	
	
	//only update if the tween has completed
	if(!TweenGallery.isPlaying)
	{
		//update the user clicks
		if(!MoveLeft)
			clicks++;
		else 
			clicks--;
		
		//reset
		if(clicks == numPages && !MoveLeft)
		{
		     clicks = 1;
		     distance = 0;		     
	 	}	
		else if(clicks == 0 && MoveLeft)
		{
		     clicks = numPages-1;
		     distance = maxDistance;		     
		}

		//move the object
		TweenGallery.continueTo(distance, 1);
	}
}

var activeSimLeague = 'MLB';
var activeDynasty = 'HD';
		
function cycleImage(isPrevious, isSimLeague)
{
	var imgArray = new Array();
	
	var activeImage = "";
			
	if(isSimLeague)
	{
		imgArray[0] = document.getElementById('MLB');
		imgArray[1] = document.getElementById('NBA');
		imgArray[2] = document.getElementById('NFL');
		imgArray[3] = document.getElementById('NHL');
				
		activeImage = activeSimLeague;
	}
	else
	{
		imgArray[0] = document.getElementById('HD');
		imgArray[1] = document.getElementById('HBD');
		imgArray[2] = document.getElementById('GD');
		imgArray[3] = document.getElementById('FCD');
		imgArray[4] = document.getElementById('CRD');
					
		activeImage = activeDynasty;
	}
			
	for(var i=0; i<imgArray.length; i++)
	{
		if(imgArray[i].id == activeImage)
		{
			if(!isPrevious)
			{					
				if(i != imgArray.length - 1)
				{
					tweenImage(imgArray[i+1].id, isSimLeague);
					
					if(!isSimLeague && i == imgArray.length - 2)
						tweenContainer(-74);
				}
				else
				{
					tweenImage(imgArray[0].id, isSimLeague);
					
					if(!isSimLeague)
						tweenContainer(0);
				}
			}
			else
			{
				if(i != 0)
				{
					tweenImage(imgArray[i-1].id, isSimLeague);
				
					if(!isSimLeague && i == 1)
						tweenContainer(0);	
				}	
				else
				{
					tweenImage(imgArray[imgArray.length-1].id, isSimLeague);
					
					if(!isSimLeague)
						tweenContainer(-74);
				}
			}
			break;
		}
	}
}
		
function tweenContainer(distance)
{
	var tweenDynasty = null;
	var productContainer = document.getElementById('productLogoContainer');
	
	if(productContainer.style.left == "")
		productContainer.style.left = "0px";
		
	tweenDynasty = new Tween(productContainer.style, 'left', '', parseInt(productContainer.style.left), 10, 1, 'px');						
	tweenDynasty.func = eval(Tween.backEaseOut);						
	tweenDynasty.continueTo(distance, 1);
}

function tweenImage(id, isSimLeague)
{
	var img = document.getElementById(id);						
	imgSrc = "";
	var prodDesc = null;
	var desc = "";
			
	TweenWidth = null;
	TweenHeight = null;
	
	//don't make any changes unless the active id is different
	if(img.id != activeSimLeague || img.id != activeDynasty)
	{
		if(isSimLeague)
		{
			//turn off the prod description
			setProductDescription(activeSimLeague, false);
			
			tweenActiveImage(true);
			activeSimLeague = id;
			imgSrc= activeSimLeague;
		}
		else if(!isSimLeague)
		{
			//turn off the prod description
			setProductDescription(activeDynasty, false);
			
			tweenActiveImage(false);
			activeDynasty = id;
			imgSrc = activeDynasty;
		}
	
		//scale the large image up so that it doesn't look like doo doo...
		img.src = "http://test.whatifsports.net/whatifsports/images/2009Layout/global/productLogos/Large/" + imgSrc + ".png";
				
		TweenWidth = new Tween(img.style, 'width', '', parseInt(img.style.width), 10, 1, 'px');
		TweenHeight = new Tween(img.style, 'height', '', parseInt(img.style.height), 10, 1, 'px');
		TweenWidth.func	=	eval(Tween.backEaseOut);				
		TweenHeight.func = eval(Tween.backEaseOut);
				
		TweenWidth.continueTo(63,1);
		TweenHeight.continueTo(87,1);

		//turn on the new prod desc.
		setProductDescription(img.id, true);
	}
}
		
function tweenActiveImage(isSimLeague)
{
	var img = null;
	var imgSrc = "";
			
	if(isSimLeague)
	{
		img = document.getElementById(activeSimLeague);
		imgSrc = activeSimLeague;
	}
	else
	{
		img = document.getElementById(activeDynasty);
		imgSrc = activeDynasty;
	}
				
	tweenWidth = new Tween(img.style, 'width', '', parseInt(img.style.width), 10, 1, 'px');
	tweenHeight = new Tween(img.style, 'height', '', parseInt(img.style.height), 10, 1, 'px');
	tweenWidth.func = eval(Tween.backEaseOut);
	tweenHeight.func = eval(Tween.backEaseOut);
			
	tweenWidth.continueTo(40,1);
	tweenHeight.continueTo(55,1);
	
	//the images look terrible when scaled down in I.E. so once the animation is over set it to the small logo
	img.src = "http://test.whatifsports.net/whatifsports/images/2009Layout/global/productLogos/Small/" + imgSrc + ".png";
}

function goToProduct(href)
{
	window.location.href	=	'http://www.whatifsports.com/' + href;
}
		
function setProductDescription(id, onOrOff)
{
	var prodDesc = null;
		
	//turn on the new product description			
	switch(id)
	{
		case "NHL":					
			prodDesc = document.getElementById("productBlurbNHL");					
			break;
		case "NBA":
			prodDesc = document.getElementById("productBlurbNBA");					
			break;
		case "NFL":
			prodDesc = document.getElementById("productBlurbNFL");					
			break;
		case "MLB":
			prodDesc = document.getElementById("productBlurbMLB");					
			break;
		case "HBD":
			prodDesc = document.getElementById("productBlurbHBD");					
			break;
		case "HD":
			prodDesc = document.getElementById("productBlurbHD");					
			break;
		case "GD":
			prodDesc = document.getElementById("productBlurbGD");					
			break;
		case "CRD":
			prodDesc = document.getElementById("productBlurbCRD");					
			break;
		case "FCD":
			prodDesc = document.getElementById("productBlurbFCD");					
		default:
			break;
	}
			
	prodDesc.style.display = (onOrOff) ? 'block' : 'none';
}
		
function goToProduct(isSimLeague)
{
	var url = "http://www.whatifsports.com/";
			
	if(isSimLeague)
		url += activeSimLeague.toLowerCase() + "-l";
	else
	{
		if(activeDynasty == 'CRD')
			url = "http://clutch.scenedaily.com/main/";
		else if(activeDynasty == 'FCD')
			url = "http://www.whatifsports.com/soccer/";
		else
			url += activeDynasty.toLowerCase();
	}
				
	window.location.href = url;
}
		

