var esAnimationTime = 0.4; // seconds
esAnimationTime = esAnimationTime*1000;

function showExpressShop(catId, prodId, options)
{
	if(typeof options == 'undefined') options = {};
	if(typeof options.useAnimation == 'undefined') options.useAnimation = true;
	if(typeof options.showId == 'undefined') options.showId = ''; else options.showId = '&showId='+options.showId;
	if(typeof options.noCartDD == 'undefined') options.noCartDD = false;
	
	if(options.noCartDD === true) options.noCartDD = '&noCartDD='+options.noCartDD; else options.noCartDD = '';
	if(typeof options.flashFeedback != 'undefined') options.flashFeedback = '&flashFeedback=true'; else options.flashFeedback = '';
	
	var useAnimationTime = options.useAnimation ? esAnimationTime : 0;
	
	hideAllExpressShop(false, options.useAnimation);
	
	if($.browser.msie && (parseInt($.browser.version) < 7)) {
		$("input.formhider").addClass("hideform");$("select.formhider").addClass("hideform");
	}
	
	var frameWidth = 666,
    frameHeight = 542,
    shadowLeftOffset = (jsContextRoot == '77kids') ? 29 : 7,
    shadowTopOffset = (jsContextRoot == '77kids') ? 35 : 6;
	
    var esFrame = 'esFrame-'+prodId;
	var esWindow = 'esWindow-'+prodId;
	var esShadow = 'esShadow-'+prodId;
	if( $('#'+esWindow).length <= 0 )
	{
		var prodlink = '#outerFooter'; // always put just after #outerFooter now because of cross sells with more than one product in different tabs would keep it hidden sometimes
		$(prodlink).after('<div id="'+esWindow+'" class="esWindow" style="display:none"><div class="esHeader"><a href="#" onclick="hideExpressShop(\''+prodId+'\', false, '+options.useAnimation+'); return false;">Close</a></div><div id="'+esFrame+'" class="esFrame"><iframe frameborder="0" scrolling="no" src="/'+jsContextRoot+'/browse/product.jsp?catId='+catId+'&productId='+prodId+'&expressShop=true'+options.showId+options.noCartDD+options.flashFeedback+'" width="'+frameWidth+'" height="'+frameHeight+'"></iframe></div></div><div id="'+esShadow+'" class="esShadow" style="display:none"></div>');
	}
	
	function centerExpressShop() {
        var viewport = getViewportDimensions();
    	var frameTop = (viewport[1]/2-(frameHeight+19)/2)+$(window).scrollTop();
    	var frameLeft = (viewport[0]/2-(frameWidth+4)/2);
    	if (frameTop < shadowTopOffset) frameTop = shadowTopOffset;
    	if (frameLeft < shadowLeftOffset) frameLeft = shadowLeftOffset;
    	$('#'+esWindow).css({top:frameTop+'px', left:frameLeft+'px'});
    	$('#'+esShadow).css({top:(frameTop-shadowTopOffset)+'px', left:(frameLeft-shadowLeftOffset)+'px'});
    }
    
    $(window).resize(function() {
        centerExpressShop();
    });
    centerExpressShop();
    
	$('#'+esWindow).show(useAnimationTime, function(){
		$('#'+esShadow).show();
	});
	if(!options.useAnimation) $('#'+esShadow).show(); // callback doesn't always seem to fire when animation time is set to zero so make sure this is called in non-animation mode
}

function hideExpressShop(prodId, killFrame, useAnimation)
{
	if(typeof useAnimation == 'undefined') useAnimation = true;
	if(typeof killFrame == 'undefined') killFrame = false;
	var useAnimationTime = useAnimation ? esAnimationTime : 0;
	$('#esShadow-'+prodId).hide();
	if(killFrame)
	{
		$('#esWindow-'+prodId).hide(useAnimationTime, function(){ $('#esFrame-'+prodId).remove(); } );
		if(!useAnimation) $('#esFrame-'+prodId).remove(); // callback doesn't always seem to fire when animation time is set to zero so make sure this is called in non-animation mode
	}
	else $('#esWindow-'+prodId).hide(useAnimationTime);
	
	if($.browser.msie && (parseInt($.browser.version) < 7)) {
		$("input.formhider").removeClass("hideform");$("select.formhider").removeClass("hideform");
	}
}
function hideAllExpressShop(killFrames, useAnimation)
{
	if(typeof useAnimation == 'undefined') useAnimation = true;
	if(typeof killFrames == 'undefined') killFrames = false;
	var useAnimationTime = useAnimation ? esAnimationTime : 0;
	if(killFrames) $('.esShadow').remove();
	else $('.esShadow').remove();
	if(killFrames)
	{
		$('.esWindow').hide(useAnimationTime, function(){ $('.esWindow').hide(); } );
		if(!useAnimation) $('.esWindow').hide(); // callback doesn't always seem to fire when animation time is set to zero so make sure this is called in non-animation mode
	}
	else $('.esWindow').remove();

	if($.browser.msie && (parseInt($.browser.version) < 7)) {
		$("input.formhider").removeClass("hideform");$("select.formhider").removeClass("hideform");
	}
}

