var agt = navigator.userAgent.toLowerCase();
var is_ie = ((agt.indexOf('msie')!=-1) && (agt.indexOf('opera')==-1));
var is_gecko= (navigator.product == "Gecko");
var is_ns = (document.layers);
var is_w3 = (document.getElementById && !is_ie);
var sch = 0;
var guides = {
	'boyds' : {'boyds_all' : {'boyds1' : ['爱恋系列','inlove.php'],
	'boyds2' : ['万圣节系列','halloween.php'],
	'boyds3' : ['限量版系列','limited_edition.php'],
	'boyds4' : ['传家宝系列','family_heirloom.php'],
	'boyds5' : ['糕点师系列','pastry_chef.php'],
	'boyds6' : ['好朋友系列','good_friend.php'],
	'boyds7' : ['唱诗天使系列','angel.php'],
	'boyds8' : ['设计师特别系列','designer.php'],
	'boyds9' : ['圣诞节姜饼系列','christmas.php']}},
	
	'gund' : {'gund_all' : {
	'gund1' : ['GUND BABY 婴儿系列','baby.php'],
	'gund2' : ['GUND CORE 核心系列','core.php'],
	'gund3' : ['GUND KIDS 儿童系列','kids.php']}},
	
	'bearsfriends' : {'bearsfriends_all' : {
	'bearsfriends1' : ['Bears & Friends都市范系列','cityfan.php'],
	'bearsfriends2' : ['Bears & Friends浪漫玫瑰熊系列','romantic.php']}},
	
	'jimi' : {'jimi_all' : {
	'jimi1' : ['幾米月亮忘记了系列','moon.php'],
	'jimi2' : ['幾米向左走向右走系列','sunshine.php'],
	'jimi3' : ['幾米遗失了一只猫系列','cat.php']}}
}
function showguide(id){
	var obj = document.getElementById('showmenu');
	var guide = guides[id];
	var html  = '<dl class=menu_dl'+id+'>';
	for(i in guide){
		var subs = guide[i];
		html += '<dd>';
		for(j in subs){
			var sub = subs[j];
			html += '<a href="'+sub[1]+'">'+sub[0]+'</a>';
		}
		html += '</dd>';
	}
	obj.innerHTML = html + '</dl>';
	var obj1  = document.getElementById(id);
	var left  = findPosX(obj1) + ietruebody().scrollLeft;
	var top   = findPosY(obj1) + ietruebody().scrollTop + 22;
	obj.style.display = "";
	obj.style.top	= top + 'px';
	obj.style.left	= left + 'px';
	addEvent(document,"mouseout",doc_mouseout);
}
function closeguide(){
	var obj = document.getElementById('showmenu');
	obj.style.display = "none";
	removeEvent(document,"mouseout",doc_mouseout);
}
function doc_mousedown(e){
	var e = is_ie ? event: e;
	obj	= document.getElementById("menu");
	_x	= is_ie ? e.x : e.pageX;
	_y	= is_ie ? e.y + ietruebody().scrollTop : e.pageY;
	_x1 = obj.offsetLeft;
	_x2 = obj.offsetLeft + obj.offsetWidth;
	_y1 = obj.offsetTop - 20;
	_y2 = obj.offsetTop + obj.offsetHeight;
 
	if(_x<_x1 || _x>_x2 || _y<_y1 || _y>_y2){
	   closemenu();
	}
}
function doc_mouseout(e){
	var e = is_ie ? event: e;
	obj	= document.getElementById("showmenu");
	_x	= is_ie ? e.x : e.pageX;
	_y	= is_ie ? e.y + ietruebody().scrollTop : e.pageY;
	_x1 = obj.offsetLeft + 2;
	_x2 = obj.offsetLeft + obj.offsetWidth;
	_y1 = obj.offsetTop - 20;
	_y2 = obj.offsetTop + obj.offsetHeight;
 
	if(_x<_x1 || _x>_x2 || _y<_y1 || _y>_y2){
		closeguide();
	}
}
function IsElement(id){
	return document.getElementById(id)!=null ? true : false;
}
function addEvent(el,evname,func){
	if(is_ie){
		el.attachEvent("on" + evname,func);
	} else{
		el.addEventListener(evname,func,true);
	}
};
function removeEvent(el,evname,func){
	if(is_ie){
		el.detachEvent("on" + evname,func);
	} else{
		el.removeEventListener(evname,func,true);
	}
};
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 - ietruebody().scrollLeft;
}
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 - ietruebody().scrollTop;;
}
function ietruebody(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}
