var common=window.common=function(args){};

common.fn=common.prototype={
//窗口大小缩放时尺寸更新
updateSize:function(){
	//解决IE6下圆角absolute 1px bug
	var W=document.body.parentNode.clientWidth;
	document.body.style.width=W<760?(760+'px'):(W%4?((W-W%4)+'px'):(W%2?(W-1)+'px':'100%'));
	
	//解决我的消息iframe尺寸更新
	var ifr=document.getElementById('inholder');
	var left=document.getElementById('left');
	var right=document.getElementById('right');
	if(ifr&&left){
		right.style.width = document.getElementById('in').offsetWidth-left.offsetWidth+'px';
	}
},

/*
	事件绑定
	如:window.onload=fn; -> bind(window,'load',fn);
*/
bind:function(o,ev,fn){
	if (document.all){
		o.attachEvent('on'+ev,fn);////////////IE绑定上但是fn里this指向window
	}
	else{
		o.addEventListener(ev,fn,false);
	}
	return o;
},

/*
	给对象添加一个class
	如:addClass(document.getElementById('id'),'classA classB');
	可以以空格分隔添加多个class
*/
addClass:function (el,cls){
	var arrCls=cls.split(/[ ]+/);
	if(el.className){
		for(var i=0;i<arrCls.length;i++){
			if(el.className.indexOf(arrCls[i])>=0){
				cls=cls.replace(new RegExp('[ ]*'+arrCls[i]+'[ ]*'),' ');////////有缺陷
			}
		}
		el.className=[el.className].concat(cls).join(' ');
	}
	else{
		el.className=cls;
	}
},

/*
	移除对象上的一个class
*/
removeClass:function (el,cls){
	if(el.className){
		if(el.className.indexOf(cls)>=0){
			el.className=el.className.replace(new RegExp('[ ]*'+cls+'[ ]*','g'),' ');
		}
	}
},

/*
	添加/移除对象上的一个class
	没有就添加，有了就移除
*/
toggleClass:function (el,cls){
	if(!el.className||el.className.indexOf(cls)<0){
		common.addClass(el,cls);//11-2
	}
	else{
		common.removeClass(el,cls);//11-2
	}
},

/*
	显示/隐藏一个元素
	@el:Element
	@sh:Boolean true:show; false:hide; undefined:toggle.
*/
show:function(el,sh){
	var dis=el.style.display;
	if(sh==undefined){
		el.style.display=(dis!='none'?'none':'');
	}else{
		el.style.display=sh?'':'none';
	}
},

createFlash:function(idad, swfurl, wad, had, vs){
	var str = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="' + wad + '" height="' + had + '" id="' + idad + '" align="middle">';
	str += '<param name="allowScriptAccess" value="always">';
	str += '<param name="quality" value="high">';
	str += '<param name="movie" value="' + swfurl + '">';
	str += '<param name="wmode" value="opaque">';
	str += '<param name="flashvars" value="' + vs + '">';
	str += '<embed wmode="opaque" src="' + swfurl + '" flashvars="' + vs + '" quality="high" width="' + wad + '" height="' + had + '" name="' + idad + '" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">';
	str += '</object>';
	document.write(str);
},

onClose:function(){
	window.opener = null;
	window.close();   
}

}

common.extend=common.fn.extend=function(a,b){
	for(i in b)a[i]=b[i];
	return a;
};

common.extend(common,common.fn);

(function(){
	function init(){
		var tm=document.getElementById('topswitch');
		if(tm)common.bind(tm,'click',showTopMenu);
		
		//alert(document.getElementById('output').value);
	}
	function showTopMenu(){
		//alert(1);
		common.show(document.getElementById('topmenu'));
	}
	if(window==top)common.bind(window,'load',init);
})();


