var incPicB = 0;
var bReady1 = false;
var bReady2 = false;
function countPicB() {
	incPicB++;
	if (incPicB >= arrPicB.length) bReady1 = true;
}
var nIndexB = -1;
var nWidth = 1;
var nSpace = 23;
var marginL = 0;
var marginT = 0;
var imgLoad;
var bn = 10;
var imgRadio0 = "../images/radio0.gif";
var imgRadio1 = "../images/radio1.gif";
var dn = 0;
var curLnk = -1;
var g_btnNext1 = new Image();
g_btnNext1.src = "../images/btn_next1.jpg";
var g_btnNext0 = new Image();
g_btnNext0.src = "../images/btn_next0.jpg";
var g_btnBack1 = new Image();
g_btnBack1.src = "../images/btn_back1.jpg";
var g_btnBack0 = new Image();
g_btnBack0.src = "../images/btn_back0.jpg";

function init() {
	fox = new RegExp("Firefox","i");
	cent = document.body.clientWidth / 2;
	IE = document.all ? true : false;
	fox = new RegExp("Firefox","i");
	if (IE || fox.test(navigator.userAgent)) {
		halfX = document.body.clientWidth / 2;
		halfY = document.body.clientHeight / 2;
		fullX = document.body.clientWidth;
		fullY =document.body.clientHeight;
	}
	else {
		halfX = pageXOffset / 2;
		halfY = pageYOffset / 2;
		fullX = pageXOffset;
		fullY = pageYOffset;
	}
	filterz = document.getElementById("filterz");
	board = document.getElementById("board");
	board4 = document.getElementById("board4");
	if (fox.test(navigator.userAgent)) {
		marginL = cent - 88;
		marginT = 350;
	}
	else {
		marginL = cent - 88;
		marginT = 335;
	}
	if (getDayNight() == 1) {
		document.getElementById("boardspace").style.backgroundImage = "url(Board_night.jpg)";
		document.getElementById("imgMainB").src = "bgboard2.jpg";
		dn = 1;
	}
	else {
		document.getElementById("boardspace").style.backgroundImage = "url(Board_day.jpg)";
		document.getElementById("imgMainB").src = "bgboard.jpg";
		dn = 0;
	}
	setTimeout("changePicB()",3000);
}

function btnOver(n,obj) {
	if (n == 2) obj.src = g_btnNext1.src;
	else if (n == 1) obj.src = g_btnBack1.src;
}

function btnOut(n,obj) {
	if (n == 2) obj.src = g_btnNext0.src;
	else if (n == 1) obj.src = g_btnBack0.src;
}

function getDayNight() {
	d = new Date();
	hh = d.getHours();
	reval = 0;
	if (hh >= 18 || hh < 6) return 1;
	return 0;
}

function changePicB() {
	nIndexB++;
	if (nIndexB >= arrPicB.length) nIndexB = 0;
	imgLoad = new Image();
	imgLoad.onload = loaded;
	imgLoad.src = "imgboard.php?dn=" + dn + "&fn=" + arrPicB[nIndexB];
}

function loaded() {
	for (i = 0;i < bn;i++) {
		bx = document.getElementById("b" + i);
		bx.style.backgroundImage = "url(imgboard.php?dn=" + dn + "&fn=" + arrPicB[nIndexB] + ")";
		posx = 0 - (i * nSpace);
		bx.style.backgroundPosition = posx + " 0";
		bx.style.top = marginT;
		bx.style.left = marginL + (i * nSpace);
		bx.style.width = 1;
	}
	nWidth = 1;
	expanding();
}

function showPicB() {
	showPic(this.ind);
}

