//Sets attribute for any html tag
function setAttr(id, attr, attrValue){
	if (document.getElementById && document.getElementById(id)){
		if (attr == 'class' && document.all) attr = 'className';
		document.getElementById(id).setAttribute(attr, attrValue);
	}
}

function getWindowWidth() {
	var width = 0;
	if (document.documentElement && document.documentElement.clientWidth) {
		width = document.documentElement.clientWidth;
	} else if (document.body && document.body.clientWidth) {
		width = document.body.clientWidth;
	} else if ( window.innerWidth ) {
		width = window.innerWidth - 18;
	}
	return width;
}

function getWindowHeight() {
	var height = 0;
	if (document.documentElement && document.documentElement.clientHeight) {
		height = document.documentElement.clientHeight;
	} else if (document.body && document.body.clientHeight) {
		height = document.body.clientHeight;
	} else if ( window.innerHeight ) {
		height = window.innerHeight - 18;
	}
	return height;
}

function positionIt(divId) {
	var div = document.getElementById(divId);
	div.style.display = "block";
	var divWidth = div.offsetWidth ? div.offsetWidth : div.style.width ? parseInt( div.style.width ) : 0;
	var divHeight = div.offsetHeight ? div.offsetHeight :  div.style.height ? parseInt( div.style.height ) : 0;
	var winWidth = getWindowWidth();
	var winHeight = getWindowHeight();
	var setX = (winWidth - divWidth) / 2;
	var setY = (winHeight - divHeight) / 2;
	if( setX < 0 ) setX = 0;
	if( setY < 0 ) setY = 0;
	div.style.left = setX + "px";
	div.style.top = setY + "px";

	var IfrRef = document.getElementById('popUpIF');
	if (IfrRef != null) {
		IfrRef.style.width = div.offsetWidth;
		var IfrmTop = setY + 25;
		var IfrmLeft = setX;
		IfrmTop = IfrmTop + "px";
		IfrmLeft = IfrmLeft + "px";
		IfrRef.style.top = IfrmTop;
		IfrRef.style.left = IfrmLeft;
		IfrRef.style.width = divWidth - 10;
		IfrRef.style.height = divHeight - 50;
		IfrRef.style.zIndex = div.style.zIndex - 1;
		IfrRef.style.display = "block";
		IfrRef.style.filter='progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';
	}
}

function showDetails(portfolioId) {
	setAttr('updater', 'class', 'galleryupd');
	positionIt('updater');
	new Ajax.Updater('updater', '/apps/portfolio/ajax.portfolio.details.php', {asynchronous:true, evalScripts:true, onLoading:function(request, json){Element.show('loading')}, onComplete:function(request, json){Element.hide('loading')}, parameters:{id: portfolioId}});
}
