﻿/*-------------- 判断是否显示二级目录 -------------------*/
var mnav2=function(){
	$('#mnav2 div.active').removeClass('active');//清除
	if($('#mnav a.active').length>0){
	var href=$('#mnav a.active').attr('href').replace('../','');
		
		if($('#mnav2 #'+href).length>0){
			$('#mnav2 #'+href).addClass('active');
		}
		else{
		$('#mnav2 div#index').addClass('active');
		}
	}
}
/*----------- 通过You are here 定义导航目前的位置 --------------*/
var mnav_active=function(){	
	var splitStr='>';//导航目录间隔符
	
	$('.active').removeClass('active');//清除	
	
	if($('#b').length>0){
		var bStr=$('#b').text().replace('You are here: ','');
		var bAry=bStr.split(splitStr);
		//一级目录
		$('#mnav a').each(function(){
			if($(this).text().toLowerCase()==$.trim(bAry[0]).toLowerCase())$(this).addClass('active');
			});
		mnav2();//判断是否显示二级目录
		//二级目录
		if(bAry.length>1){
			if($.trim(bAry[1]).toLowerCase()=='products'){
				$('#mnav2 div.active a').each(function(){
					var mtText=$(this).text();
					if($.trim(mtText).toLowerCase()==$.trim(bAry[2]).toLowerCase())$(this).addClass('active');
					});
			}
		}
	}else{
		//首页
		$('#mnav a:first').addClass('active');
		$('#mnav2 div#index').addClass('active');
	}
	
}

var f_action=function(){
	/*----------- 次级导航定位 ------------*/
	$('#mnav a').each(function(){ 
		var href=$(this).attr('href').replace('../','');
		if(href.indexOf('.')==-1){
			$('#mnav2 #'+href).css('left',$(this).offset().left+'px');
		}
	});
	/*---------  主导航鼠标经过 ---------------*/
	$('#mnav a').mouseover(function(){ 
		$('#mnav a.active').removeClass('active');
		$(this).addClass('active');
		mnav2();//判断是否显示二级目录
	});
	$('#mnav_wrap').mouseleave(function(){
		mnav_active();//通过You are here 定义导航目前的位置
		});
}
$(document).ready(function(){
	mnav_active();//通过You are here 定义导航目前的位置
	f_action();
	});

//change products title picture
var pro_title=function(src_str){
	var img=document.getElementById('pro_t');
	if(img){
		img.src='images/'+src_str;
	}
}
//products tabview
var tab_view=function(elid,el){
	var nav=document.getElementById('nav');
	if(nav){
		var a=nav.getElementsByTagName('a');
		for(var i=0;i<a.length;i++){
			if(a[i].className=='sel')a[i].className='';
		}
		el.className='sel';
		el.blur();
	}
	var con=document.getElementById('con');
	if(con){
		var d=document.getElementsByTagName('div');
		for(var i=0;i<d.length;i++){
			if(d[i].className=='sel')d[i].className='';
		}
		document.getElementById(elid).className='sel';
	}
}

//Add to Favorites
function addfavorite()
{
if (document.all)
{ window.external.addFavorite('http://www.archmade.com','ARCH'); }
else if (window.sidebar)
{ window.sidebar.addPanel('ARCH', 'http://www.archmade.com', ""); }
}

//sidebar
var sidnav=function(num){
	var d=document.getElementById('pro_category');
	if(d){
		var dd=d.getElementsByTagName('div');
		for(var i=0;i<dd.length;i++){
			if(i==num){
				dd[num].className='sel';
			}else{
				dd[i].className='';
			}
		}
	}
}

var search_pro=function(){
	var kwd=document.getElementById('search_key').value;
	if(kwd!=''){
		window.location='/search.aspx?kwd='+kwd;
	}else{
		alert('Please Fill In Keyword!');
	}
}
//enquiry.aspx open
$(document).ready(function(){ 
	$('#mnav a.inquiry').click(function(){ 
		window.open('../enquiry.aspx','','width=680,height=470,location=no,toolbar=no,status=no,resizable=yes,scrollbars=yes')
		return false;
	});
})

//获取Cookie
$(document).ready(function(){ 
	if($('span.cookieUser').length>0){
		var temp=$.cookie('userList');
		if(temp==null){
			$('span.cookieUser').html('<a href="/login.aspx">Login</a>');
		}else{
			var temp=getCookieVal(temp,'User');
			temp+=' | <a href="#" onclick="user_quit()">Quit</a>';
			$('span.cookieUser').html(temp);
		}
	}
});
var getCookieVal=function(s,key){
	var ary=s.split('&');
	for(var i=0; i<ary.length; i++){
		if(ary[i].search(key+'=')!=-1){
			return ary[i].replace(key+'=','');
		}
	}
}
var user_quit=function(){
	$.cookie('userList',null);
	window.location=window.location;
}
