var timerlen = 5;
var slideAniLen = 250;

var featured_pet_flash_id = "featured_pet_flash";
var main_flash_id = "main_flash_div";
var small_flash_id = "small_flash_div";
var movers = { "featured_pet_flash" : {}, "main_flash_div": {}, "small_flash_div": {}  };

function slidedown(objname)
{
	startslide( objname, "down");
}

function slideup(objname)
{
	startslide( objname, "up"); 
}

function startslide( objname, dir)
{
	var flash_id = 	(objname == "spacer") ? main_flash_id : featured_pet_flash_id;
	if($('#'+flash_id).length == 0)
	{
		flash_id = small_flash_id
	}
	var mover = movers[flash_id];
	
    if(mover.moving)  return;
    
    var _obj = $('#'+flash_id);
    mover.minHeight = $(_obj).attr("minHeight");
    mover.maxHeight = $(_obj).attr("maxHeight");
    mover.dir = dir;
    mover.moving = true;
    mover.startTime = (new Date()).getTime();
	mover.obj = $(_obj)[0];
	mover.timer = setInterval('slidetick(\'' + flash_id + '\');',timerlen);

}
function slidetick(flash_id)
{
	var mover = movers[flash_id];
	if(! mover.moving)  return;
	
	var _obj = mover.obj;
	var elapsed = (new Date()).getTime() - mover.startTime;
	if (false) 
	{
		$(_obj).height( (mover.dir == "up") ?  mover.minHeight: mover.maxHeight);
		endSlide(flash_id)
    }
    else 
    {
    	var _height = $(_obj).height();
    	//var _diff = Math.round( (elapsed / slideAniLen) * (mover.maxHeight - mover.minHeight) );
		var _diff = 20;
		if(mover.dir == "up")
    	{
    		var _new_h = _height - _diff;
    		if( (_new_h) < mover.minHeight)
    		{
    			$(_obj).height(mover.minHeight);
    			endSlide(flash_id)
    		}
    		
    	
    		else $(_obj).height(_new_h);
    	}
    	else 
    	{
    		var _new_h = _height + _diff
    		if( (_new_h) > mover.maxHeight)
    		{
    			$(_obj).height(mover.maxHeight);
    			endSlide(flash_id)
    		}
    		else $(_obj).height(_new_h);
    	}
    }
    //console.debug("Current Flash Div height = " + $(_obj).height());
}

function endSlide(flash_id)
{
	var mover = movers[flash_id];
    clearInterval(mover.timer);
	mover.moving = false;
	var _obj = mover.obj;
    $(_obj).height( (mover.dir == "up") ?  mover.minHeight: mover.maxHeight);
   // console.debug("Final Flash Div height = " + $(_obj).height());
    mover.open = (mover.dir == "up") ? false : true;
}

function toggleSlide(objname)
{
	var flash_id = 	(objname == "spacer") ? main_flash_id : featured_pet_flash_id;
	var mover = movers[flash_id];
	
	if(! mover.open){
		// div is hidden, so let's slide down
		slidedown(objname);
	}else{
		// div is not hidden, so slide up
		slideup(objname);
	}
}