function expanding() {
	nWidth += 1;
	if (nWidth > nSpace) {
		document.getElementById("imgMainB").src = imgLoad.src;
		document.getElementById("imgMainB").ind = nIndexB;
		document.getElementById("imgMainB").onclick = showPicB;
		document.getElementById("imgMainB").style.cursor = "pointer";
		for (i = 0;i < bn;i++) {
			bx = document.getElementById("b" + i);
			bx.style.left = -500;
		}
		setTimeout("changePicB()",5000);
		return;
	}
	for (i = 0;i < bn;i++) {
		bx = document.getElementById("b" + i);
		bx.style.width = nWidth;
	}
	setTimeout("expanding()",20);
}
function radioc(n) {
	if (n == nSel) return;
	nSel = n;
	if (n == 1) {
		document.getElementById("radi1").src = imgRadio1;
		document.getElementById("radi2").src = imgRadio0;
	}
	else {
		document.getElementById("radi2").src = imgRadio1;
		document.getElementById("radi1").src = imgRadio0;
	}
	document.forms["formPage2"].type.value = n;
	document.forms["formPage2"].submit();
}
function hlLnk(n) {
	if (curLnk >= 0) document.getElementById("lnk" + curLnk).style.backgroundColor = "";
	document.getElementById("lnk" + n).style.backgroundColor = "#bc1817";
	curLnk = n;
}

var nShift = 0;
var fs;
var sliding = false;
function slideNext() {
	if (sliding) return;
	nShift = 0;
	fs = window.frames["frameSlide"];
	sliding = true;
	slidingNext();
}
function slideBack() {
	if (sliding) return;
	nShift = 0;
	fs = window.frames["frameSlide"];
	sliding = true;
	slidingBack();
}
function slidingNext() {
	if (!sliding) return;
	fs.scrollBy(nShift,0);
	if (nShift < 50) nShift++;
	setTimeout("slidingNext()",20);
}
function slidingBack() {
	if (!sliding) return;
	fs.scrollBy(nShift,0);
	if (nShift > -50) nShift--;
	setTimeout("slidingBack()",20);
}

var frameShow;
var arrPic;
var nCount = 0;
var nIndexOld = -1;
var nIndex = 0;
var nPageWidth = 0;
var nPageHeight = 900;
var centerY = 350;
var nAlpha = 0;
var nAlpha2 = 0;
var nLeft = 0;
var nTop = 0;
var newPosX = 0;
var newPosY = 0;
var filterz;
var board;
var board4;
var halfX = 0;
var halfY = 0;
var fullX = 0;
var fullY = 0;
var lmt;
var imgC;
var IE;
var fdir = "advs/";
var imgLoading = new Image();
imgLoading.src = "../images/loading.gif";
var bNoCount = false;