function initNav(path){
	var path=path||'./';
	var menu=[
		{title:'首页',url:path+'index.html',file:'index.html'},
		{title:'我的帐户',url:path+'acc_index.html',file:'acc_index.html',sb:
			[
				{title:'帐户首页',url:path+'acc_index.html',file:'acc_index.html'},
				{title:'效果报告',url:path+'acc_report.html',file:'acc_report.html'},
				{title:'获取代码',url:path+'acc_code.html',file:'acc_code.html'},
				{title:'积分管理',url:path+'acc_bonus.html',file:'acc_bonus.html'},
				{title:'支付记录',url:path+'acc_pay.html',file:'acc_pay.html'},
				{title:'信息修改',url:path+'acc_modify.html',file:'acc_modify.html'},
				{title:'我的消息',url:path+'acc_msg.html',file:'acc_msg.html'}
			]
		},
		{title:'产品与服务',url:path+'pro_index.html',file:'pro_index.html',sb:
			[
				{title:'产品首页',url:path+'pro_index.html',file:'pro_index.html'},
				{title:'主题推广',url:path+'pro_cpro.html',file:'pro_cpro.html'},
				{title:'网站搜索',url:path+'pro_search.html',file:'pro_search.html'},
				{title:'合作推广',url:path+'pro_uap.html',file:'pro_uap.html'},
				{title:'软件合作',url:path+'pro_soft.html',file:'pro_soft.html'},
				{title:'网吧合作',url:path+'pro_icafe.html',file:'pro_icafe.html'},
				{title:'统计系统',url:path+'pro_tracker.html',file:'pro_tracker.html'},
				{title:'排行榜',url:path+'pro_up.html',file:'pro_up.html'},
				{title:'大连盟认证',url:'http://ulic.baidu.com/',file:'http://ulic.baidu.com/'},
				{title:'解决方案',url:path+'pro_solution.html',file:'pro_solution.html'}
			]
		},
		{title:'积分乐园',url:path+'bon_index.html',file:'bon_index.html',sb:
			[
				{title:'积分首页',url:path+'bon_index.html',file:'bon_index.html'},
				{title:'特惠快讯',url:path+'bon_discount.html',file:'bon_discount.html'},
				{title:'奖品兑换',url:path+'bon_converse.html',file:'bon_converse.html'},
				{title:'积分FAQ',url:path+'bon_faq.html',file:'bon_faq.html'}
			]
		},
		{title:'支持中心',url:path+'sup_index.html',file:'sup_index.html',sb:
			[  
				{title:'常见问题',url:path+'sup_index.html',file:'sup_index.html'},
				{title:'优化技巧',url:path+'sup_skill.html',file:'sup_skill.html'},
				{title:'论坛',url:path+'sup_forum.html',file:'sup_forum.html'}
			]
		}
	];
	
	var url=location.pathname.replace(/\\/g,'/');// /xxx/xxx.xxx
	//var file=(file=url.split('/').pop())?file:menu[0].file; //index.html
	var file=url.split('/').pop();
	var cur=file?-1:0,subcur=0;
	var HTML='';//changed 11-1
		HTML+='<div id="logo"><a href="http://union.baidu.com"><img src="img/slogo-un.gif"></a>　让伙伴更强</div>';
		HTML+='<div id="hd"><div id="tools"><a href="login.html">登录</a> | <a href="login.html">注册</a> | <a href="sup_index.html">帮助</a></div>';
		HTML+='<div id="links"><a href="#">先锋论坛</a>　<a href="#">联盟志</a>　<a href="#">联盟空间</a>　<a href="#">联盟帖吧</a></div>';
		HTML+='<div class="clear"></div>';
		HTML+='<div id="nav"><ul>';
	for(var i=0;i<menu.length;i++){
		HTML+='<li><a href="'+menu[i].url+'">'+menu[i].title+'</a></li>';
		//if(!i)cur=0;
		if(
			file==menu[i].file||
			(function(j){
				var submenu=menu[j].sb;
				if(!submenu)return false;
				for(var k=submenu.length-1;k>=0;k--){
					if(file==submenu[k].file){subcur=k;return true;}
				}
				return false;
			})(i)
		)cur=i;
	}
		HTML+='</ul></div>';
	
	if(cur>=0)var submenu=menu[cur].sb;
	if(submenu){
		HTML+='<div id="subnav">';
		if(cur==1){
			HTML+='<div id="ban"><span class="tt3">会员状态：</span> <img src="img/ban.gif"> <span class="ban">无效</span> [<a href="#">恢复</a>]</div>';
		}
		HTML+='<ul>';
		for(var j=0;j<submenu.length;j++){
			HTML+='<li><a href="'+submenu[j].url+'">'+submenu[j].title+'</a></li>';
		}
		HTML+='</ul>';
		if(cur>1){
			HTML+='<div class="snline"><div class="in" style="margin-left:'+73*(subcur+1)+'px;"></div></div>';
		}
		HTML+='</div></div>';
	}
	
	//alert(HTML.replace(/></g,'>\n<'));
	document.write(HTML);
	
	//var nav=document.getElementById('nav').getElementsByTagName('li');
	if(cur>=0)
		common.addClass(
			document.getElementById('nav').getElementsByTagName('li')[cur],
			'active'
		);
	
	var subnav=document.getElementById('subnav');
	subnav=subnav?subnav.getElementsByTagName('li'):null;
	if(subnav)common.addClass(subnav[subcur],'active');
	
}

function initFoot(){
	document.write('<div id="ft"><p class="links"><a href="about.html">关于联盟</a> | <a href="partner.html">合作伙伴</a> | <a href="event.html">精彩活动</a> | <a href="contact.html">联系我们</a><p class="copy">&copy;2007 Baidu <a href="#">免责声明</a> <a href="#">与百度对话</a></p></div>');
}

/*
	iframe高度自适应
	@ifr:HtmlIframeElement
	@ids:[String] 一组id字符串
	由iframe dom 里的onload属性调用
*/
function adjustIframe(ifr){
	ifr.height=ifr.contentWindow.document.body.scrollHeight;
}

/*
	更新成对互相覆盖的框架高度
	作为顶层页面window.onload的handler
*/
/*
function adjustIframePairs(){
	if(adjustPairs!=undefined){
		for(var i=adjustPairs.length-1,outer,inner,outinner;i>=0;i--){
			outer=document.getElementById(adjustPairs[i].outer);
			inner=document.getElementById(adjustPairs[i].inner);
			if(outer&&inner){
				outinner=outer.contentWindow.document.getElementById(adjustPairs[i].inner);
				outinner.style.height=inner.offsetHeight+'px';
				inner.style.top=outinner.offsetTop;
			}
		}
	}
}
*/
