// Javascript document for site: www.design-and-arts.com
// All pages except index and pop-ups

// IE 5 for Mac incompatibility warning
if ((navigator.userAgent.indexOf("MSIE") >= 0) && (navigator.userAgent.indexOf("Mac") >= 0) && (navigator.userAgent.indexOf("Opera") < 0)) {
  alert("Sie sind anscheinend mit Internet Explorer auf Macintosh unterwegs. Bedauerlicherweise ist diese Website nicht mit diesem Browser kompatibel. Mozilla/Firefox oder Safari sind gute Alternativen. Danke fuer Ihr Verstaendnis.\n\nIt seems you are using Internet Explorer on Macintosh. This site is unfortunately not compatible with this browser. Good alternatives are Mozilla/Firefox or Safari. Thank you for your comprehension.");
}

// ------------------------------
// Code for drop-down menus based on Suckerfish Dropdowns by Patrick Griffiths and Dan Webb at http://www.alistapart.com/articles/dropdowns/
// with Gecko hover - overflow:auto bug work around by Stephan Edelbroich
// ------------------------------

startList = function() {
	if (((document.all&&document.getElementById) || (navigator.userAgent.indexOf("Netscape6/") >= 0) || (navigator.userAgent.indexOf("Gecko") >= 0) || (navigator.userAgent.indexOf("Safari") >= 0)) && (navigator.userAgent.indexOf("Opera") < 0)) { // some browser sniffing here for IE + Gecko based browsers

		var productgroupsUl = 1; // number of navigation elements which have a drop-down

    if (!document.all) { // for Gecko only

      // function for hiding all the drop downs
      // nav-productgroupN is the ID of the always visible navigation links, nav-productgroupN-ul the ID of the ul li ul nodes  
			// Note: nav-productgroupN-ul is the drop-down of nav-productgroupN 
      keepMenu = function(keep) {
			  for (k=1; k<=productgroupsUl; k++) {
          if (keep != "nav-productgroup"+k) document.getElementById("nav-productgroup"+k+"-ul").style.display="none";
				}
	      document.getElementById("nav-productgroup0").style.zIndex=1; // set z-index of the help layer back to as low as possible
      }
			
		  // Assign mouseover event to help layer and always visible navigation elements; a loop can cause flickering of the drop-downs (?)
			document.getElementById("nav-productgroup0").onmouseover=function() {
			  keepMenu("nav-productgroup0");
			}
			document.getElementById("nav-productgroup1").onmouseover=function() {
			  keepMenu("nav-productgroup1");
			}
			document.getElementById("nav-productgroup3").onmouseover=function() {
			  keepMenu("nav-productgroup3");
			}
			document.getElementById("nav-productgroup4").onmouseover=function() {
			  keepMenu("nav-productgroup4");
			}
		}
		else { // IE display correction for services and ebay links in navigation (shift down 1px to adjust)
		  document.getElementById("nav-3").style.top="1px";
			document.getElementById("nav-4").style.top="1px";
		}
		
		for (i=1; i<=productgroupsUl; i++) { // for IE and Gecko
		  navRoot = document.getElementById("nav-rollover"+i);
		  for (j=0; j<navRoot.childNodes.length; j++) {
			  node = navRoot.childNodes[j];
			  if (node.nodeName=="LI") {
					node.onmouseover=function() {
				    if (document.all) { // for IE
					    this.className+=" over";
						}
						else { // for Gecko
							this.childNodes[2].style.display="block"; // make ul li ul visible, equivalent to class change for IE
							this.childNodes[2].style.top="20px"; // Site optimized for IE which may have a rounding error on the vertical position of the drop-down; since I need a workaround for Gecko anyway I adjust it here
							document.getElementById("nav-productgroup0").style.zIndex=3; // z-index of the help layer must be higher than the one of the div with the overflow set, but lower than that of the drop-down menu
						}
					}
				  if (document.all) { // for IE
					  node.onmouseout=function() {
				      this.className=this.className.replace(" over", "");
					  }
				  }
			  }
		  }
		}
	}
}

window.onload=startList;


// ------------------------------
// Code for product detail pop-up
// ------------------------------

productWindow = null;

// check if there's already a pop-up open, if yes, close it

closeProductDetail = function() {
  if (productWindow && productWindow.open && !productWindow.closed) {
		productWindow.close();
	}
}

// open pop-up for products

openProductDetail = function(product) {
  var posX = 0;
	var posY = 0;
	var offsetLeft = document.getElementById('center-site').offsetLeft + document.getElementById('background').offsetLeft;
	var offsetTop = document.getElementById('center-site').offsetTop + document.getElementById('background').offsetTop;

  if (window.screenLeft || window.screenTop) {
    // For IE 4+ and Opera
		posX = window.screenLeft+offsetLeft-130;
		posY = window.screenTop+offsetTop-130;
  }
	else if (window.innerWidth || window.innerHeight) {
    // Gecko
		posX = screenX+offsetLeft-130;
		posY = screenY+(window.outerHeight-window.innerHeight-20)+offsetTop-160;
  }
	else {
    // fallback in case of other browser
    posX = 100;
		posY = 100;
  }
	closeProductDetail();
  productWindow = window.open(product,"ProductDetail","width=1010,height=815,top="+posY+",left="+posX+",location=no,menubar=no, status=no,toolbar=no");
	if (window.focus) {productWindow.focus()}
}

window.onunload=closeProductDetail;