//  Author of this modified version: Richard Prangnell (October 2007)
//  Credits: rapo & Peter-Paul Koch -  http://www.quircksmode.org (dates: 2002-2004)

/*
  getDocumentObject
        Description: getDocumentObject function returns THE object
							from the document that has the provided id(name).
        Parameters: name - represents the id of the object
        Returns: the object if found or null (so check if not null!)
*/
function getDocumentObject(name)
{
  //NN6+, IE5+
  if (document.getElementById)
  {
	  if(document.getElementById(name))
		{
	    this.obj = document.getElementById(name);
	    this.style = document.getElementById(name).style;
	  }
	  else return;
  }
  //IE4
  else if (document.all)
  {
	  if(document.all[name])
		{
	    this.obj = document.all[name];
	    this.style = document.all[name].style;
	  }
	  else return;
  }
  //NN4
  else if (document.layers)
  {
		this.obj = getObjNN4(document,name);
		this.style = this.obj;
  }
  return this;
}


//used for NN4 to search in nested layers
//created by PPK - untouched by me
function getObjNN4(obj,name)
{
	var x = obj.layers;
	var thereturn;
	for (var i=0;i<x.length;i++)
	{
		if (x[i].id == name)
		  thereturn = x[i];
		else if (x[i].layers.length)
		  var tmp = getObjNN4(x[i],name);
		if (tmp)
		  thereturn = tmp;
	}
	return thereturn;
}


/*
  getObjectProperty
  Description: the function searches for the object with the
  specified id and if found returns the specified property value
	  NOTE: undefined value may be returned if the object is
		found BUT its property was not explicitly defined
  Parameters: the id(name) of the object
	            the property of that object
	Returns: the value of the property if object found or null
*/
function getObjectProperty(id, property)
{
	var object=getDocumentObject(id);
	if(object!=null)
	{
	  var styleObject=object.style;
		if(styleObject[property])
		  return styleObject[property];
	}
	else return;
}

/*
  setObjectProperty
  Description: the function searches for the object with the specified id
               and if found the specified property is updated to value
  Parameters: the id(name) of the object,
              the property of that object,
              the new value for property;
  Returns:true(if succesfull)/false
*/

function setObjectProperty(id, property, value)
{
	var object=getDocumentObject(id);
	if(object!=null)
	{
	  var styleObject=object.style;
	  if(styleObject[property]=value)
		  return true;
	}
	else return false;
}


/*
  setPNGBackground
  Description: Applies a PNG image to a layer. The layer must not have a previous background,
  					and the size of the layer must be equal with the size of the background image.
               Special created for IE that can't handle translucent PNGs.
  Parameters: the id(name) of the object,
              the path to the PNG image.
  Returns:undefined
*/

function setPNGBackground(divId, path)
{
	var foundDiv=getDocumentObject(divId).style;
	var ua=navigator.userAgent.toLowerCase();
	var ie=(document.all && (ua.indexOf("opera") == -1) && (ua.indexOf("webtv") == -1));
	if(ie)
   	foundDiv.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+path+"', sizingMethod='scale')";
	else
	  foundDiv.backgroundImage = 'url('+path+')';
}

var styleObject=null;
var speed=32;
var step=1;
var max=326;
var module=326;
var course1=652;
var course2=326;
var course3=-0;
var course4=-326;
var course5=-652;
var course6=-978;
var course7=-1304;

function move(id,top,left){
  styleObject=getDocumentObject(id).style;
  if(styleObject)
	{
		styleObject.top=top;
		styleObject.left=left;
  }
}


function recalculate()
{
  course1+=step;
	if(course1<max+module)
	{
		if(course1>max)
			setObjectProperty("extraDiv1","width",(module+max-course1)+"px");
   	move("extraDiv1","0px",(course1-3)+"px");
	}
  else
	{
    course1=-1274;
    setObjectProperty("extraDiv1","display","none");
    setObjectProperty("extraDiv1","width","326px");
    move("extraDiv1","0px","-326px");
    setObjectProperty("extraDiv1","display","block");
  }
  course2+=step;
	if(course2<max+module)
	{
		if(course2>max)
			setObjectProperty("extraDiv2","width",(module+max-course2)+"px");
   	move("extraDiv2","0px",(course2-3)+"px");
	}
  else
	{
    course2=-1274;
    setObjectProperty("extraDiv2","display","none");
    setObjectProperty("extraDiv2","width","326px");
    move("extraDiv2","0px","-326px");
    setObjectProperty("extraDiv2","display","block");
  }
  course3+=step;
	if(course3<max+module)
	{
		if(course3>max)
			setObjectProperty("extraDiv3","width",(module+max-course3)+"px");
	  move("extraDiv3","0px",(course3-3)+"px");
	}
  else
	{
    course3=-1274;
    setObjectProperty("extraDiv3","display","none");
    setObjectProperty("extraDiv3","width","326px");
    move("extraDiv3","0px","-326px");
    setObjectProperty("extraDiv3","display","block");
  }
  course4+=step;
	if(course4<max+module)
	{
		if(course4>max)
			setObjectProperty("extraDiv4","width",(module+max-course4)+"px");
	  move("extraDiv4","0px",(course4-3)+"px");
	}
  else
	{
    course4=-1274;
    setObjectProperty("extraDiv4","display","none");
    setObjectProperty("extraDiv4","width","326px");
    move("extraDiv4","0px","-326px");
    setObjectProperty("extraDiv4","display","block");
  }
  course5+=step;
	if(course5<max+module)
	{
		if(course5>max)
			setObjectProperty("extraDiv5","width",(module+max-course5)+"px");
	  move("extraDiv5","0px",(course5-3)+"px");
	}
  else
	{
    course5=-1274;
    setObjectProperty("extraDiv5","display","none");
    setObjectProperty("extraDiv5","width","326px");
    move("extraDiv5","0px","-326px");
    setObjectProperty("extraDiv5","display","block");
  }
  course6+=step;
	if(course6<max+module)
	{
		if(course6>max)
			setObjectProperty("extraDiv6","width",(module+max-course6)+"px");
	  move("extraDiv6","0px",(course6-3)+"px");
	}
  else
	{
    course6=-1274;
    setObjectProperty("extraDiv6","display","none");
    setObjectProperty("extraDiv6","width","326px");
    move("extraDiv6","0px","-326px");
    setObjectProperty("extraDiv6","display","block");
  }
  course7+=step;
	if(course7<max+module)
	{
		if(course7>max)
			setObjectProperty("extraDiv7","width",(module+max-course7)+"px");
	  move("extraDiv7","0px",(course7-3)+"px");
	}
  else
	{
    course7=-1274;
    setObjectProperty("extraDiv7","display","none");
    setObjectProperty("extraDiv7","width","326px");
    move("extraDiv7","0px","-326px");
    setObjectProperty("extraDiv7","display","block");
  }
	thread=window.setTimeout("recalculate()",speed);
}



window.onload = function()
{

  setObjectProperty("extraDiv8","display","none");
  // setObjectProperty("container","background","transparent");

  setObjectProperty("extraDiv1","display","block");
  setObjectProperty("extraDiv2","display","block");
  setObjectProperty("extraDiv3","display","block");
  setObjectProperty("extraDiv4","display","block");
  setObjectProperty("extraDiv5","display","block");
  setObjectProperty("extraDiv6","display","block");
  setObjectProperty("extraDiv7","display","block");
  if(document.body && document.body.clientWidth)
		max=document.body.clientWidth-module;
  setPNGBackground("pageHeader","resources/logo.png");
  // setPNGBackground("container","container.png");
  recalculate();

}