window.onload = function()
{
	initOrderButton();
	fDescweb();
	loadAlbumPreview();

	InitPhotoBars();
}
function InitPhotoBars()
{
	var divs = document.getElementsByTagName("div");
	for(var i=0; i<divs.length; i++)
	{
		if(divs[i].className == 'photoBarThumbs')
		{
			InitPhotoBar(divs[i]);
		}
	}
}

function InitPhotoBar(o)
{
	o.scroller = null;
	o.places = new Array();
	o.images = new Array();
	o.id = o.id + Math.random();
	var divs = o.getElementsByTagName("div");
	for(var i=0; i<divs.length; i++)
	{
		if(divs[i].className == 'photoBarThumb')
			o.places.push(divs[i]);
	}

	var tables = o.getElementsByTagName("table");
	for(var i=0; i<tables.length; i++)
	{
		if(tables[i].className == 'photoBarThumbsTable')
			o.scroller = tables[i];
	}


	var imgs = o.getElementsByTagName("img");
	for(var i=0; i<imgs.length; i++)
	{
		if(imgs[i].className == 'photoBarPreloadImg')
			o.images .push(imgs[i].src);
	}

	switchPhotoBarPhoto(o.id);
}

function switchPhotoBarPhoto(cBar)
{
	bar = document.getElementById(cBar);
	if(bar.images.length > 1)
	{
		//window.setTimeout("scrollPhotoBar()",3000);

		bar.images.push(bar.images.shift())
		for(var i=1; i<=bar.places.length; i++)
		{
			n = i;
			if(n > bar.images.length - 1)
			{
				n = n % bar.images.length ;
			}
			bar.places[i-1].style.backgroundImage = "url('" + bar.images[n] + "')";
		}
		bar.scrollcount = 0;
		scrollPhotoBar(cBar);
	}
}


function scrollPhotoBar(cBar)
{

	o = document.getElementById(cBar);

	var pos = o.scrollcount ;
	o.scroller.style.left = pos + "px";
	pos --;
	o.scrollcount = pos;
	if(pos == -110)
	{
		window.setTimeout("switchPhotoBarPhoto('"+cBar+"')",20);
	}
	else
	{
		window.setTimeout("scrollPhotoBar('"+cBar+"')",20);
	}
}

function pop(url, width, height)
{
	window.open(url,'','width='+width+', height='+height+', menubar=no, status=no, location=no, toolbar=no, scrollbars=no, resizable=no', false);
}


function poppage(url, width, height)
{
	window.open(url,'','width='+width+', height='+height+', menubar=no, status=no, location=no, toolbar=no, scrollbars=yes, resizable=yes', false);
}

function initOrderButton()
{
	var loBtn = document.getElementById("cmd_OrderNow");
	if(loBtn != null)
	{
		loBtn.onclick = function()
		{
			this.value= "Order wordt verwerkt...";
			this.onclick = function()
			{
				return false;
			}
		}
	}
}

function showWebgroups(cFilter, cCluster)
{
	if(!cCluster)
		cCluster = "";

	if(cFilter.indexOf("|") > 0)
	{
		var laFilter = cFilter.split("|");
		re = new RegExp("," + laFilter[0] + "(?=,|$)","gi");
		cFilter = laFilter[1].replace(re,"");
	}

	var cHref;

	if(window.location.href.toLowerCase().indexOf("default.asp?") > 1)
	{
		cHref = window.location.href.replace(/webgroupfilter\=[0-9,]+\&?/gi,"");
		cHref = cHref.replace("?", "?webgroupfilter=" + cFilter + "&");
		cHref = cHref.replace(/alstart=\d+/gi, "alstart=0");
		if(cCluster != "")
			cHref += '&clusterfilter=' + cCluster;
		if(window.location.href.indexOf('pageid=') < 0)
			cHref += '&pageid=8';
		window.location.href = cHref;
	}
	else
	{
		cHref = "/default.asp?alstart=0&webgroupfilter=" + cFilter;
		if(cCluster != "")
			cHref += '&clusterfilter=' + cCluster;
		if(window.location.href.indexOf('pageid=') < 0)
			cHref += '&pageid=8';
		window.location.href = cHref;
	}
}

function fDescweb()
{
	var o = document.getElementById('descweb');
	if(!o)
		return;

	var h = o.clientHeight > 0 ? o.clientHeight : o.offsetHeight;

	if(h > 700)
	{
		var oMore = document.getElementById('artdescmore');
		if(!oMore)
			return;

		o.className = "artdesclimit";
		oMore.style.display = 'block';
	}
}

function fDescwebShowHide(tiMode)
{
	var o = document.getElementById('descweb');
	var oMore = document.getElementById('artdescmore');
	var oLess = document.getElementById('artdescless');
	if(!o || !oMore || !oLess)
		return;

	if(tiMode)
	{
		o.className = "artdesclimit";
		oMore.style.display =  'block';
		oLess.style.display = 'none';
	}
	else
	{
		o.className = "artdesc";
		oMore.style.display = 'none';
		oLess.style.display =  'block';
	}
}

function fShowPicture(toImg)
{
	var lcXS = toImg.src;
	var lcXL = lcXS.replace("/small/","/large/");
	var lcXL = lcXS.replace("/thumbs/","/images/");
	var loXL = document.getElementById("showimg");
	if(loXL != null)
	{
		loXL.src = lcXL;
	}
	else
	{
		win = window.open(lcXL,"picpop","width=470,height=370,resizable=true",true);
		win.focus();
	}
}

function fPopPicture(toDiv)
{
	var lcXS = toDiv.style.backgroundImage;
	if(lcXS.indexOf("('") > -1)
		lcXS = lcXS.substring(lcXS.indexOf('\'') + 1, lcXS.lastIndexOf('\''));
	else
		lcXS = lcXS.substring(lcXS.indexOf('(') + 1, lcXS.lastIndexOf(')'));

	var lcXL = lcXS.replace("/small/","/large/");
	var lcXL = lcXS.replace("/thumbs/","/images/");
	var loXL = document.getElementById("showimg");
	if(loXL != null)
	{
		loXL.src = lcXL;
	}
	else
	{
		win = window.open(lcXL,"picpop","width=500,height=500,resizable=true",true);
		win.focus();
	}
}


function loadAlbumPreview()
{
	oImgs = document.getElementsByTagName("img");
	for(var i=0; i<oImgs.length; i++)
	{
		if(oImgs[i].className=="albumthumb")
		{
			fShowPicture(oImgs[i]);
			break;
		}
	}
}
