var menunavgfxpath = "gfx/nav-menu/";
var parts       = new Array("chromosoom","object","subject","readme","thanks");
var partsStatus = new Array(1,0,0,0,0,0);
var partsPosX   = new Array(140,153,166,179,192,205);
var partsPosY   = new Array(49,67,100,133,151,169);

function initDateTimeTimer() {
 displayTimeAndData();
 setTimeout("displayTimeAndData()",1000);

}

function displayTimeAndData() {
 var spanDate,spanTime;
 var datetime;
 var h,m,s;
 datetime = new Date(); //get the current date
 spanDate = document.getElementById('spandate');
 spanTime = document.getElementById('spantime');

 
 y = datetime.getYear();
 y = y.toString();
 y = y.substr(y.length - 2);

 m = datetime.getMonth()+1;
 if (m < 10) m = '0' + m;
 
 d = datetime.getDate();
 if (d < 10) d = '0' + d;
 
 if (spanDate != null) {
  spanDate.innerHTML = d + '.' + m + '.' + y;
 }

 h = datetime.getHours();
 m = datetime.getMinutes();
 if (m < 10) m = '0' + m;
 s = datetime.getSeconds();
 if (s < 10) s = '0' + s;

 if (spanTime != null) {
  spanTime.innerHTML = h + ':' + m + ':' + s;
 }
 setTimeout("displayTimeAndData()",1000);
}

function getPartIndex(name) {
 var index;
 
 for (i=0;i<parts.length;i++) {
  if (parts[i] == name) {
   index = i;
   break;
  }
 }
 
 return index;
}

function bringLastPartToFront() {
 
 for (i=0;i<parts.length;i++) {
  if (partsStatus[i] == 1) {
   bringPartToFront(parts[i]);
   break;
  }
 }  
}


function bringPartToFront(name) {
 var partindex;
 var partwindow;
 var divdisable;
 
 for (i=0;i<parts.length;i++) {
  partwindow = document.getElementById('w_' + parts[i]);
  divdisable = document.getElementById('disable_' + parts[i]);
  if (partwindow != null) {
   partwindow.style.zIndex = 100+i;
  }
  if (divdisable != null) {
   divdisable.style.display = '';
  }
 }
 partindex = getPartIndex(name);
 
 partwindow = document.getElementById('w_' + name);
 divdisable = document.getElementById('disable_' + name);
 if (partwindow != null) {
   partwindow.style.zIndex = 500;
 }
 if (divdisable != null) {
   divdisable.style.display = 'none';
 } 
  
}



function menuChoose(name) {
 var partindex;
 var partwindow;
 menuSwap(name,'hide');
 partindex = getPartIndex(name);
 partsStatus[partindex] = 1; //set status to opened 
 partwindow = document.getElementById('w_' + name); 
 partwindow.style.left = partsPosX[partindex] + 'px';
 partwindow.style.top  = partsPosY[partindex] + 'px'; 
 partwindow.style.display = '';
 
 bringPartToFront(name);
 if (name == 'object') {
  document.getElementById('i_objects_frame').src = 'objects.php';
 } else if (name == 'subject') {
  document.getElementById('i_subject_frame').src = 'subject.html';
 }
 
}

function menuClose(name) {
 var partindex;
 partindex = getPartIndex(name);
 partsStatus[partindex] = 0; //set status to opened 
 menuSwap(name,'out');
 document.getElementById('w_' + name).style.display = 'none'; 
 bringLastPartToFront();
 if (name == 'object') {
  document.getElementById('i_objects').src = 'empty.php';
 }
}

function menuSwap(name,why) {
 var img;
 var partindex;
 img = document.getElementById('m_img_'+name);
 partindex = getPartIndex(name);
 if (partsStatus[partindex] == 1) { return -1; } //part is opened, so do not swap
 
 if (img != null) {
  if (why == 'over') { img.src = menunavgfxpath + name + '-over.gif'; }
  if (why == 'out') { img.src = menunavgfxpath + name + '.gif'; }
  if (why == 'hide') { img.src = 'gfx/x.gif'; }  
 }
}

function hideMenu() {
 div = document.getElementById('LayerMenu');
 if (div != null) {
  if (div.style.display == '') { 
   div.style.display = 'none'; 
  }
  else { 
   div.style.display = ''; 
  }
 }
}

