// JavaScript Document

function GWpopUp(){
	$$('.GWpopUp').each( function(popUpDiv){
								shrunkDim = popUpDiv.select('.GWpopShrunk')[0].getDimensions();
								popUpDiv.setStyle({height: shrunkDim.height+'px',width: shrunkDim.width+'px'});
								popUpDiv.select('.GWpopExpanded')[0].setOpacity(.2).hide();
								popUpDiv.wrap('div', {'class':'GWpopWrap'}).setStyle({height: shrunkDim.height+'px',
																					 width: shrunkDim.width+'px',
																					 'z-index': '8',
																					 position: 'relative'});
								  });
}
function GWpopExpand(popUpId){
	popUpDiv = $(popUpId);
	var inc = 70;
	var oInc = .1;
	var curDim = popUpDiv.getDimensions();
	var expandedDiv = popUpDiv.select('.GWpopExpanded')[0];
	if(!expandedDiv.visible()) expandedDiv.show();
	expandedDiv.setOpacity(expandedDiv.getStyle('opacity')+oInc);
	var maxDim = expandedDiv.getDimensions();
	curDim.height += inc;
	curDim.width += inc;
	if(curDim.height > maxDim.height){
		curDim.height = maxDim.height;
	}
	maxDim.width+=40;
	if(curDim.width > maxDim.width){
		curDim.width = maxDim.width;
	}
	popUpDiv.setStyle({height: curDim.height+'px', width: curDim.width+'px'});
	GWpopPose(popUpDiv, false);
	if(curDim.height < maxDim.height || curDim.width < maxDim.width){
		setTimeout("GWpopExpand('"+popUpId+"');",100);
	}else{
		expandedDiv.setOpacity(1);
		//setTimeout("GWpopContract('"+popUpId+"');",5000);
	}
}
function GWpopContract(popUpId){
	popUpDiv = $(popUpId);
	var inc = 70;
	var oInc = .1;
	var curDim = popUpDiv.getDimensions();
	var minDim = popUpDiv.select('.GWpopShrunk')[0].getDimensions();
	curDim.height -= inc;
	curDim.width -= inc;
	if(curDim.height < minDim.height){
		curDim.height = minDim.height;
	}
	if(curDim.width < minDim.width){
		curDim.width = minDim.width;
	}
	popUpDiv.setStyle({height: curDim.height+'px', width: curDim.width+'px'});
	GWpopPose(popUpDiv, true);
	if(curDim.height > minDim.height || curDim.width > minDim.width){
		var expandedDiv = popUpDiv.select('.GWpopExpanded')[0];
		expandedDiv.setOpacity(expandedDiv.getStyle('opacity')-oInc);
		setTimeout("GWpopContract('"+popUpId+"');",100);
	}else{
		popUpDiv.select('.GWpopExpanded')[0].hide();
	}
}

function GWpopPose(popUp, shrinkPop){
	var pose = popUp.cumulativeOffset();
	if(pose.top > 28 || shrinkPop){
		var smallH = popUp.select('.GWpopShrunk')[0].getHeight();
		var curH = popUp.getHeight();
		var top = -(curH-smallH)/2;
		popUp.setStyle({top: top+'px'});
	}
}

Event.observe(window, 'load', function() {
	GWpopUp();
});