Photos = {
	instance : null,
	getInstance : function() {
		if (Photos.instance == null) Photos.instance = new _Photos();
		return Photos.instance;
	}
}
function _Photos() {
	this.vPositionElement = null;
	this.hPositionElement = null;	
	this.myId = null;	
	this.inDetails=null;
}
_Photos.IFRAME_ID = "PhotosIframe";
_Photos.prototype.getIframeId = function() {
	return this.myId;
}

_Photos.prototype.close = function(horizontalElement, verticalElement) {
	Transition.addEffect(document.body, Transition.FADE_IN, "duration=.1,interval=.1");
	document.body.effects.play(Transition.FADE_IN);
	// remove iframe so EAF entries will be removed from browser history	var iframeObj= document.getElementById(_Photos.IFRAME_ID);	if(iframeObj){		/*IE throws an exception when iFrame element is remove from the DOM. Hence wrapping the iFrame object in a DIV object*/		var newDiv = document.createElement('div');		newDiv.appendChild(iframeObj);		document.body.appendChild(newDiv);		document.body.removeChild(newDiv);	}
}
_Photos.prototype.getLeft = function() {
	//removed the previous code, now the code is common for VSR and VD pages
	return (window.document.body.clientWidth - document.getElementById(_Photos.IFRAME_ID).offsetWidth) / 2;
}
_Photos.prototype.getTop = function() {
	var photoContainer = document.getElementById(_Photos.IFRAME_ID);
	//removed the previous code, now the code is common for VSR and VD pages
	var closeButtonHeight = 15;
	if(window.document.body.clientHeight > (photoContainer.offsetHeight + closeButtonHeight))	return (document.body.scrollTop + (window.document.body.clientHeight - photoContainer.offsetHeight) / 2);
	else return document.body.scrollTop + closeButtonHeight;
}
_Photos.prototype.getUrl = function(doc) {
	if (!doc) var doc = document;
	var eafUrlUtil = new URLUtility(doc);
	var params = eafUrlUtil.getParameterMap();
	for (var paramName in params) {
		if (!params[paramName]) eafUrlUtil.removeParameter(paramName);
	}
	return eafUrlUtil.getUrl();
}
_Photos.prototype.pageLoad = function(eafContentElement) {	
	var iframe = document.getElementById(_Photos.IFRAME_ID);		
	iframe.style.width = eafContentElement.offsetWidth;
	iframe.style.height = eafContentElement.offsetHeight;
	iframe.style.top = this.getTop();
	iframe.style.left = this.getLeft();
	iframe.style.visibility = "visible";
}
_Photos.prototype.open = function(verticalElement,vID,inDetail,pageName,isPhotoLinkClicked) {
	var iframe = document.createElement("iframe");
	iframe.setAttribute("id", _Photos.IFRAME_ID);
	iframe.name = _Photos.IFRAME_ID;
	this.myId = _Photos.IFRAME_ID;
	this.inDetails=inDetail;
	iframe.style.position = "absolute";
	iframe.style.top = "0px";
	iframe.style.visibility = "hidden";
	iframe.style.zIndex = 1000;
	iframe.src = "about:blank";
	iframe.setAttribute("border", "0");
	iframe.setAttribute("frameBorder", "0");
	iframe.setAttribute("scrolling", "no");
	document.body.appendChild(iframe);
	this.vPositionElement = verticalElement;
	iframe.src = "vehiclePhotoPopup.do?pageName="+pageName+"&id="+vID+"&page=" + pageName+"&isPhotoClicked=" + isPhotoLinkClicked;
	Transition.addEffect(document.body, Transition.FADE_OUT, "duration=.1,interval=.1,backgroundColor=#222222" );
	document.body.effects.play(Transition.FADE_OUT);		
}

if (!window.getAbsOffsetLeft) {
	function getAbsOffsetLeft(element) {
		if (element.offsetParent) return element.offsetLeft + getAbsOffsetLeft(element.offsetParent);
		else return element.offsetLeft;
	}
}
if (!window.getAbsOffsetTop) {
	function getAbsOffsetTop(element) {
		if (element.offsetParent) return element.offsetTop + getAbsOffsetTop(element.offsetParent);
		else return element.offsetTop;
	}
}

