function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function mouseOver(e){
	if(e.srcElement){obj=e.srcElement}else{obj=e.currentTarget};
	if(obj.className=="top_menu_head"){obj.style.backgroundColor="#696969"};
	var subMenu = obj.getElementsByTagName("div");
	if(subMenu[0] && subMenu[0].className=="top_submenu"){
		subMenu[0].style.display="block";

	};
	return;
}

function mouseOut(e){
	if(e.srcElement){
		obj=e.srcElement;
		//alert(obj.id.indexOf("top_menu_") + "object id is " + obj.id);
		while(obj.id.indexOf("top_menu_") && obj.nodeName != 'BODY'){
			obj = obj.parentNode;
			//alert("converting " + obj.parentNode.id);
		}
		//alert("which element now fired? " + obj.id);
		if(e.toElement){
			var related = e.toElement;
			while (related.id != obj.id && related.nodeName != 'BODY'){
				related = related.parentNode;
			}
			if (related.id == obj.id ){return; };
		}
	}else{obj=e.currentTarget};
	//alert("object id = " + obj.id);
	if(obj.className=="top_menu_head"){obj.style.backgroundColor=""};
	subMenu = obj.getElementsByTagName("div");
	if(subMenu[0] && subMenu[0].className=="top_submenu"){
		subMenu[0].style.display="none";
	}
	return;
}

function init(){
	var topmenu = document.getElementById( "top_menu" );
	if(topmenu){
		var topmenu_items = topmenu.childNodes;
		//add event listeners now;
		for (i=0;i<topmenu_items.length;i++){
			if(topmenu_items[i] && topmenu_items[i].className=="top_menu_head"){
				if(document.addEventListener){
					topmenu_items[i].addEventListener("mouseover",mouseOver,false);
					topmenu_items[i].addEventListener("mouseout",mouseOut,false);
				}
				else{
					topmenu_items[i].attachEvent("onmouseover",mouseOver);
					topmenu_items[i].attachEvent("onmouseout",mouseOut);
				}
			}
		}
		// close menus on page change and make sure all reset to display none
		var submenus = getElementsByClassName("top_submenu", topmenu);
		for (i=0;i<submenus.length;i++){
			submenus[i].style.display="none";
			//alert(submenus[i].style.display);
		}
	}
}


function getElementsByClassName(classname, node) {
      if(!node) node = document.getElementsByTagName("body")[0];
      var a = [];
      var re = new RegExp('\\b' + classname + '\\b');
      var els = node.getElementsByTagName("*");
      for(var i=0,j=els.length; i<j; i++)
      if(re.test(els[i].className))a.push(els[i]);
      return a;
}

function product_detail(img){
   var image = '/images/items/' + img;		
   window.open(image, 'prod_detail', 'width=700, height=440'); 
}

function article_image(img){
   var image = img;		
   window.open(image, 'article_image', 'width=544, height=410'); 
}

function gallery_slideshow(folder){
   var gallery = '/gallery/' + folder + "/index.html";		
   window.open(gallery, 'Gallery', 'width=840, height=620, resizable=1'); 
}

function close_up(image,width,height)
 {
	var iheight = height || 370;
	var iwidth = width || 370;
	iheight += 20;
	iwidth += 20;
	this.window.name="parentwindow";
	var config = "directories=0,location=0,toolbar=0,menubar=0,resizable=0,dependent=0,status=0,width=" + iwidth + ",height=" + iheight + ",left=25,top=25";
	illustration = window.open(image ,'illustration',config);
 }

function close_up_scroll(image,width,height)
 {
	var iheight = height || 370;
	var iwidth = width || 370;
	iheight += 20;
	iwidth += 20;
	this.window.name="parentwindow";
	var config = "directories=0,location=0,toolbar=0,menubar=0,scrollbars=1,resizable=1,dependent=0,status=0,width=" + iwidth + ",height=" + iheight + ",left=25,top=25";
	illustration = window.open(image ,'illustration',config);
 }
 
 function highlight(id){
  var mit = document.getElementById(id);
  mit.style.color = '#000';
  mit.focus();
  mit.select()
 }
 
addLoadEvent(init);



