var welcomeTimeout;
var cleanupTimeout;

var effectDuration = 500;
var animationStartDelay = 2000;


var slideEffectBody;
var slideEffectLogo;
var slideEffectFooter;
var slideEffectFooterContents;

function updateAnimationTime(time) {
	
	animationStartDelay = time;
	
}
function resizeEventHandler(event) {
	updateBgImageLeft();
}
function updateBgImageLeft() {
	
	var windowWidth = window.getWidth();
	var newLeft = ( ( windowWidth ) - ( $('bg_image').getCoordinates().width ) )/2;
	$('bg_image').setStyle('left',newLeft)
}

function loadRevisitEventHandler() {
	$('bg_image').setStyle("visibility", "visible");
	$('background_image').setStyle('top','-425px');
	$('logo_image').setStyle('top','0px');
	$('footer').setStyle('top',getFooterTop());
	$('footer_contents').setStyle('top','0px');
	cleanupHeader();
}



function loadEventHandler (event) {

	$('bg_image').setStyle("visibility", "visible");

	updateBgImageLeft();
	
	slideEffectBody = new Fx.Tween($('background_image'), $extend({property: 'top'}, {duration: effectDuration, transition: Fx.Transitions.linear}));
	slideEffectLogo = new Fx.Tween($('logo_image'), $extend({property: 'top'}, {duration: effectDuration, transition: Fx.Transitions.linear}));
	slideEffectFooter = new Fx.Tween($('footer'), $extend({property: 'top'}, {duration: effectDuration, transition: Fx.Transitions.linear}));
	slideEffectFooterContents = new Fx.Tween($('footer_contents'), $extend({property: 'top'}, {duration: effectDuration, transition: Fx.Transitions.linear}));
	welcomeTimeout = setTimeout('revealBody()',animationStartDelay)	
	
}

function getFooterTop() {
	
	return $('main_content').getCoordinates().height+$('main_content').getCoordinates().top+20;
}

function revealBody() {
	
	welcomeTimeout = null;
	slideEffectBody.start(0,-425);
	slideEffectLogo.start($('logo_image').getCoordinates().top,0);
	
	
	var newFooterTop = getFooterTop();

	slideEffectFooter.start($('footer').getCoordinates().top,newFooterTop)
	
	cleanupTimeout = setTimeout('cleanupHeader()',effectDuration+25)
}

function cleanupHeader() {	
	slideEffectBody = null;
	slideEffectLogo = null;
	slideEffectFooter = null;
	
	$('background_image').setStyle('background-position','center -425px')
	$('navigation').setStyle('z-index','100')
	
	welcomeTimeout = setTimeout('revealFooter()',10000)
	updateBgImageLeft();
}

function revealFooter() {
	welcomeTimeout = null;
	slideEffectFooterContents.start(-110,0);
}

function updatePrice(val) {
	
	var price = '1.99';
	var shipping = '0.99';
	
	if (val >= 100)
	{
		price = "1.49";
		shipping = "2.00";
	}
	else if (val >= 24)
	{
		price = "1.49";
		shipping = "0.99";
	}
	else if (val >= 10)
	{
		price = "1.79";
		shipping = "0.99";
	}
	else if (val >=5)
	{
		price = "1.79";
		shipping = "0.99";
	}
	else
	{
		price = "1.99";
		shipping = "0.99";
	}
	$('item_quantity_1').value = val;
	$('pp_quanity').value = val;
	//$('price_field').innerHTML = 'Only '+price;
	//$('item_price_1').value = price;
	$('ship_method_price_1').value = shipping;
	
	
}