var showflag=false;
var t=null;
var on_id="";
var hiddenform=false;

var agt = navigator.userAgent.toLowerCase() ;
var ie = ((agt.indexOf ("msie") != -1) && (agt.indexOf ("opera") == -1) && (agt.indexOf ("safari") == -1)) ;


function show(menu_id,element_id){
    killtimer();
    if(showflag) hide();        
	menu = document.getElementById(menu_id);	
	
	main_element= document.getElementById(element_id);	
	for(i=main_element, x=0, y=0; i; i = i.offsetParent){
    	x += i.offsetLeft;      
    	y += i.offsetTop;
  	} 

	x = x-main_element.offsetWidth/2;  
	if (x<18) x = 18;  
    y = y+main_element.offsetHeight+10; 
	
	menu.style.left=x+"px";	
	menu.style.top=y+"px";
	
	menu.style.display = "block";	
	
	if ((hiddenform) && (ie)) {
		form_hidden = document.getElementById(hiddenform);	
		form_hidden.style.visibility="hidden";
	}
    showflag=true;
    on_id=menu_id;            
}


function killtimer(){
    if(t!=null) {
      clearTimeout(t);
      t=null;
    }
    return true;
}


function hide() {
    if(t!=null) killtimer();   
	menu = document.getElementById(on_id);	
	
	if (showflag) menu.style.display = "none";	
	if ((hiddenform) && (ie)) {
		form_hidden = document.getElementById(hiddenform);	
		form_hidden.style.visibility="visible";
	}   
	
    showflag = false;
    on_id = "";
}


function reset() {
    killtimer();
    t = setTimeout('hide()', 500);
}




function win_open(source,window_name,w,h,sc){
	ws=screen.availWidth;
	hs=screen.availHeight;
	kl=(ws-w)/2;
	if (kl<0){kl=0;}
	kt=(hs-h)/2;
	if (kt<0){kt=0;}
	var window_params = 'status=no,toolbar=no,scrollbars='+sc+',titlebar=yes,menubar=no,resizable=no,width='+w+',height='+h+',left='+kl+',top='+kt+',directories=no,location=no';
	window.open(source, window_name, window_params);
}

 
 function big_img(){
	if (document.all){
		//IE Opera
		im = event.srcElement;
		im_src=im.getAttribute("src");
		im_alt=im.getAttribute("alt");
		name_im=im_src.slice(im_src.lastIndexOf("/")+1,-4);
		name_im=name_im.replace("-","");
		big_im_src=im_src.replace("/s_","/b_");
		win_open("/tpls/big_img.php?im="+big_im_src+"&alt="+im_alt,"big_im"+name_im,500,400,1);
	}
	else {
		//Mozilla
		window.captureEvents(Event.CLICK);
		window.onclick= handle; 
	}   
}


function handle(e) {
	var retval = routeEvent(e);
	if (retval == true){
		return true;
	}
	else {
		obj=e.target;
		tag_name=obj.tagName;
		if (tag_name!='IMG'){
			return true;
		}
		else {
			im_src=obj.src;		
			link_im=obj.parentNode;
			link_im_function=link_im.getAttribute("onclick");
			if (link_im_function!="big_img();"){
				return true;
			}
			else {
				im_alt=obj.getAttribute("alt");
				name_im=im_src.slice(im_src.lastIndexOf("/")+1,-4);
				big_im_src=im_src.replace("/s_","/b_");
				win_open("/tpls/big_img.php?im="+big_im_src+"&alt="+im_alt,"big_im"+name_im,500,400,0,0,1,0);
			}        
		}      
	}
}
