/*
	enlarge.js
	==========
	
	Version 1.21 (April 2nd 2010)
	Copyright amphora.interactive
	
	Usage:
	In <head> section place <script type="text/javascript" src="enlarge.js"></script>
	Put enlargeInit() in body onload, for example <body onload="enlargeInit()"> or <script type="text/javascript">enlargeInit()</script> within content
	enlargeInit(nextImg,prevImg,closeImg) Img are (relative) urls to UI images.
	Use <a href="largeimage.jpg" rel="enlarge" title="Not supported"><img src="thumbnail.jpg"></a>
	
	CSS Sample:
	
.enlargeBackground {
	background-color:#111111;
	opacity: 0.8;
	filter: alpha(opacity=80);
}
.enlarge {
	background-color: #FFF;
	border-spacing: 0px;
	border: 10px solid #fff;
}
.enlarge TD {
	padding: 0px;
}
.enlarge .enlargeContainer {
	margin: auto;
	display: table;
	padding: 5px;
	background-color: #fff;
	width: auto;
}
.enlarge .enlargeClose {
	text-align: right;
	padding-bottom: 5px;
}
.enlarge .enlargeImage {
	padding: 0px 0px 0px 0px;
}
.enlarge .enlargePrev {
	padding-top: 5px;
	float: left;
}
.enlarge .enlargeNext {
	padding-top: 5px;
	float: right;
}
	
*/

var enlargeImages=new Array();
var enlargeTexts=new Array();

function enlargeGetScrollXY() {
  var scrOfX=0,scrOfY=0;
  if (typeof(window.pageYOffset)=='number') {
    scrOfY=window.pageYOffset;
    scrOfX=window.pageXOffset;
  } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
    scrOfY=document.body.scrollTop;
    scrOfX=document.body.scrollLeft;
  } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
    scrOfY=document.documentElement.scrollTop;
    scrOfX=document.documentElement.scrollLeft;
  }
  return [scrOfX,scrOfY];
}

function enlarge(id) {
	document.getElementById('enlargepic2').src=enlargeImages[id];
	
	e1=document.getElementById('enlargepic');
	e2=document.getElementById('enlargepicbg');
	e1.style.display="";
	e1.style.left=enlargeGetScrollXY()[0]+'px';
	e1.style.top=enlargeGetScrollXY()[1]+'px';
	e2.style.display="";
	e2.style.left='0px'
	e2.style.top='0px'
	if (document.body.scrollHeight>document.body.clientHeight)
		e2.style.height=document.body.scrollHeight+'px';
	else
		e2.style.height='100%';
	e2.style.width='100%';
	
	//document.body.style.overflow="hidden";
	
	prev=id-1; if (prev<0) prev=enlargeImages.length-1;
	next=id+1; if (next>=enlargeImages.length) next=0;
	if (document.getElementById("enlargePrev"))
		if (prev>-1 && next!=prev) {
			document.getElementById("enlargePrev").style.display="";
			document.getElementById("enlargePrev").href="javascript:enlarge("+prev+")";
		} else
			document.getElementById("enlargePrev").style.display="none";
	if (document.getElementById("enlargeNext"))
		if (next>-1 && next!=prev) {
			document.getElementById("enlargeNext").style.display="";
			document.getElementById("enlargeNext").href="javascript:enlarge("+next+")";
		} else
			document.getElementById("enlargeNext").style.display="none";
	if (document.getElementById('enlargetxt'))
		if (enlargeTexts[id]!='') {
			document.getElementById('enlargetxt').style.display="";
			document.getElementById('enlargetxt').innerHTML=enlargeTexts[id];
		} else
			document.getElementById('enlargetxt').style.display="none";
}

function enlargeclose() {
	//document.getElementById('enlargetxt').innerHTML="";
	document.getElementById('enlargepic').style.display="none";
	document.getElementById('enlargepicbg').style.display="none";
	document.getElementById('enlargepic2').src="";
	//document.getElementById('enlargeswf').style.display="none";
	//document.getElementById('enlargeswf2').innerHTML="";
}

function enlargeInit(nextImg,prevImg,closeImg) {
	for(i=0; i<document.links.length; i++)
		if (document.links.item(i).rel=='enlarge') {
			enlargeImages[enlargeImages.length]=document.links.item(i).href;
			document.links.item(i).href="javascript:enlarge("+enlargeTexts.length+")";
			enlargeTexts[enlargeTexts.length]=document.links.item(i).title;
		}
		
	c1=document.createElement("div");
	c1.id="enlargepicbg";
	c1.style.zIndex='10000';
	c1.style.position='absolute';
	c1.style.display='none';
	c1.className='enlargeBackground';
	c1.style.width='100%';
	c1.style.height='100%';
	document.body.appendChild(c1);
	
	c2=document.createElement("div");
	c2.id="enlargepic";
	c2.style.zIndex='10001';
	c2.style.position='absolute';
	c2.style.display='none';

	c2.style.width='100%';
	c2.style.height='100%';
	document.body.appendChild(c2);
	
	t=   '<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" onclick="enlargeclose()"><tr><td align="center">';
	t=t+'<table class="enlarge"><tr><td>';
	if (closeImg!=undefined)
		t=t+'<div class="enlargeClose"><img src="'+closeImg+'" onmouseover="mover(this)" style="cursor: pointer"></div>';
	t=t+'<img id="enlargepic2" alt="" class="enlargeImage" style="cursor: pointer;" onclick="enlargeclose()">';
	t=t+'<div>';
	if (prevImg!=undefined)
		t=t+'<div class="enlargePrev"><a onfocus="blur()" id="enlargePrev"><img onmouseover="mover(this)" src="'+prevImg+'" border="0"></a></div>';
	if (nextImg!=undefined)
		t=t+'<div class="enlargeNext"><a onfocus="blur()" id="enlargeNext"><img src="'+nextImg+'" onmouseover="mover(this)" border="0"></a></div>';
	t=t+'</div>';
	t=t+'</td></tr></table>';
	t=t+'</td></tr></table>';	
	document.getElementById("enlargepic").innerHTML=t;
}

