var p_height = 0;
var p_top = 0;
var p_increment = 0;
var btn_flash = 0;
var btn_flash_id = 0;
var cursection = 0;
var cursubpage = 0;
var GALLERYPAGE = 1;
var GALLERYSECT = 5;
var HLNOVELPAGE = 2;
var HLNOVELSECT = 5;
var CONTACTSECT = 9;

function ChangePage(section, subpage)
{
	if(!section || isNaN(section)){section = 0;}
	if(!subpage || isNaN(subpage)){subpage = 0;}
	
	StartPageScroll(section, subpage);
}
function GetPage(section, subpage)
{
	FlashButton(section);
	var xmlHttp;
	try {xmlHttp=new XMLHttpRequest();}
	catch (e) {try {xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
	catch (e) {try {xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
	catch (e) {alert("Your browser does not support AJAX!"); return false;}}}
	xmlHttp.onreadystatechange=function()
	{
		if (xmlHttp.readyState==4)
		{
			var response = xmlHttp.responseText;
			document.getElementById('content').innerHTML=response;
			p_height = document.getElementById('content').offsetHeight + 48;
			p_top = 0 - p_height;
			document.getElementById('pagediv').style.height = p_height.toString() + 'px';
			document.getElementById('pagediv').style.top = p_top.toString() + 'px';
			p_increment = parseInt((p_height / 16).toString());
			cursection = section;
			cursubpage = subpage;
			issamepage = 1;
			SetNavButtons(section, subpage);
			if (section == GALLERYSECT && subpage == GALLERYPAGE){InitGallery();}
			if (section == CONTACTSECT){InitContact();}
			ScrollPageDown();
		}
	}
	xmlHttp.open("GET",'ajaxpage.php?s='+section+'&p='+subpage, true);xmlHttp.send(null); 
}
function StartPageScroll(section, subpage)
{
	if (document.getElementById('pagediv'))
	{
		document.getElementById('pagediv').style.zIndex = -1;
		//document.getElementById('content').style.zIndex = -1;
		var pagediv = document.getElementById('pagediv');
		p_height = pagediv.offsetHeight - 16;
		p_increment = parseInt((p_height / 16).toString());
		p_top = parseInt(pagediv.style.top.replace(/\D/g, ""));
		setTimeout("ScrollPageUp("+section+", "+subpage+")", 31);
	}
}
function ScrollPageUp(section, subpage)
{
	if (document.getElementById('pagediv'))
	{
		var pagediv = document.getElementById('pagediv');
		p_top -= p_increment;
		if (p_top > (4 - p_height))
		{
			pagediv.style.top = p_top.toString()+"px";
			setTimeout("ScrollPageUp("+section+", "+subpage+")", 31);
		}else
		{
			p_top = 4 - p_height;
			pagediv.style.top = p_top.toString()+"px";
			GetPage(section, subpage);
		}
		//document.getElementById("debug").innerHTML = pagediv.style.top;
	}
}
function ScrollPageDown()
{
	if (document.getElementById('pagediv'))
	{
		var pagediv = document.getElementById('pagediv');
		p_top += p_increment;
		if (p_top < 0)
		{
			pagediv.style.top = p_top.toString()+"px";
			setTimeout("ScrollPageDown()", 31);
		}else
		{
			p_top = 0;
			pagediv.style.top = p_top.toString()+"px";
			document.getElementById('pagediv').style.zIndex = 0;
			//document.getElementById('content').style.zIndex = 0;
		}
		//document.getElementById("debug").innerHTML = pagediv.style.top;
	}
}
function SetNavButtons(section, subpage)
{
	var divid = 0;
	var curHTML = '';
	var titles = new Array(9);
	var labels = new Array(9);
	titles[0] = 'home'; titles[1] = 'club info'; titles[2] = 'features'; titles[3] = 'events'; titles[4] = 'member art'; titles[5] = 'reviews'; titles[6] = 'archives'; titles[7] = 'links'; titles[8] = 'contact';
	labels[0] = 'Home'; labels[1] = 'Club Info'; labels[2] = 'Features'; labels[3] = 'Events'; labels[4] = 'Member Art'; labels[5] = 'Reviews'; labels[6] = 'Archives'; labels[7] = 'Links'; labels[8] = 'Contact';
	
	btn_flash = 0;
	
	switch (section)
	{
		case 1:
			divid = document.getElementById("btnd01");
			break;
		case 2:
			divid = document.getElementById("btnd02");
			break;
		case 3:
			divid = document.getElementById("btnd03");
			break;
		case 4:
			divid = document.getElementById("btnd04");
			break;
		case 5:
			divid = document.getElementById("btnd05");
			break;
		case 6:
			divid = document.getElementById("btnd06");
			break;
		case 7:
			divid = document.getElementById("btnd07");
			break;
		case 8:
			divid = document.getElementById("btnd08");
			break;
		case 9:
			divid = document.getElementById("btnd09");
			break;
	}
	for (i = 1; i < 10; i++)
	{
		if (document.getElementById("btnd0"+i.toString()))
		{
			curHTML = '<a id="btn0'+i.toString()+'" href="javascript:ChangePage('+i.toString()+')" title="'+titles[i-1]+'" onmouseover="ShowMenu('+i+',0,0);"><span>'+labels[i-1]+'</span></a>';
			document.getElementById("btnd0"+i.toString()).innerHTML = curHTML;
		}
	}
	if (divid)
	{
		if (divid.innerHTML)
		{
			divid.innerHTML = '<img alt="'+titles[section-1]+': you are here" src="images/nbtn0'+section.toString()+'a.png" style="width: 79px; height: 22px" onmouseover="ShowMenu('+section+','+cursubpage+',1);">';
		}
	}
	SetMenuButtons();
}

function SetMenuButtons()
{
	var curid = 'sbtnd_'+cursection.toString()+'_'+cursubpage.toString();
	if (cursubpage == 0){curid = 'sbtnd_0_0';}
	if (document.getElementById(curid))
	{
		var xmlHttp;
		try {xmlHttp=new XMLHttpRequest();}
		catch (e) {try {xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
		catch (e) {try {xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
		catch (e) {alert("Your browser does not support AJAX!"); return false;}}}
		xmlHttp.onreadystatechange=function()
		{
			if (xmlHttp.readyState==4)
			{
				document.getElementById('sbarnav').innerHTML=xmlHttp.responseText;
				if (document.getElementById('sbarbtns'))
				{document.getElementById('sbarnav').style.height = document.getElementById('sbarbtns').offsetHeight+'px';}
				else{document.getElementById('sbarnav').style.height = '16px';}
			}
		}
		xmlHttp.open("GET",'ajaxsbar.php?s='+cursection+'&p='+cursubpage+'&a='+issamepage, true);xmlHttp.send(null); 
		//document.getElementById(curid).innerHTML = '<img alt="you are here" src="images/sbtn_'+cursection.toString()+'_'+cursubpage.toString()+'_a.png" style="width: 166px; height: 22px">';
	}
}

function FlashButton(section)
{
	if (section > 0 && section < 10)
	{
		btn_flash_id = section;
		btn_flash = 2;
		DoBtnFlash();
	}
}
function DoBtnFlash()
{
	if (!document.getElementById("btn0"+btn_flash_id.toString())){return;}
	if (btn_flash == 1)
	{
		document.getElementById("btn0"+btn_flash_id.toString()).style.backgroundPosition = '0 0';
		btn_flash = 2;
		setTimeout("DoBtnFlash()", 500);
	}else{if (btn_flash == 2)
	{
		document.getElementById("btn0"+btn_flash_id.toString()).style.backgroundPosition = '0 -22px';
		btn_flash = 1;
		setTimeout("DoBtnFlash()", 500);		
	}else
	{
		document.getElementById("btn0"+btn_flash_id.toString()).style.backgroundPosition = '0 0';
	}}
}
