﻿/*=======================================================
@Name：PageCore.js
@Time: 2011/5/10
@Mail: jjplay@qq.com
@Author：jjplay
@Browser：IE6/7/8,FF3.0/3.5,webkit
=======================================================*/
//checkIndex
function checkIndex(){
	var thisUrl = location.pathname
	thisUrl.replace(/(.*\/){0,}([^\.]+).*/ig,'$2')
	if(thisUrl !='/index.html'){
		window.location.replace('index.html'); 
	}
}

//设为首页
function SetHome(obj, vrl) {
	try {
		obj.style.behavior = 'url(#default#homepage)';
		obj.setHomePage(vrl);
	} catch(e) {
		if (window.netscape) {
			try {
				netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
			} catch(e) {
				alert('抱歉！您的浏览器不支持直接设为首页。请在浏览器地址栏输入“about:config”并回车然后将[signed.applets.codebase_principal_support]设置为“true”，点击“加入收藏”后忽略安全提示，即可设置成功。');
			}
			var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
			prefs.setCharPref('browser.startup.homepage', vrl);
		}
	}
}

//加入收藏
function AddFavorite(sURL, sTitle){
   try{
	   window.external.addFavorite(sURL, sTitle);
   }
   catch (e){
	   try{
		   window.sidebar.addPanel(sTitle, sURL, '');
	   }
	   catch (e){
		   alert('加入收藏失败，请使用Ctrl+D进行添加');
	   }
   }
}

//页标签
function tabSet(a, b) {
	var c = $('[id^=' + b + ']').length;
	c++;
	for (i = 1; i < c; i++) {
		if (a == i) {
			$('#' + b + i).addClass('this')
			$('#c_' + b + i).show();
		} else {
			$('#' + b + i).removeClass('this');
			$('#c_' + b + i).hide();
		}
	}
};

//返回顶部
function backTop(){
	$body=($.browser.Opera)?($compatMode=='CSS1Compat'?$('html'):$('body')):$('html,body');
	$body.animate({scrollTop:'0px'},500);
};

function setHash(a){
	$.browser.msie?$.locationHash(a):location.hash=a;
	//location.hash=a;
}

//getHtml
function loadHtml(htmlUrl){
	$.ajax({
		type: 'get',
		url: htmlUrl +'.html',
		error: function (XMLHttpRequest, textStatus, errorThrown) {
			$('#loading').hide();
			alert ('加载失败请重试...');
		},
		beforeSend:function(){
			$('#loading').show();
		},
		success: function(msg){
			$('#loading').hide();
			$('#mContent').html(msg);
		}
	});
};

//add attr
$.fn.HashPlus = function(){
	return this.attr('href',function(){
		var aHref = $(this).attr('href');
		return "javascript:setHash('"+ aHref.replace('.html','') +"');"
	})
};


//加载
$(document).ready(function(){
	
	checkIndex()
	
	$('#menu a').click(function(){
		$('#menu a').removeClass('thisMenu');
		$(this).addClass('thisMenu');
	});
	
	$.getJSON('news.txt?cache='+Math.random(),function(data){
		$('.ulTeam1').empty();
		var strHTML ='';
		$('.ulTeam1').html('<p><img src="lib/images/load.gif"/></p>');
		$.each(data,function(i,c){
			strHTML += '<li><a href="' + c['url'] + '" target="_blank">' + c['title'] + '</a>';
			$('.ulTeam1').html(strHTML);
		});
	})
	
});
