var ie6 = (navigator.appVersion.indexOf('MSIE 6')>-1);

function fillDiv(el, id, contentId) {
	var imageContainer = document.getElementById(id);
	imageContainer.style.visibility = "hidden";
	imageContainer.style.top = 0;
	imageContainer.style.left = 0;
	imageContainer.style.bottom = "auto";
	imageContainer.innerHTML = document.getElementById(contentId).innerHTML;
	imageContainer.className = 'withoutBorder';
	document.getElementById('imageTitle').innerHTML = '';
	if (document.getElementById('activeNav')){
		document.getElementById('activeNav').removeAttribute('id');
	}
	if (document.getElementById('activeThumb')){
		document.getElementById('activeThumb').removeAttribute('id');
	}
	el.id = 'activeNav';
	imageContainer.style.visibility = "visible";
}

function showThisImageIn(realPath, id, resizedPath, alt, el) {
	var imageContainerWidth = 384;
	var popupButtonOnPath = "/meshcms/themes/tinabarth/images/popupButtonOn.gif";
	var popupButtonOffPath = "/meshcms/themes/tinabarth/images/popupButtonOff.gif";
	var imageContainer = document.getElementById(id);
	// ie6 box problems.
	imageContainer.style.top = "auto";
	if (ie6) 
		imageContainer.style.bottom = "230px";
	else
		imageContainer.style.bottom = 0;
	imageContainer.className = 'withBorder';
	var img = document.createElement('img');
	img.style.visibility = "hidden";
	img.setAttribute('alt', alt);
	img.setAttribute('title', alt);
	img.setAttribute('src', resizedPath);
	imageContainer.style.left = 0;
	if (img.width && img.width != "" && img.width != 0 && img.width != 384)
		imageContainer.style.left = (imageContainerWidth - img.width) / 2 + "px";
	img.onclick = function openPopUp(){popImageExtra (realPath, alt, false, 0);}
	imageContainer.innerHTML = '';
	imageContainer.appendChild(img);
	if (document.getElementById('activeNav')){
		document.getElementById('activeNav').removeAttribute('id');}
	document.getElementById('imageTitle').innerHTML = '&laquo;'+alt+'&raquo;';
	var button = document.createElement('img');
	button.setAttribute('alt', 'zoom');
	button.setAttribute('title', 'zoom');
	button.className = 'zoomButton';
	button.setAttribute('src', '/meshcms/themes/tinabarth/images/popupButtonOff.gif');
	button.onmouseover= function popupButtonOn(){button.setAttribute('src', popupButtonOnPath);};
	button.onmouseout= function popupButtonOn(){button.setAttribute('src', popupButtonOffPath);};
	button.onclick = function openPopUp(){popImageExtra (realPath, alt, false, 0);};
	document.getElementById('imageTitle').appendChild(button);
	if (document.getElementById('activeThumb')){
		//document.getElementById('activeThumb').parentNode.previousSibling.id = 'activeNav';
		document.getElementById('activeThumb').removeAttribute('id');
	}
	el.parentNode.previousSibling.id = 'activeNav';
	el.id = 'activeThumb';
	img.style.visibility = "visible";
}

var positionX = 0;
var positionY = 0;
var defaultWidth = screen.availWidth ? screen.availWidth : screen.width;
var defaultHeight = screen.availHeight ? screen.availHeight : screen.height;
if (ie6) {
	defaultWidth = defaultWidth - 12;
	defaultHeight = defaultHeight - 20;
}

function popImageExtra(imageURL,imageTitle,AutoClose,oTimeClose,extraHTML){
	var imgWin = window.open('','_blank','scrollbars=no,resizable=1,width='+defaultWidth+',height='+defaultHeight+',left='+positionX+',top='+positionY);
	var closeButtonOffPath = "/meshcms/themes/tinabarth/images/closeButtonOff.gif";
	var closeButtonOnPath = "/meshcms/themes/tinabarth/images/closeButtonOn.gif";
	if( !imgWin ) { return true; } //popup blockers should not cause errors
	imgWin.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n'+
		'<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" id=\"popup\"><head><title>'+imageTitle+'<\/title>'+
		'<link type=\"text/css\" rel=\"stylesheet\" href=\"/meshcms/admin/theme/meshcms.css\" /><link type=\"text/css\" rel=\"stylesheet\" href=\"/meshcms/themes/tinabarth/main.css\" />'+
		'<meta http-equiv="imagetoolbar" content="false" \/>\n'+
		 '<script type="text\/javascript">\n'+
		'var positionX = 0;\n'+
		'var positionY = 0;\n'+
		'var defaultWidth = screen.availWidth ? screen.availWidth : screen.width;\n'+
		'var defaultHeight = screen.availHeight ? screen.availHeight : screen.height;\n'+
		'var ie6 = (navigator.appVersion.indexOf("MSIE 6")>-1);\n'+
		'if (ie6) {\n'+
		'        defaultWidth = defaultWidth - 12;\n'+
		'        defaultHeight = defaultHeight - 20;\n'+
		'}\n'+

		'function moveImage() {\n'+
			'var popupImage = document.getElementById("popupImage");\n'+
			'if (popupImage) {\n'+
				'popupImage.style.left = (defaultWidth - popupImage.width) / 2 + "px";\n'+
				'popupImage.style.top = (defaultHeight - popupImage.height) / 2 + "px";\n'+
				'popupImage.style.visibility = "visible";\n'+
			'}\n'+
			'var popupLogo = document.getElementById("popupLogo");\n'+
			'var closeButton = document.getElementById("closeButton");\n'+
			'if (popupLogo && closeButton) {\n'+
				'popupLogo.style.left = (defaultWidth - popupImage.width) / 2 - 29 + "px";\n'+
				'popupLogo.style.top = (defaultHeight - popupImage.height) / 2 + popupImage.height - popupLogo.height + "px";\n'+
				'popupLogo.style.visibility = "visible";\n'+
				'closeButton.style.left = (defaultWidth - popupImage.width) / 2 - 30 + "px";\n'+
				'closeButton.style.top = (defaultHeight - popupImage.height) / 2 + "px";\n'+
				'closeButton.style.visibility = "visible";\n'+
			'}\n'+
                '}\n'+
		'<\/script>'+	
		'<\/head><body>\n'+
		'<div id="popupContainer">'+
		'<img id="closeButton" src="'+closeButtonOffPath+'" alt="close" title="close" onclick="self.close()" onmouseover="document.getElementById(\'closeButton\').src=\''+closeButtonOnPath+'\'" onmouseout="document.getElementById(\'closeButton\').src=\''+closeButtonOffPath+'\'" />'+
		'<img id="popupLogo" alt="Tina Barth Photography" title="Tina Barth Photography" src="/meshcms/themes/tinabarth/images/popupLogo.gif" />'+
		'<img id="popupImage" style="cursor: pointer;" src="'+imageURL+'" alt="'+ imageTitle  +'" title="'+ imageTitle  +'" onload="moveImage();"  onclick="self.close();" />'+
		'<\/div><\/body><\/html>');
	imgWin.document.close();
	if( imgWin.focus ) { imgWin.focus(); }
	return false;
}

/**
 * onload() event handler.
 */

init = function () {
  // Load first image of gallery.
  showFirstImage();
}

window.onload = init;