function swhideExpressShop(killFrames, useAnimation)
{
	if(typeof useAnimation == 'undefined') useAnimation = true;
	if(typeof killFrames == 'undefined') killFrames = false;
	var useAnimationTime = useAnimation ? esAnimationTime : 0;
	if(killFrames) $('.esShadow').hide();
	else $('.esShadow').hide();
	if(killFrames)
	{
		$('.esWindow').hide(useAnimationTime, function(){ $('.esWindow').hide(); } );
		if(!useAnimation) $('.esWindow').hide(); // callback doesn't always seem to fire when animation time is set to zero so make sure this is called in non-animation mode
	}
	else $('.esWindow').hide();
	
	if($.browser.msie && (parseInt($.browser.version) < 7)) {
		$("input.formhider").removeClass("hideform");$("select.formhider").removeClass("hideform");
	}

}

function openAllExpressShop(killFrames, useAnimation)
{
	if(typeof useAnimation == 'undefined') useAnimation = true;
	if(typeof killFrames == 'undefined') killFrames = false;
	var useAnimationTime = useAnimation ? esAnimationTime : 0;
	if(killFrames) $('.esShadow').show();
	else $('.esShadow').show();
	if(killFrames)
	{
		$('.esWindow').show(useAnimationTime, function(){ $('.esWindow').show(); } );
		if(!useAnimation) $('.esWindow').show(); // callback doesn't always seem to fire when animation time is set to zero so make sure this is called in non-animation mode
	}
	else $('.esWindow').show(useAnimationTime);
}

var eslRevertTimeout = null;
var eslRevertDelay = .1; // seconds
eslRevertDelay = eslRevertDelay * 1000; // convert to miliseconds

function showExpressShopLink(prodLink, catId, prodId, options)
{
	if(typeof options == 'undefined') options = {};
	if(typeof options.useAnimation == 'undefined') options.useAnimation = true;
	if(typeof options.referenceParent == 'undefined') options.referenceParent = false;
	if(typeof options.showId == 'undefined') options.showId = '';
	if(typeof options.position == 'undefined') options.position = true;
	if(typeof options.left == 'undefined') options.left = false;
	if(typeof options.top == 'undefined') options.top = false;
	if(typeof options.noCartDD == 'undefined') options.noCartDD = false;
	if(typeof options.positionToOffsetParent == 'undefined') options.positionToOffsetParent = false;
	
	var leftMargin = 6;
	var topMargin = 5;
	
	clearEslRevertTimeout(); // clear the timeout so this isn't hidden prematurely
	$('.esLink').hide(); // hide others
	var esLink = 'esl-'+prodId;
	
	if(! $('#'+esLink).length <= 0 ) $('#'+esLink).remove(); // remove link if already in page.  need to always create again because could be more than one of the same item in cross sells
	
	var parentReference = options.referenceParent == true ? 'parent.' : '';
	$(prodLink).after('<a id="'+esLink+'" class="esLink" onclick="'+parentReference+'showExpressShop(\''+catId+'\', \''+prodId+'\', {useAnimation:'+options.useAnimation+', showId:\''+options.showId+'\', noCartDD:'+options.noCartDD+'}); dcsMultiTrack(\'WT.ac\',\'ExpressShop\'); return false;" href="#">express&nbsp;shop</a>');
	
	if(options.positionToOffsetParent)
		var pos = $(prodLink).position();
	else
		var pos = $(prodLink).offset();
	
	if(options.position) $('#'+esLink).css({left:(pos.left+leftMargin)+'px', top:(pos.top+topMargin)+'px'}); // if you are letting js position for you
	else{
		if(options.left !== false) $('#'+esLink).css({left:options.left}); // if you are manually setting the left value
		if(options.top !== false) $('#'+esLink).css({top:options.top}); // if you are manually setting the top value
	}
	
	$('#'+esLink).show();
	
	$('#'+esLink).bind('mouseover', function(e){
		clearEslRevertTimeout();  // make sure box doesn't revert back
	});
	$('#'+esLink).bind('mouseout', function(e){
		setEslRevertTimeout(prodId); // to revert back
	});
}
function hideExpressShopLink(prodId)
{
	esLinkName = 'esl-'+prodId;
	$('#'+esLinkName).hide();
}

function setEslRevertTimeout(prodId)
{
	eslRevertTimeout = window.setTimeout('hideExpressShopLink("'+prodId+'")', eslRevertDelay);
}
function clearEslRevertTimeout()
{
	clearTimeout(eslRevertTimeout);
}
