// JavaScript Document

var loaded = false;

function loadAgain()
{
   if( loaded )
      window.location.reload();
}

window.onresize = loadAgain;


function mijnScriptsLoader() {
//	alert("imgscale");
	loaded = true;
}

function GetWindowSize() // get viewport size
{
	var size = [-1,-1];
	
	if (document.images)
	{
		if (typeof window.innerWidth != 'undefined')
		{
			size = [self.innerWidth, self.innerHeight];
		}
		else if (typeof document.documentElement != 'undefined'
				 &&
				 typeof document.documentElement.clientWidth != 'undefined'
				 &&
				 document.documentElement.clientWidth != 0)
		{
			size = [document.documentElement.clientWidth, document.documentElement.clientHeight];
		}
		else
		{
			size = [
					document.getElementsByTagName('body')[0].clientWidth,
					document.getElementsByTagName('body')[0].clientHeight
					];
		}
	}
	return size;
}

function GetSuffix(size,xy,lh)
{
	var w = size[0];
	var suffix = "";
	if (xy == "xy")
	{
		if ((size[0]/size[1])>(8/5))
		{
			w=(size[1]*8/5);
		}
	}

	if (w<=700)
	{
		suffix = "_07";
	} else if (w<=800 && lh == "h")
	{
	  	suffix = "_08";
	} else if (w<=900)
	{
		suffix = "_09";
	} else if (w<=1000 && lh == "h")
	{
		suffix = "_10";
	} else if (w<=1100)
	{
		suffix = "_11";
	} else if (w<=1200 && lh == "h")
	{
		suffix = "_12";
	} else if (w<=1300)
	{
		suffix = "_13";
	} else if (w<=1400 && lh == "h")
	{
		suffix = "_14";
	} else if (w<=1500)
	{
		suffix = "_15";
	} else if (w<=1600 && lh == "h")
	{
		suffix = "_16";
	} else
	{
		suffix = "_17";
	}
	return suffix;
}

function dummy()
{
	loaded = true;
	return 0;
}

function GetMenuWH(sizes,xy,lh)
{
	var size = GetWindowSize();
		var w = size[0];
	var hw = [1,1];
	if (xy == "xy")
	{
		if ((size[0]/size[1])>(8/5))
		{
			w=(size[1]*8/5);
		}
	}

	if (w<=700)
	{
		hw = sizes[0];
	} else if (w<=800 && lh == "h")
	{
	  	hw = sizes[1];
	} else if (w<=900)
	{
		hw = sizes[2];
	} else if (w<=1000 && lh == "h")
	{
		hw = sizes[3];
	} else if (w<=1100)
	{
		hw = sizes[4];
	} else if (w<=1200 && lh == "h")
	{
		hw = sizes[5];
	} else if (w<=1300)
	{
		hw = sizes[6];
	} else if (w<=1400 && lh == "h")
	{
		hw = sizes[7];
	} else if (w<=1500)
	{
		hw = sizes[8];
	} else if (w<=1600 && lh == "h")
	{
		hw = sizes[9];
	} else
	{
		hw = sizes[10];
	}
	return hw;
}

function ScaleImages() // search for images to scale, and scale them.
{
	loaded = false;
	var img;
	var imgSrc, imgID, imgName;
	var us, sel, rest, xy, lh, ext, path, suffixe, fname;
	var size = GetWindowSize();
	var i=0;
	var divs
	var n=0;
	
	divs = document.getElementsByTagName("div");
	n = divs.length;
	for(i=0; i<n; i++)
	{
		imgID = divs[i].id;
		if (imgID.substring(0,3) == "bgs")
		{
			imgSrc = divs[i].style.backgroundImage;
			us = imgSrc.indexOf("(");
			imgSrc = imgSrc.substring(us+1,imgSrc.length);
			us = imgSrc.indexOf(")");
			imgSrc = imgSrc.substring(0,us-1);
			us = imgID.indexOf("_");
		 	sel = imgID.substring(0,us);
			rest = imgID.substring(us+1,imgID.length);
			us = rest.indexOf("_");
			xy = rest.substring(0,us);
			rest = rest.substring(us+1,rest.length);
			us = rest.indexOf("_");
			lh = rest.substring(0,us);
			rest = rest.substring(us+1,rest.length);
			us = rest.indexOf("_");
			ext = "."+rest.substring(0,us);
			imgName = rest.substring(us+1,rest.length);
			path = imgSrc.substring(0,imgSrc.lastIndexOf("/")+1);
			suffix = GetSuffix(size, xy, lh);
			fname = imgSrc.substring(imgSrc.lastIndexOf("/")+1,imgSrc.length);
//			alert(size[0]+"     "+size[1]+"     "+sel+"     "+xy+"     "+lh+"     "+path+"     "+imgName+"     "+suffix+"     "+ext);
			if (fname != (imgName+suffix+ext))
			{
			 	divs[i].style.backgroundImage = "url("+path+imgName+suffix+ext+")";
			}
		} 
	}
	
	
//	imgs = document.getElementsByTagName("img");
	n = document.images.length;
    for(i=0; i<n; i++)
    {
		img = document.images[i];
		imgSrc = img.src;
		imgID = img.id;
		//imgName = img.name;
		if (imgID.substring(0,3) == "sel")
		{
			us = imgID.indexOf("_");
		 	sel = imgID.substring(0,us);
			rest = imgID.substring(us+1,imgID.length);
			us = rest.indexOf("_");
			xy = rest.substring(0,us);
			rest = rest.substring(us+1,rest.length);
			us = rest.indexOf("_");
			lh = rest.substring(0,us);
			rest = rest.substring(us+1,rest.length);
			us = rest.indexOf("_");
			ext = "."+rest.substring(0,us);
			imgName = rest.substring(us+1,rest.length);
			path = imgSrc.substring(0,imgSrc.lastIndexOf("/")+1);
			suffix = GetSuffix(size, xy, lh);
			fname = imgSrc.substring(imgSrc.lastIndexOf("/")+1,imgSrc.length);
			if (fname != (imgName+suffix+ext))
			{
			 	img.src = path+imgName+suffix+ext;
			}
		} 
    }
//			alert(size[0]+"     "+size[1]+"     "+sel+"     "+xy+"     "+lh+"     "+path+"     "+imgName+"     "+suffix+"     "+ext);
	setTimeout("dummy()",500);
  	loaded = true;
}

//addLoadListener(mijnScriptsLoader);
addLoadListener(ScaleImages);
//</script>
//<![endif]-->
