var doScroll = 0;
var startScroll = 0;
var sloScroll = 0;
var curpos = 0;
var increment = 1;
var gfile = '';
var gwidth = 0;
var gheight = 0;

function InitGallery()
{
	curpos = document.getElementById('gallerydiv').style.left;
	curpos = curpos.replace(/\D/g, '');
	document.getElementById('gallerydiv').style.width = document.getElementById('tbl').offsetWidth+'px';
}

function StartScrollLeft()
{
	startScroll = 1;
	doScroll = 1;
	setTimeout("ScrollLeft()", 20);
}

function ScrollLeft()
{
	var curstop = document.getElementById('gallerydiv').offsetWidth;
	if (curpos <= 0 && doScroll)
	{
		curpos += increment;
		if (increment < 64){increment++;}
		document.getElementById('gallerydiv').style.left = curpos.toString()+'px';
		startScroll = 0;
		setTimeout("ScrollLeft()", 20);
	}else
	{
		startScroll = 0;
		sloScroll = 1;
		StopScroll();
	}
}

function StartScrollRight()
{
	startScroll = 2;
	doScroll = 2;
	setTimeout("ScrollRight()", 20);
}

function ScrollRight()
{
	var curstop = document.getElementById('gallerydiv').offsetWidth;
	if (curpos >= ((0 - curstop) + 640) && doScroll)
	{
		curpos -= increment;
		if (increment < 64){increment++;}
		document.getElementById('gallerydiv').style.left = curpos.toString()+'px';
		startScroll = 0;
		setTimeout("ScrollRight()", 20);
	}else
	{
		startScroll = 0;
		sloScroll = 2;
		StopScroll();
	}
}

function StopScroll()
{
	if (startScroll){sloScroll = 0; increment = 1; return;}
	if (doScroll)
	{
		doScroll = 0;
		increment -= 4;
		setTimeout("StopScroll()", 10);

	}else
	{
		if (increment > 1)
		{
			if (sloScroll == 1)
			{
				curpos += increment;
				if (curpos > 0){curpos = 0;}
			}else{if(sloScroll == 2)
			{
				var curstop = document.getElementById('gallerydiv').offsetWidth;
				curpos -= increment;
				increment--;
				if (curpos < ((0 - curstop) + 640)){curpos = (0 - curstop) + 640;}
			}else
			{
				sloScroll = 0;
				increment = 1;
				return;
			}}
			increment--;
			document.getElementById('gallerydiv').style.left = curpos.toString()+'px';
			setTimeout("StopScroll()", 10);
		}else
		{
			sloScroll = 0;
			increment = 1;
		}
	}
}

function HoverImg(id)
{
	if (!id){return;}
	var curimg = 	document.getElementById("timg"+id).style;
	curimg.borderStyle = "solid";
	curimg.borderWidth = "2px";
	curimg.borderColor = "#E0A040";
	curimg.marginRight = "4px";
	//document.getElementById("timg"+id).style = curimg;
}

function UnhoverImg(id)
{
	if (!id){return;}
	var curimg = 	document.getElementById("timg"+id).style;
	curimg.borderStyle = "none";
	curimg.borderWidth = "0";
	curimg.borderColor = "#000000";
	curimg.marginRight = "8px";
	//document.getElementById("timg"+id).style = curimg;
}

function ShowImage(file, width, height, title, description)
{
	if (!file || !width || !height){return;}
	if (title){document.getElementById('mainttl').innerHTML = title.replace(/\\\'/, "&#39;");}else{document.getElementById('mainttl').innerHTML = '';}
	if (description){document.getElementById('maindsc').innerHTML = description.replace(/\\\'/, "&#39;");}else{document.getElementById('maindsc').innerHTML = '';}
	document.getElementById('mainimg').src = 'images/gallery/images/'+file;
	document.getElementById('mainimg').style.width = width+'px';
	document.getElementById('mainimg').style.height = height+'px';
	gfile = file; gwidth = width; gheight = height;
}

function SepImage()
{
	if (!gfile || !gwidth || !gheight){return;}
	window.open("images/gallery/images/"+gfile, gfile, "status=0, toolbar=0, location=0, menubar=0, directories=0, resizable=1, scrollbars=1, width="+gwidth+", height="+gheight);
}

function ShowStory(id)
{
	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('storydiv').innerHTML=response;
			document.getElementById('storylist').style.display = 'none';
		}
	}
	xmlHttp.open("GET",'ajaxhnovel.php?i='+id, true);xmlHttp.send(null); 

}

function HideStory()
{
	document.getElementById('storydiv').innerHTML='';
	document.getElementById('storylist').style.display = '';
}

