// JavaScript Document

(function(window, $){

var document = window.document,
	href = window.location.href;
	
// ie9- location BUG!
$.goLocation = function(url){
    $.msieVersion < 9 ? 
        setTimeout(function(){ window.location.href = url; }) : 
        (window.location.href = url);
    return false;
};

// 向文档根元素添加样式
$('html').
	addClass('js');

// 加载公用头部
$.ajax({
	url: '/inc/siteTop.html',
	success: function(data){
		$(function(){
			$.byId('siteTop') || $(data).prependTo(document.body);
		});
	}
});

// 加载公用导航
$.ajax({
	url: '/inc/nav.html',
	success: function(data){
		
		$(function(){
			$.byId('nav') || $(data).afterTo('#header');
			
(function(){
	
	var body = document.body,
		channel = body.id;
	
	if( channel && channel !== 'page_index' && (channel = channel.slice(5)) ){
		
		$('#aNav').
			html( $('#nav_' + channel).html().replace(/(<a.+?<\/a>)/i, '<h2 class="body-article-title">$1</h2>') ).
				find('ul a').
					some(function(a){
						if( href.indexOf( a.href ) === 0  ){
							return $(a).ancestor('li').addClass('current');
						}
					});
	}
	
})();	
			
			$('#navList>li').mouseenter(function(e){
				$(this).sibs().removeClass('current');
				$(this).addClass('current');
			}).mouseleave(function(e){
				$(this).removeClass('current');
			});
			
//			$('<textarea style="position:absolute;top:0;right:0;width:30%;height:100%;"/>').
//			appendTo('body').
//			val( jScaler('#navList>li').map(function(li){
//				var id = li.id;
//				return '#page_' + id.slice(3) + ' #' + id + ' a b';
//				
//			}).join(',\r'));
			
		});
	}
});

// 加载友情链接
$.ajax({
	url: '/inc/links.html',
	success: function(data){
		$(function(){
			
			$.byId('links') || $(data).appendTo('#bodyer');
			
			$.UI.Marquee && $(function(){
				
			$('#links .Marquee', function(el){
				new $.UI.Marquee(el, {
					direction: 'left',
					interval: 2000
				});
			});
			
			});
			
		});
	}
});

// 加载公用页脚
$.ajax({
	url: '/inc/footer.html',
	success: function(data){
		$(function(){
			$.byId('footer') || $(data).appendTo('#wrapper');
		});
	}
});


})(this, zCool);
