/*
Jason Fong
080911
080910
080820
 */


	// gmail code
	var isIE=(window.attachEvent && !window.opera);
	var Ka=navigator.userAgent.toLowerCase();
	var rt=Ka.indexOf("opera")!=-1;
	var r=Ka.indexOf("msie")!=-1&&(document.all&&!rt);
	
	function myAttachEvent(a,b,c){if(r){a.attachEvent("on"+b,c)}else{a.addEventListener(b,c,false)}}


function getXCoord(el) {
	x = 0;
	while(el){
		x += el.offsetLeft;
		el = el.offsetParent;
	}
	return x;
}

function getYCoord(el) {
	y = 0;
	while(el){
		y += el.offsetTop;
		el = el.offsetParent;
	}
	return y;
}





var jsmenu={

	menu_container_id:'menu_container',
	delay:700,
	
	
	
	

	container_obj:null,
	delaytimer:null,
	
	over:function(obj,direction){
		this.obj=obj;
		/* direction */
		this.direction=direction;
		
		this.clearhidemenu();

		if(this.container_obj){
			 this.container_obj.style.display = 'none'; 
		}
		
		/* obj event */
		myAttachEvent(obj,"mousemove",jsmenu.clearhidemenu);
		myAttachEvent(obj,"mouseout",jsmenu.out);
		
		
		/* ============= */
				
		/* show menu */
		jsmenu.show(obj);
		
		obj.blur();
		return false;
		

	},
	
	out:function(){
		jsmenu.hide();
	},
	
	container_over:function(){
		jsmenu.clearhidemenu();
	},
	
	
	
	
	show:function(obj){
	
		/*
		if($(this.menu_container_id)){
			this.container_obj=$(this.menu_container_id);
		}else{
			this.container_obj = document.createElement('div');
			this.container_obj.id = this.menu_container_id;
			document.body.appendChild(this.container_obj);
			this.container=this.container_obj;	
		}
		*/
		


		/* content */
		
		content_obj=document.getElementById(obj.id+'_content');
		/*this.container_obj.innerHTML=content_obj.innerHTML;*/
		this.container_obj=document.getElementById(obj.id+'_content');
		


		if( this.container_obj){
		 this.container_obj.style.display = 'none'; 
		 
		 
		 	/* this.container_obj event */
			myAttachEvent(this.container_obj,"mouseover",jsmenu.container_over);
			myAttachEvent(this.container_obj,"mouseout",jsmenu.out);
			myAttachEvent(this.container_obj,"click",jsmenu.out);
		
			/* ============= */
		}
		
				
		this.container_obj.style.display = '';
		this.container_obj.style.position = 'absolute';
		this.container_obj.style.zIndex = "1";
		/*this.container_obj.style.left = 0 +'px';
		this.container_obj.style.top = 0 +'px';*/
		

		/*document.title=getXCoord(obj)+ " " +this.container_obj.offsetWidth;*/

		/* fix firefox "a img" problem */
		if(obj.tagName.toLowerCase()=='a' && obj.getElementsByTagName("img")[0]){
			obj=obj.getElementsByTagName("img")[0];
		}




		if(this.direction=='right'){
			this.container_obj.style.left = getXCoord(obj)+obj.offsetWidth+'px';
			this.container_obj.style.top  = getYCoord(obj)+'px';	
		}else if(this.direction=='left'){

			this.container_obj.style.left = getXCoord(obj)-this.container_obj.offsetWidth+'px';
			this.container_obj.style.top  = getYCoord(obj)+'px';	
			
			
		}else if(this.direction=='up'){
		

			this.container_obj.style.left = getXCoord(obj)-((this.container_obj.offsetWidth-obj.offsetWidth)/2)+'px';
			this.container_obj.style.top  = getYCoord(obj)-this.container_obj.offsetHeight+'px';	
		}else{
		

			this.container_obj.style.left = getXCoord(obj)+ (-0)+'px';
			this.container_obj.style.top  = getYCoord(obj)+obj.offsetHeight+'px';	
			
			
		}
		
		/* ============= */

		
	
		/*document.title=document.title+'.';*/
	},
	
	
	
	hide:function(){
/*		document.title="hide..";*/
		clearTimeout(this.delaytimer);
		this.delaytimer=setTimeout(function(){
		jsmenu.container_obj.style.display = 'none';

			/*$(jsmenu.menu_container_id).style.display = 'none';*/
			
			
		},this.delay);
		
		/*alert("a"+this.delaytimer);*/

		//hide menu	;
	},
	
	
	clearhidemenu:function(){

	/*clearTimeout(this.delaytimer);
		*/if (this.delaytimer!=null){
			/*document.title="clear";*/
			/*alert("clear "+this.delaytimer);*/
			clearTimeout(this.delaytimer);
		}
	}	
	
}

/*
jsmenu.jsmenu();
*/
