var pagemenu;

function findPosX(obj) {
   var curleft = 0;
   if(obj.offsetParent) {
      while(obj.offsetParent) {
         curleft += obj.offsetLeft
         obj = obj.offsetParent;
      }
   }
   else if(obj.x) 
     curleft = obj.x;
   return curleft;
}
 
function findPosY(obj) {
   var curtop = 0;
   if(obj.offsetParent) {
      while(obj.offsetParent) {
         curtop += obj.offsetTop
         obj = obj.offsetParent;
      }
   }
   else if(obj.y)
      curtop = obj.y;
   return curtop;
}

function getElementsByClassName(class_name) {
	var all_obj,ret_obj=new Array(),j=0,teststr;
	if(document.all)all_obj=document.all;
	else if(document.getElementsByTagName && !document.all)all_obj=document.getElementsByTagName("*");
	for(i=0;i<all_obj.length;i++) {
		if(all_obj[i].className.indexOf(class_name)!=-1){
			teststr=","+all_obj[i].className.split(" ").join(",")+",";
			if(teststr.indexOf(","+class_name+",")!=-1){
				ret_obj[j]=all_obj[i];
				j++;
			}
		}
	}
	return ret_obj;
}

function reset_pagemenu(val) {
	stopclose();
	array=getElementsByClassName('snav');
	for(i=0;i<array.length;i++) {
		array[i].style.visibility='hidden';
	}
}

function submenu(obj,cid) {
	reset_pagemenu();

	posx=findPosX(obj)-15;
	posy=findPosY(obj)+18;

	document.getElementById('subnav_'+cid).style.left=posx+"px";
	document.getElementById('subnav_'+cid).style.top=posy+"px";
	document.getElementById('subnav_'+cid).style.visibility='visible';

	pagemenu=cid;
	
}
var active;
function startclose(){
	active = window.setTimeout("reset_pagemenu()",500);
}
function stopclose(){
	if(active){
		window.clearTimeout(active);
	}
}

var picactive;
function hidePic() {
	document.getElementById('overlay').style.visibility='hidden';
}

function showPic(val,obj) {
	posx=findPosX(obj)-30;
	posy=findPosY(obj)-40;
	document.getElementById('overlay').style.left=posx+"px";
	document.getElementById('overlay').style.top=posy+"px";
	document.getElementById('overlay').innerHTML='<a href="detail.php?item='+val+'"><img onmouseout=\"hidePic();\" src="img/s_'+val+'.png" src="" border="" alt=""/></a>';
	document.getElementById('overlay').style.visibility='visible';
}

