/*
 * @description 卖家频道头部导航位置提醒和速卖通下拉菜单功能。
 *   从原有多个js中抽离并进行重写，便于维护和使用。
 *   包含两部分：
 *   1.根据当前Url对用户所在的位置进行提醒
 *   2.初始化速卖通后台入口的下拉菜单
 * 
 *   唯一的全局变量：navigation
 * 
 * @author wb_fei.xu@alibaba-inc.com
 * @revise 2011-11-09
 * 
 */
if (!window.navigation) {
	window.navigation = function () {
		this.navConfig = {
			homeUrl1 : 'http://seller.aliexpress.com/index.html',
			homeUrl2 : 'http://seller.aliexpress.com/',
			homeUrl3 : 'http://seller.aliexpress.com/?',
			navMap : {
				'seller.aliexpress.com/notice/' : 'mintro',
				'seller.aliexpress.com/product/' : 'product',
				'seller.aliexpress.com/freight/' : 'freihgt',
				'seller.aliexpress.com/agent/' : 'mpromotion',
				'seller.aliexpress.com/education/' : 'mbusiness',
				'ask.aliexpress.com' : 'ask'
			}
		};
		this.meEnterConfig = {
			targetId : 'myaliexpress',
			contentId : 'myaliexpress-content'
		};
	};
	window.navigation.prototype = {
		init : function () {
			this.setNavCurrent();
			this.bind();
		},
		bind : function () {
			var target = document.getElementById(this.meEnterConfig.targetId),
				content = document.getElementById(this.meEnterConfig.contentId);
                
			this.addHandler(target, 'mouseover', function(){
				target.className += ' onshow';
                content.style.display = 'block';
			});
			this.addHandler(target, 'mouseout', function(){
				target.className = target.className.replace(/(\s*)?onshow(\s*)?/g, ' ');
                content.style.display = 'none';
			});
		},
		setNavCurrent : function () {
			var Url = document.location.href,
				homeUrl1 = this.navConfig.homeUrl1,
				homeUrl2 = this.navConfig.homeUrl2,
				homeUrl3 = this.navConfig.homeUrl3,
				navMap = this.navConfig.navMap,
				currentSM = null;
				
			if (Url == homeUrl1 || Url == homeUrl2 || Url.indexOf(homeUrl3) > -1) {
				currentSM = document.getElementById('mhome');
				currentSM.className += ' ' + 'current';
			} else {
				for (var key in navMap) {
					if (Url.indexOf(key) != -1) {
						currentSM = document.getElementById(navMap[key]);
						currentSM.className += ' current';
						break;
					};
				};
			};
		},
		addHandler : function (el, type, handler) {
			if (el.addEventListener) {
				el.addEventListener(type, handler, false);
			} else if (el.attachEvent) {
				el.attachEvent('on' + type, function (e) {
					handler.call(el, e);
				});
			} else{
				el['on' + type] = handler;
			};
		}
	};
};
(new window.navigation).init();
