/*
 * util.js
 * Utility functions for biovitrum.se/biovitrum.com
 */
 
 /*
  * Cross-browser settings
  */
  var IE = 1;
  var GECKO = 2;
  var UNSUPPORTED = 10;
  var browser = UNSUPPORTED;
  
  if(document.all) {
	browser = IE;
  } else if(document.getElementById) {
	browser = GECKO;
  }
 
 var activePush = "";
 var hideIsOk = false;
 var hideable = Array();
 hideable[1] = false;
 hideable[2] = false;
 hideable[3] = false;
 
 
 function setHideable(pid) {
	var n = parseInt(pid.substr(4));
	hideable[n] = true;
 }
 
 function clearHideable(pid) {
	var n = parseInt(pid.substr(4));	
	hideable[n] = false;
 }
 
 function isHideable(pid) {
	var n = parseInt(pid.substr(4));
	return hideable[n];	
 }
 
 function softShowFrontpagePush(pid) {
	activePush = pid;
	clearHideable(pid);
 }
 
 /* frontpage functions */
 function showFrontpagePush(pid) {
	remainHidden = false;
	
	switch(browser) {
		case IE:
			if(document.all[pid]) {				
				if(document.all[pid].style.display == "") {
					remainHidden = true;
				}
			}
			break;
		case GECKO:
			if(document.getElementById(pid)) {
				if(document.getElementById(pid).style.display == "") {
					remainHidden = true;
				}
			}
			break;
	}
	
	// hide all push ads
	for(i = 1; i < 4; i++) {
		setHideable("push" + i);
		hideFrontpagePushDoIt("push" + i);
	}
	
	activePush = pid;
	clearHideable(pid);
	
	if(remainHidden) {
		return;
	}
		
	switch(browser) {
		case IE:
			if(document.all[pid]) {				
				document.all[pid].style.display = "";
				document.all[pid + "header"].style.display = "none";
			}
			break;
		case GECKO:
			if(document.getElementById(pid)) {				
				document.getElementById(pid).style.display = "";
				document.getElementById(pid + "header").style.display = "none";
			}
			break;
	}
 }
 
 /* delays layer-hiding */
 function hideFrontpagePush(pid) { 
	setHideable(pid);
	
	return;
	
	setTimeout("hideFrontpagePushDoIt('" + pid + "');", 1000);
 }
 
 function hideFrontpagePushDoIt(pid) {
	if(!isHideable(pid)) {
		return;
	}
	switch(browser) {
		case IE:
			if(document.all[pid]) {
				document.all[pid].style.display = "none";
				document.all[pid + "header"].style.display = "";
			}
			break;
		case GECKO:
			if(document.getElementById(pid)) {
				document.getElementById(pid).style.display = "none";
				document.getElementById(pid + "header").style.display = "";				
			}
			break;
	}
 }
