/**
 * @author eric
 */
var tweening = false;
function showOverLay( imgSrc ){
	var matte = _.get("matte");
	var overlay = _.get("overlay");
	var img = new Image();

	if( nopostfix ) {
		img.src = imgSrc + ".jpg";
	} else {
		img.src = imgSrc + "_600_400.jpg";
	}
	
	img.onload = doTween;
	
	overlay.innerHTML = skinnyBox(captions[imgSrc.split("/").pop()]);
	overlay.insertBefore(img,overlay.lastChild);
	
	var ypos = parseInt((_.viewportH/2) - (200 + 15 + 25)) + _.scrollTop;
	var xpos = parseInt((_.viewportW/2) - 300);						
	_.x(overlay,xpos); 
	_.y(overlay,ypos);
	
	_.h(matte,_.documentH);
	
	tweening = true;
	checkMatteClick(matte);
	_.show(matte);
	
	if(img.complete){
		doTween();
	}
}

function doTween(){
	var matte = _.get("matte");
	var overlay = _.get("overlay");
	_.quickTween(matte,{diffAlpha:60,startAlpha:0},Math.easeInOutQuint,8,5,showCaption);
}
function showCaption(){
	var matte = _.get("matte");
	var overlay = _.get("overlay");
	var caption = _.get("caption");
	_.show(overlay);
	_.h(matte,_.documentH);
	_.quickTween(caption,{diffH:50,startH:0,startY:-50,diffY:50},Math.easeInOutQuint,5,20,function(){tweening = false;});
}

function checkMatteClick(matte){
	if(!matte.onclick){
		matte.onclick = closeOverLay;
	}
}

function closeOverLay(){
	var matte = _.get("matte");
	if (!tweening){
		_.hide(_.get("matte"));
		_.hide(_.get("overlay"));
		_.h(_.get("caption"), 0);
		_.alpha(matte, 0);
	}
}

function skinnyBox( caption ){
	var html =	'<div style="position:absolute;right:0px;margin-top:-30px;">'+
					'<a href="javascript:closeOverLay();"><img src="/images/close.png" width="80" height="20" border="0" /></a>'+
				'</div><div id="caption">'+caption+'</div>';
	return html;
}