
var adcard_showing = 0;

function rotatebanner(image)
{
	if (image < images_banners.length-1) { image++; } else { image=0; }
	get("bannerslide").style.backgroundImage = "url('"+images_banners[image].src+"')";
	setTimeout("rotatebanner_move('"+image+"',900,0)",10);
}

function rotatebanner_move(image, ph, pv)
{
	var b = get("bannerslide");
	ph-=50;
	pv+=0;

	if (ph<=0)
	{ 
		ph=0;
		pv=0;
		get("banner").style.backgroundImage = "url('"+images_banners[image].src+"')";
		b.style.backgroundPosition = "900px 0px";
		setTimeout("rotatebanner("+image+")", 7000);
	}
	else
	{
		b.style.backgroundPosition = ph+"px "+pv+"px";
		setTimeout("rotatebanner_move('"+image+"',"+ph+","+pv+")", 25);
	}
}

function rotateadcard(image)
{
	if (image < images_adcards.length-1) { image++; } else { image=0; }
	get("adcardslide").style.backgroundImage = "url('"+images_adcards[image].src+"')";
	setTimeout("rotateadcard_move('"+image+"',900,0)",10);
}

function rotateadcard_move(image, ph, pv)
{
	var b = get("adcardslide");
	ph-=50;
	pv+=0;

	if (ph<=0)
	{ 
		ph=0;
		pv=0;
		get("adcard").style.backgroundImage = "url('"+images_adcards[image].src+"')";
		get("adcard_subpage_content").innerHTML = get("subpage_"+image).innerHTML;
		b.style.backgroundPosition = "900px 0px";
		adcard_showing = image;
		
		if (striphtml(get("subpage_"+image).innerHTML)=="")
		{ get("adcard_left").style.display = "none"; }
		else { get("adcard_left").style.display = "block"; }

		setTimeout("rotateadcard("+image+")", 5000);
	}
	else
	{
		b.style.backgroundPosition = ph+"px "+pv+"px";
		setTimeout("rotateadcard_move('"+image+"',"+ph+","+pv+")", 25);
	}
}

function follow_adcard_link()
{ if (links_adcards[adcard_showing]!="") { document.location = links_adcards[adcard_showing]; } }

function load_subpage(sp)
{
	if (get('page_content'))
	{ get('page_content').innerHTML=''+get('subpage_'+sp).innerHTML+'<br />'; }

	if (get('page_description'))
	{ get('page_description').innerHTML=''+(get('subpage_desc_'+sp).innerHTML)+'<br />'; }
}

function hlist_init(id)
{
	var list = document.getElementById(id);
	var width = 280;
	
	for (i=0;i<list.childNodes.length;i++) // remove junk
	{ 
		if (list.childNodes[i].nodeType!=1)
		{ list.removeChild(list.childNodes[i]); i--; }
	}

	list = list.childNodes[1];
	for (i=0;i<list.childNodes.length;i++) // remove junk
	{ 
		if (list.childNodes[i].nodeType!=1)
		{ list.removeChild(list.childNodes[i]); i--; }
	}

	for (i=0;i<list.childNodes.length;i++) // update list items
	{
		list.childNodes[i].style.position = "absolute"; 
		list.childNodes[i].style.display = "block";
		list.childNodes[i].style.top = 0+"px"; 
		list.childNodes[i].style.left = (i*width)+"px"; 
	}
}

function hlist_move(id, dir)
{
	var list = document.getElementById(id).childNodes[1];
	var width = 280;

	if (list.childNodes.length>3)
	{
		// prepare list to shuffle //
		if (dir=='r') 
		{
			// move last element into position //
			for (i=0;i<list.childNodes.length-1;i++)
			{ list.appendChild(list.childNodes[0]); }
			list.childNodes[0].left = (0-width)+"px";
			setTimeout("hlist_moveright('"+id+"',"+(0-width)+")",20);
		}
		else
		{
			// do nothing for left, list is ready
			setTimeout("hlist_moveleft('"+id+"',0)",20);
		}
	}
}

function hlist_moveright(id, pos)
{
	var list = document.getElementById(id).childNodes[1];
	var width = 280;

	pos+=10; if (pos>0) { pos=0; }
	
	for (i=0;i<list.childNodes.length;i++) // update list items
	{ list.childNodes[i].style.left = ((i*width)+pos)+"px"; }

	if (pos!=0) { setTimeout("hlist_moveright('"+id+"',"+pos+")",20); }
}

function hlist_moveleft(id, pos)
{
	var list = document.getElementById(id).childNodes[1];
	var width = 280;
	
	pos-=10; if (pos<(0-width)) { pos=(0-width); }
	
	for (i=0;i<list.childNodes.length;i++) // update list items
	{ list.childNodes[i].style.left = ((i*width)+pos)+"px"; }
	
	if (pos!=(0-width)) { setTimeout("hlist_moveleft('"+id+"',"+pos+")",20); }
	else
	{ list.appendChild(list.childNodes[0]); }
}

function striphtml(data)
{
	data = data.replace(/<!(?:--[sS]*?--s*)?>s*/g,"");
	data = data.replace(/<\/?(?!\!)[^>]*>/gi,"");
	return data.replace(/^\s+|\s+$/g,"");
}

function stripslashes(data)
{
	data=data.replace(/\\'/g,'\'');
	data=data.replace(/\\"/g,'"');
	data=data.replace(/\\0/g,'\0');
	data=data.replace(/\\\\/g,'\\');
	return data;
}