function setAlpha(obj,per) {
	inone = per / 100;
	if (inone >= 1) inone = 0.99;
	obj.style.opacity = inone;
	obj.style.MozOpacity = inone;
	obj.style.KhtmlOpacity = per / 100;
	obj.style.filter = "alpha(opacity=" + per + ")";
}
function setSize(n) {
	nCount = 0;
	arrPic = new Array(n);
	if (n == 0) {
		board.style.left = -5000;
		filterz.style.left = 0 - parseInt(filterz.style.width);
	}
}
function counting() {
	nCount++;
	if (document.getElementById("strLoading") != null) {
		document.getElementById("strLoading").innerHTML = "Picture " +  nCount + " of " + arrPic.length;
		if (nCount >= arrPic.length) {
			board.style.left = -5000;
			filterz.style.left = 0 - parseInt(filterz.style.width);
			bReady2 = true;
		}
	}
	else if (document.getElementById("board")) {
		document.getElementById("board").style.left = -5000;
		document.getElementById("filterz").style.left = -5000;
	}
	else {
		bNoCount = true;
	}
}
function setPic(n,name,desc) {
	arrPic[n] = new Image();
	arrPic[n].onload = counting;
	arrPic[n].src = fdir + name;
	arrPic[n].desc = desc;
}
function prepare() {
	IE = document.all ? true : false;
	fox = new RegExp("Firefox","i");
	if (IE || fox.test(navigator.userAgent)) {
		halfX = document.body.clientWidth / 2;
		halfY = document.body.clientHeight / 2;
		fullX = document.body.clientWidth;
		fullY =document.body.clientHeight;
	}
	else {
		halfX = pageXOffset / 2;
		halfY = pageYOffset / 2;
		fullX = pageXOffset;
		fullY = pageYOffset;
	}
	filterz = document.getElementById("filterz");
	board = document.getElementById("board");
	board4 = document.getElementById("board4");
	//frameShow = document.getElementById("frameSlide");
	blacking();
	//frameShow.onload = function() {
		//alert("give me");
		//frameShow.contentWindow.giveMe();
	//}
	//frameShow.src = "slide.php";
}
function cngPage(n) {
	blacking();
	document.forms["cngP"].page.value = n;
	document.forms["cngP"].submit();
}
function blacking() {
	setAlpha(filterz,50);
	filterz.style.left = 0;
	filterz.style.top = 0;
	filterz.style.width = fullX  + nPageWidth;
	filterz.style.height = 800 + nPageHeight;
	board.style.backgroundColor = "#FFFFFF";
	board.style.left = halfX - 200;
	board.style.width = 400;
	board.style.height = 400;
	board.innerHTML = "<table border=\"0\" width=\"400\"><tr><td height=\"400\" valign=\"middle\" align=\"center\"><img src=\"" + imgLoading.src + "\"><br><span id=\"strLoading\">Preparing... </span></td></tr></table>";
	setBoardCenter();
}
function setBoardCenter() {
	if (bReady2) return;
	pikad = halfY - 200 + document.body.scrollTop
	t = parseInt(board.style.top);
	h = Math.abs(pikad - t);
	kt = Math.ceil(20 / 100 * h);
	if (t < pikad) {
		nt = t - 0 + kt;
		if (nt > pikad) nt = pikad;
		board.style.top = nt;
	}
	else if (t > pikad) {
		nt = t - kt;
		if (nt < pikad) nt = pikad;
		board.style.top = nt;
	}
	setTimeout("setBoardCenter()",50);
}
function blackingMore() {
	setAlpha(filterz,nAlpha);
	if (nAlpha >= 80) {
		bReady1 = false;
		bReady2 = false;
		nAlpha = 80;
		board.style.width = board.style.height = "";
		board.innerHTML = "<img src=\"" + arrPic[nIndex].src + "\">";
		board.style.left = halfX - (arrPic[nIndex].width / 2);
		nTop = halfY - halfY - (arrPic[nIndex].height / 2) + centerY;
		if (nTop < 20) nTop = 20;
		board.style.top = nTop;
		board.style.width = arrPic[nIndex].width;
		filterz.align = "right";
		filterz.valign = "top";
		filterz.style.height = 800 + nPageHeight;
		//filterz.innerHTML = "<a href=\"javascript:closer()\"><font color=\"#FFFFFF\" size=\"+2\">close [x]</font></a>";
		board.style.backgroundColor = "#FFFFFF";
		board.style.align = "center";
		strDesc = "";
		if (arrAddr[nIndex] != "") strDesc += " <b>Address:</b> " + arrAddr[nIndex];
		if (arrTel[nIndex] != "") strDesc += " <b>Telephone:</b> " + arrTel[nIndex];
		strDesc += "<br>";
		if (arrEmail[nIndex] != "") strDesc += " <b>Email:</b> <a href=\"mailto:" + arrEmail[nIndex] + "\">" + arrEmail[nIndex] + "</a>";
		if (arrWeb[nIndex] != "") {
			str = arrWeb[nIndex];
			if (str.indexOf("http") == 0) strDesc += " <b>Website:</b> <a href=\"" + str + "\" target=\"_blank\">" + arrWeb[nIndex] + "</a>";
			else strDesc += " <b>Website:</b> <a href=\"http://" + str + "\" target=\"_blank\">" + arrWeb[nIndex] + "</a>";
		}
		board.innerHTML += "<br><font color=\"#000000\" size=\"+1\">" + arrPic[nIndex].desc + "</font><br>" + strDesc + "<br><table border=\"0\" cellspacing=\"2\"><tr><td style=\"cursor:pointer;\" onClick=\"showPrev()\"><img src=\"../images/btn_back0.jpg\" onMouseOver=\"btnOver(1,this)\" onMouseOut=\"btnOut(1,this)\"></td><td width=\"100\" align=\"center\"><a href=\"javascript:closer()\"><img src=\"../images/btn_close.gif\" border=\"0\"></a></td><td style=\"cursor:pointer;\" onClick=\"showNext()\"><img src=\"../images/btn_next0.jpg\" onMouseOver=\"btnOver(2,this)\" onMouseOut=\"btnOut(2,this)\"></td></tr></table>";
		board4.style.width = arrPic[nIndex].width;
		board4.style.top = parseInt(board.style.top) - 20;
		board4.style.left = board.style.left;
		board4.style.height = 20;
		board4.style.backgroundColor = "#FFFFFF";
		return;
	}
	nAlpha += 10;
	setTimeout("blackingMore()",50);
}
function showPic(n) {
	if (curLnk >= 0) document.getElementById("lnk" + curLnk).style.backgroundColor = "";
	document.getElementById("lnk" + n).style.backgroundColor = "#bc1817";
	curLnk = n;
	nIndex = n;
	nAlpha = 0;
	filterz.style.left = 0;
	filterz.style.top = 0;
	filterz.style.width = fullX  + nPageWidth;
	filterz.style.height = fullY + nPageHeight;
	blackingMore();
}
function setStop() {
	//setAlpha(board,100);
	stTop = halfY - (arrPic[nIndex].height / 2) + centerY;
	if (stTop < 20) stTop = 20;
	board.style.top = stTop;
	board.style.left = nLeft;
	board.style.width = arrPic[nIndex].width;
		strDesc = "";
		if (arrAddr[nIndex] != "") strDesc += " <b>Address:</b> " + arrAddr[nIndex];
		if (arrTel[nIndex] != "") strDesc += " <b>Telephone:</b> " + arrTel[nIndex];
		strDesc += "<br>";
		if (arrEmail[nIndex] != "") strDesc += " <b>Email:</b> <a href=\"mailto:" + arrEmail[nIndex] + "\">" + arrEmail[nIndex] + "</a>";
		if (arrWeb[nIndex] != "") {
			str = arrWeb[nIndex];
			if (str.indexOf("http") == 0) strDesc += " <b>Website:</b> <a href=\"" + str + "\" target=\"_blank\">" + arrWeb[nIndex] + "</a>";
			else strDesc += " <b>Website:</b> <a href=\"http://" + str + "\" target=\"_blank\">" + arrWeb[nIndex] + "</a>";
		}
	board.innerHTML += "<br><font color=\"#000000\" size=\"+1\">" + arrPic[nIndex].desc + "</font><br>" + strDesc + "<br><table border=\"0\" cellspacing=\"2\"><tr><td style=\"cursor:pointer;\" onClick=\"showPrev()\"><img src=\"../images/btn_back0.jpg\" onMouseOver=\"btnOver(1,this)\" onMouseOut=\"btnOut(1,this)\"></td><td width=\"100\" align=\"center\"><a href=\"javascript:closer()\"><img src=\"../images/btn_close.gif\" border=\"0\"></a></td><td style=\"cursor:pointer;\" onClick=\"showNext()\"><img src=\"../images/btn_next0.jpg\" onMouseOver=\"btnOver(2,this)\" onMouseOut=\"btnOut(2,this)\"></td></tr></table>";
	board4.style.left = board.style.left;
	board4.style.width = arrPic[nIndex].width;
	board4.style.top = parseInt(board.style.top) - 20;
}
function showNext() {
	index = nIndex + 1;
	if (index >= arrPic.length) index = 0;
	document.getElementById("lnk" + curLnk).style.backgroundColor = "";
	document.getElementById("lnk" + index).style.backgroundColor = "#bc1817";
	curLnk = index;
	w = arrPic[index].width;
	h = arrPic[index].height;
	board4.style.top = -30;
	board.innerHTML = "<img src=\"" + arrPic[nIndex].src + "\" id=\"imgC\">";
	board.style.top = halfY - (arrPic[nIndex].height / 2) + centerY;
	board.style.width = "";
	newPosX = parseInt(board.style.left);
	newPosY = parseInt(board.style.top);
	nLeft = halfX - (w / 2);
	nTop = halfY - (h / 2);
	if (nTop < 20) nTop = 20;
	nAlpha = 100;
	imgC = document.getElementById("imgC");
	nIndex = index;
	fadeOut();
}
function fadeOut() {
	setAlpha(imgC,nAlpha);
	if (nAlpha <= 0) {
		nAlpha = 0;
		setAlpha(imgC,0);
		//imgC.src = arrPic[nIndex].src;
		//setAlpha(imgC,100);
		sizing();
		return;
	}
	nAlpha -= 5;
	setTimeout("fadeOut()",20);
}
function sizing() {
	ktw = arrPic[nIndex].width - imgC.width;
	kth = arrPic[nIndex].height - imgC.height;
	nPlus = 3;
	if (Math.abs(ktw) > 20 || Math.abs(kth) > 20) nPlus = 20;
	if (ktw == 0 && kth == 0) {
		imgC.src = arrPic[nIndex].src;
		fadeIn();
		return;
	}
	if (arrPic[nIndex].width > imgC.width) {
		imgC.width += nPlus;
		if (imgC.width > arrPic[nIndex].width) imgC.width = arrPic[nIndex].width;
	}
	else if (arrPic[nIndex].width < imgC.width) {
		imgC.width -= nPlus;
		if (imgC.width < arrPic[nIndex].width) imgC.width = arrPic[nIndex].width;
	}
	if (arrPic[nIndex].height > imgC.height) {
		imgC.height += nPlus;
		if (imgC.height > arrPic[nIndex].height) imgC.height = arrPic[nIndex].height;
	}
	else if (arrPic[nIndex].height < imgC.height) {
		imgC.height -= nPlus;
		if (imgC.height < arrPic[nIndex].height) imgC.height = arrPic[nIndex].height;
	}
	board.style.left = halfX - (imgC.width / 2);
	stTop = halfY - (imgC.height / 2) + centerY;
	if (stTop < 20) stTop = 20;
	board.style.top = stTop;
	setTimeout("sizing()",20);
}
function fadeIn() {
	setAlpha(imgC,nAlpha);
	if (nAlpha >= 100) {
		nAlpha = 100;
		setAlpha(imgC,100);
		setStop();
		return;
	}
	nAlpha += 5;
	setTimeout("fadeIn()",20);
}
function showPrev() {
	index = nIndex - 1;
	if (index < 0) index = arrPic.length - 1;
	document.getElementById("lnk" + curLnk).style.backgroundColor = "";
	document.getElementById("lnk" + index).style.backgroundColor = "#bc1817";
	curLnk = index;
	w = arrPic[index].width;
	h = arrPic[index].height;
	board4.style.top = -30;
	board.innerHTML = "<img src=\"" + arrPic[nIndex].src + "\" id=\"imgC\">";
	board.style.top = halfY - (arrPic[nIndex].height / 2) + centerY;
	board.style.width = "";
	newPosX = parseInt(board.style.left);
	newPosY = parseInt(board.style.top);
	nLeft = halfX - (w / 2);
	nTop = halfY - (h / 2);
	if (nTop < 20) nTop = 20;
	nAlpha = 100;
	imgC = document.getElementById("imgC");
	nIndex = index;
	fadeOut();
}
function closer() {
	board4.style.top = -30;
	lmt = fullX - 20;
	board.style.width = arrPic[nIndex].width;
	board.style.height = arrPic[nIndex].height / 2;
	board.innerHTML = "";
	nAlpha = 100;
	closing();
}
function closing() {
	nSizeW = parseInt(board.style.width);
	nSizeH = parseInt(board.style.height);
	nPlusW = 30;
	nPlusH = 20;
	if (nSizeW > lmt) {
		nPlusW = 5;
		nAlpha -= 20;
		if (nAlpha < 0) nAlpha = 0;
		setAlpha(board,nAlpha);
	}
	if (nSizeH < 20) nPlusH = 2;
	newy = nSizeH - nPlusH;
	newx = nSizeW + nPlusW;
	if (newy < 1) newy = 1;
	if (newx >= fullX) newx = fullX;
	board.style.left = halfX - (nSizeW / 2);
	board.style.top = halfY - (nSizeH / 2) + centerY;
	board.style.height = newy;
	board.style.width = newx;
	if (newx >= fullX) {
		board.style.left = -5000;
		filterz.style.left = 0 - parseInt(filterz.style.width);
		setAlpha(board,100);
		return;
	}
	setTimeout("closing()",20);
}
function rePage(cat,type,az) {
	f = document.forms["formPage"];
	f.cat.value = cat;
	f.type.value = type;
	f.az.value = az;
	f.submit();
}
function urlencode(str) {
str = escape(str);
str = str.replace('+', '%2B');
str = str.replace('%20', '+');
str = str.replace('*', '%2A');
str = str.replace('/', '%2F');
str = str.replace('@', '%40');
return str;
}

function urldecode(str) {
str = str.replace('+', ' ');
str = unescape(str);
return str;
}