function menuToggle() {
 var div,img;
 div = document.getElementById('divMenu');
 img = document.getElementById('imgMenu');

 if (div != null && img != null) {
  if (div.style.display == '') { 
   
   div.style.display = 'none';
   img.src = menunavgfxpath + 'window-plus.gif';
  }
  else { 
   div.style.display = ''; 
   img.src = menunavgfxpath + 'window-minus.gif';
  }
 }
 
 if (img != null) {
  if (img.src == '') { div.style = 'none'; }
  else { div.style = ''; }
 
 }
  
}


function randomBackground() {
 var imgnum = Math.round(1+Math.random()*2);
 var img;
 img = document.getElementById('imgBackground');
 img.src = "gfx/background/sky" + imgnum + ".gif";
}	


function getElementHeight(id) {
 var value;
 value = -1;
 if (document.defaultView) {
  elm = document.getElementById(id);
  cst= document.defaultView.getComputedStyle(elm, "");
  if (cst != null) { 
   value = cst.getPropertyValue("height");
  }
 } else if (document.getElementById(id).currentStyle) {
   value = document.getElementById(id).currentStyle.height;
 }
 if (value != -1) {
  value = value.toString();
  if (value.indexOf('px') != -1) { 
   value = value.substr(0,value.length-2); //remove 'px' from string
  }
 }
 return parseInt(value);
}
function getElementWidth(id) {
 var value;
 value = -1;
 if (document.defaultView) {
  elm = document.getElementById(id);
  cst= document.defaultView.getComputedStyle(elm, "");
  if (cst != null) { 
   value = cst.getPropertyValue("width");
  }
 } else if (document.getElementById(id).currentStyle) {
  value = document.getElementById(id).currentStyle.width;
 }
 
 if (value != -1) {
  value = value.toString();
  if (value.indexOf('px') != -1) { 
   value = value.substr(0,value.length-2); //remove 'px' from string
  }
 }
 return parseInt(value);
}

function getElementLeft(id) {
 var value;
 value = -1;
 if (document.defaultView) {
  elm = document.getElementById(id);
  cst= document.defaultView.getComputedStyle(elm, "");
  if (cst != null) { 
   value = cst.getPropertyValue("left");
  }
 } else if (document.getElementById(id).currentStyle) {
  value = document.getElementById(id).currentStyle.left;
 }
 if (value != -1) {
  value = value.toString();
  if (value.indexOf('px') != -1) { 
   value = value.substr(0,value.length-2); //remove 'px' from string
  }
 }
 return parseInt(value);
}

function getElementTop(id) {
 var value;
 value = -1;
 if (document.defaultView) {
  elm = document.getElementById(id);
  cst= document.defaultView.getComputedStyle(elm, "");
  if (cst != null) { 
   value = cst.getPropertyValue("top");
  }
 } else if (document.getElementById(id).currentStyle) {
  value = document.getElementById(id).currentStyle.top;
 }
 if (value != -1) {
  value = value.toString();
  if (value.indexOf('px') != -1) { 
   value = value.substr(0,value.length-2); //remove 'px' from string
  }
 }
 return parseInt(value);
}

getViewportScrollTop = function() {
	var x;
	if (self.scrollTop) // all except Explorer
	{
		x = self.scrollTop;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict Mode
	{
		x = document.documentElement.scrollTop;
	}
	else if (document.body) // other Explorers
	{
		x = document.body.scrollTop;
	}
	return x;		
};


// First paramter is a nodes id, second the CSS property you want
function getCSSProperty(sNodeId, sProperty)
{
	var oNode = document.getElementById(sNodeId);
	
	if(document.defaultView)
	{
		return document.defaultView.getComputedStyle(oNode, null).getPropertyValue(sProperty);
	}
	else if(oNode.currentStyle)
	{
		var sProperty = sProperty.replace(/-\D/gi, function(sMatch)
		{
			return sMatch.charAt(sMatch.length - 1).toUpperCase();
		});

		return oNode.currentStyle[sProperty];
	}
	else return null;
}

getViewportScrollTop = function() {
	var x;
	if (self.scrollTop) // all except Explorer
	{
		x = self.scrollTop;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict Mode
	{
		x = document.documentElement.scrollTop;
	}
	else if (document.body) // other Explorers
	{
		x = document.body.scrollTop;
	}
	return x;		
};

var detect = navigator.userAgent.toLowerCase();

safariCheck = function () {

 if ( detect.indexOf('safari') + 1) {
  return true;
 } else { 
  return false; 
 }

}

