//document.onselectstart=new Function ("return false");

var client;
var box;
var ajaxTarget;
var opa = 100;
var divToFade = "container";
var IE_divToFade = "content";
var slideH, slideW;
var curH, curW;
var timerF, timerS, timerT;
var inc = 10;
var pageW, preview;
var captBoxHeight;
var capt;

function setSlide()
{
	document.getElementById('slidebox').style.left = Math.round((document.body.offsetWidth-192)/2)+'px';
}
function createClient()
{
	try
	{
		client = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch (e)
	{
		alert("Sorry, your browser is not AJAX-enabled!"); 
	}
}

function boxEvent(page, target)
{
	var tDate = new Date();
	uVal = tDate.getTime();
	ajaxTarget = target;
	createClient();
	client.onreadystatechange = callback;
	client.open("get",page+"&x="+uVal,true);
	client.send(null);
}

function callback()
{
	if (client.readyState == 4 && client.status == 200)
		document.getElementById(ajaxTarget).innerHTML = client.responseText;
}

function showBox(php, id, w)
{
	IE_divToFade = "container";
	pageW = document.body.offsetWidth;
	timerF = window.setTimeout('fadeBackground()',1);
	var box = document.getElementById('popupbox');
	var cnt = document.getElementById('popupcontents');
	cnt.innerHTML = "";
	if(document.body.scrollTop)
		box.style.top = (document.body.scrollTop + 50) + 'px';
	else
		box.style.top = (document.documentElement.scrollTop + 50) + 'px';
	box.style.display = 'none';
	box.style.left = Math.round((document.body.offsetWidth-w)/2)+'px';
	box.style.width = w + 'px';
	cnt.style.width = (w-40) + 'px';
	cnt.innerHTML = "loading";
	box.style.display='block';
	boxEvent("ajaxEvents/" + php + ".php?id="+id, "popupcontents");
}
function showBox2(php, id, w)
{
	IE_divToFade = "container";
	pageW = document.body.offsetWidth;
	timerF = window.setTimeout('fadeBackground()',1);
	var box = document.getElementById('popupbox2');
	var cnt = document.getElementById('popupcontents2');
	cnt.innerHTML = "";
	if(document.body.scrollTop)
		box.style.top = (document.body.scrollTop + 50) + 'px';
	else
		box.style.top = (document.documentElement.scrollTop + 50) + 'px';
	box.style.display = 'none';
	box.style.left = Math.round((document.body.offsetWidth-w)/2)+'px';
	box.style.width = w + 'px';
	cnt.style.width = w + 'px';
	cnt.innerHTML = "loading";
	box.style.display='block';
	boxEvent("ajaxEvents/" + php + ".php?id="+id, "popupcontents2");
}

function resizeSlide()
{
	var changed = false;
	if (curW != slideW)
	{
		if (curW < slideW)
			curW = (curW+inc)>slideW?slideW:(curW+inc);
		else
			curW = (curW-inc)<slideW?slideW:(curW-inc);
		document.getElementById('pic').style.width = curW + 'px';
		document.getElementById('slidebox').style.left = Math.round((pageW-curW)/2)+'px';
		changed = true;
	}
	if (curH != slideH)
	{
		if (curH < slideH)
			curH = (curH+inc)>slideH?slideH:(curH+inc);
		else
			curH = (curH-inc)<slideH?slideH:(curH-inc);
		document.getElementById('pic').style.height = (curH+0) + 'px';
		document.getElementById('next').style.top = ((curH+14)/2) + 'px';
		document.getElementById('prev').style.top = ((curH+14)/2) + 'px';
		if (capt == "s")
		{
			document.getElementById('captSide').style.top = Math.round((curH)*.75) + 'px';
		}
		changed = true;
	}
	if (changed)
		timerS = window.setTimeout('resizeSlide()',1);
	else
	{
		document.getElementById('slidebox').style.display='block';
		document.getElementById('slidePic').style.display='block';
		if (capt == "b")
			document.getElementById('captBottom').style.display='block';
		else
			document.getElementById('captSide').style.display='block';
	}
}

function loadPic(val)
{
	if (!preview)
	{
		curPic += val;
		if (curPic == pix.length)
			curPic = 0;
		if (curPic < 0)
			curPic = pix.length-1;
		showSlide(curPic);
	}
}

function hideBox()
{
	opa = 100;
	document.getElementById('popupbox').style.display = 'none';
	if (document.getElementById(divToFade).filters)
		document.getElementById(divToFade).style.removeAttribute('filter');
	else if (document.getElementById(divToFade).style.opacity)
		document.getElementById(divToFade).style.opacity = 1;
}
function hideBox2()
{
	opa = 100;
	document.getElementById('popupbox2').style.display = 'none';
	if (document.getElementById(divToFade).filters)
		document.getElementById(divToFade).style.removeAttribute('filter');
	else if (document.getElementById(divToFade).style.opacity)
		document.getElementById(divToFade).style.opacity = 1;
}

function hideSlide()
{
	opa = 100;
	document.getElementById('slidebox').style.display = 'none';
	if (document.getElementById(divToFade).filters)
		document.getElementById(IE_divToFade).style.removeAttribute('filter');
	else if (document.getElementById(divToFade).style.opacity)
		document.getElementById(divToFade).style.opacity = 1;
}

function hidePopup()
{
	opa = 100;
	document.getElementById('popupbox').style.display = 'none';
	if (document.getElementById(divToFade).filters)
	{
		document.getElementById(IE_divToFade1).style.removeAttribute('filter');
		document.getElementById(IE_divToFade2).style.removeAttribute('filter');
	}
	else if (document.getElementById(divToFade).style.opacity)
		document.getElementById(divToFade).style.opacity = 1;
}

function fadeBackground()
{
	if (opa > 30)
		opa-=5;
	if (document.getElementById(divToFade).filters)
		document.getElementById(IE_divToFade).style.filter="alpha(opacity="+opa+")";
	else if (document.getElementById(divToFade).style.opacity)
		document.getElementById(divToFade).style.opacity = (opa/100);
	if (opa > 30)
		timerF=window.setTimeout('fadeBackground()',1)
}

function toggleDiv(divid, val)
{
	val = val?"visible":"hidden";
	document.getElementById(divid).style.visibility = val;
}

function showImage(pid)
{
	preview = false;
	document.getElementById('slidebox').style.display='block';
	document.getElementById('slidePic').style.display='block';
	showSlide(pid);
}

function previewSlide(ppic, pw, ph, pcapt)
{
	preview = true;
	pageW = document.body.offsetWidth;
	timerF = window.setTimeout('fadeBackground()',1);
	var pic = document.getElementById('pic');
	slideH = ph;
	slideW = pw;
	curH = parseInt(pic.style.height);
	curW = parseInt(pic.style.width);
	document.getElementById('capt').innerHTML=pcapt;
	document.getElementById('slidePic').style.display='none';
	document.getElementById('slidePic').width=pw;
	document.getElementById('slidePic').height=ph;
	document.getElementById('slidePic').src=ppic;
	timerS = window.setTimeout('resizeSlide()',1);
}
function showSlide(pid)
{
	curPic = pid;
	pageW = document.body.offsetWidth;
	timerF = window.setTimeout('fadeBackground()',1);
	var box = document.getElementById('slidebox');
	var pic = document.getElementById('pic');
	var w = pix[pid][1];
	var h = pix[pid][2];
	capt = w>h?"b":"s";
	if (capt=="b")
	{
		document.getElementById('captSide').style.display='none';
		document.getElementById('captBottom').style.display='block';
		document.getElementById('captBottom').style.width = w + 'px';
		document.getElementById('captBottom').innerHTML=pix[pid][3];
		document.getElementById('captBottom').style.height = '0px';
		captBoxHeight = document.getElementById('captBottom').scrollHeight;
		document.getElementById('captBottom').style.display='none';
		document.getElementById('captBottom').style.height = captBoxHeight + 'px';
		slideH = h + captBoxHeight + 2;
	}
	else
	{
		document.getElementById('captBottom').style.display='none';
		document.getElementById('captSide').style.display='none';
		document.getElementById('captSide').innerHTML=pix[pid][3];
		slideH = h;
	}
	slideW = w;
	curH = parseInt(pic.style.height);
	curW = parseInt(pic.style.width);
	timerS = window.setTimeout('resizeSlide()',1);
	document.getElementById('slidePic').style.display='none';
	document.getElementById('slidePic').src='/images/nav/blank.png';
	document.getElementById('slidePic').width=w;
	document.getElementById('slidePic').height=h;
	document.getElementById('slidePic').src=pix[pid][0];
}

