var imageSizeH = 120;
var imageSizeV = 90;
var borderSizeH = 2;
var borderSizeV = 2;

var availableImages = 207;
var imgArray = new Array();


function myWindowWidth ()
{
  if (window.innerWidth)
  {
    return window.innerWidth;
  }
  else if (document.body && document.body.offsetWidth)
  {
    return document.body.offsetWidth;
  }
  else
  {
    return 0;
  }
}

function myWindowHeight ()
{
  if (window.innerHeight)
  {
    return window.innerHeight;
  }
  else if (document.body && document.body.offsetHeight)
  {
    return document.body.offsetHeight;
  }
  else
  {
    return 0;
  }
}

function calculate () {
  if (Width != myWindowWidth() || Height != myWindowHeight())
  location.href = location.href;
}

/* Überwachung von Netscape initialisieren */
if (!window.Width && window.innerWidth)
{
	window.onresize = calculate;
	Width = myWindowWidth();
	Height = myWindowHeight(); 
}

function positionMainbox()
{
    document.getElementById('mainb').style.left = Width/2-275;
    //document.getElementById('mainb').style.top = Height/2-150;    
}

function positionImpBox()
{
    document.getElementById('impBox').style.left = Width-90;
    document.getElementById('impBox').style.top = Height-30;    
}

/*Anzahl von Bildern in einer Zeile*/
function calcImagesH()
{
	return Width / (imageSizeH+borderSizeH);
}

/*Anzahl von Bildern in einer Spalte*/
function calcImagesV()
{
	return Height / (imageSizeV+borderSizeV);
}


function createRandomColor()
{
	var valueR = Math.floor(Math.random()*255).toString(16);
	var valueG = Math.floor(Math.random()*255).toString(16);
	var valueB = Math.floor(Math.random()*255).toString(16);

	//function d2h(d) {return d.toString(16);}
	//function h2d(h) {return parseInt(h,16);}
	
	return valueR+valueG+valueB;
}

function createRandomImageName()
{
	for (var j = 0; j < availableImages; j ++)
	{
		var randomImage = Math.floor(Math.random()*availableImages).toString();
		
		if (randomImage == "0") randomImage = "1";
		if (randomImage.length == 1) randomImage = "00"+randomImage;
		if (randomImage.length == 2) randomImage = "0"+randomImage;

		imgArray[j] = randomImage;
	}

	return imgArray;
}

function mouseOver(obj)
{
    obj.style.opacity = 1;
    obj.style.filter = "alpha(opacity = 100)";
    //obj.style.width: 100%
    //obj.innerHTML.style.visibility = "visible" 
}

function mouseOut(obj)
{
    obj.style.opacity=0.5;
    obj.style.filter = "alpha(opacity = 50)";
    //obj.style.width: 100%
    //obj.innerHTML.style.visibility = "hidden"
}




function createImageMatrix()
{
  var numRows = Math.ceil(calcImagesV());
  var numColumns = Math.ceil(calcImagesH());
  var numPossibleImages = Math.ceil(calcImagesH()*calcImagesV());

  //document.write("R:"+numRows);
  //document.write(" C:"+numColumns);
  //document.write(" T:"+numPossibleImages);

  for(var i=0; i<=numRows; i++)
    { 
        for(var j=0; j<=numColumns; j++)
        {
        
            var imageNumber = createRandomImageName()[i];
            document.write('<div class="imagebox" style="');
            document.write('left:'+(imageSizeH+borderSizeH)*j+'; top:'+(imageSizeV+borderSizeV)*i+';');
            document.write('background-image:url(mosaic/images/jufactory_mini'+imageNumber+'.jpg);');
            document.write('" onmouseover="mouseOver(this)" onmouseout="mouseOut(this)";>');
            //document.write(imageNumber);
            document.write('</div>')       
        }
    }
}
