/*js by davidguoshuang at gmail.com*/

//setHomePage jquery plugin
jQuery.extend({
setHomepage: function(url) {
if (document.all) {
 document.body.style.behavior = 'url(#default#homepage)';
 document.body.setHomePage(url);
}
else if (window.sidebar) {
 if (window.netscape) {
  try {
   netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
  }
  catch (e) {
   var strTemp = '';
   strTemp += "this action was aviod by your browser,";
   strTemp += "if you want to enable,please enter about:config in your address line,";
   strTemp += "and change the value of signed.applets.codebase_principal_support to true";
   alert(strTemp);
  }
 }
 var prefs = Components.classes['@mozilla.org/preferences-service;1']
     .getService(Components.interfaces.nsIPrefBranch);
 prefs.setCharPref('browser.startup.homepage', url);
}
}
});

//setCookie 定义---------------------start------------------------------------------------
function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name)
{
	createCookie(name,"",-1);
}
//setCookie 定义---------------------end------------------------------------------------

jQuery.noConflict(); 
jQuery(document).ready(function($) {
///////////////////////////////////////////////////

$('body.home').prepend('<base target="_blank" />')
$('a[rel=external]').attr('target','_blank');
$('form[rel=external]').attr('target','_blank');

$('input:submit,input:reset,button,input:button').each(function(){
	if(!$(this).hasClass('defaultBtn')){$(this).addClass('submitButton')}
})

$('input:text,input:password').addClass('inputText');

$('.addhome').click(function(){
	$.setHomepage(window.location);
	return false;
})


$('.fav').click(function(){
      var ctrl = (navigator.userAgent.toLowerCase()).indexOf('mac') != -1 ? 'Command/Cmd' : 'CTRL'; 
        if (document.all){
          window.external.addFavorite(window.location,document.title);
          }else if (window.sidebar){
         window.sidebar.addPanel(document.title, window.location, '');
       }else {
               alert('您可以尝试通过快捷键' + ctrl + ' + D 加入到收藏夹~');
       }
	   return false;
})

//guoshuang marquee /*gMarquee*/
$('.gMarquee').each(function(){
	
	var marqueeTotal=$(this).find('li').length;
	var marqueeNum=1;
	var othis=$(this);
	var marqueeTimer;
	var marqueeDealy=3000;
	  
	function doMarquee(){
		  marqueeTimer=setInterval(function(){			  
			  if(marqueeNum>marqueeTotal)marqueeNum=1;
			  othis.find('li').hide();
			  othis.find('li:nth-child('+marqueeNum+')').stop().fadeIn();
			  marqueeNum+=1;			  
		  },marqueeDealy)
		  }			  
	doMarquee();	
	othis.mouseover(function(){clearInterval(marqueeTimer);}).mouseout(function(){doMarquee();})
})

$('div.border').wrapInner('<div class="borderDiv"></div>')


//图片翻滚
var imgGalleyli=$('#imgGallery li');
var imgNum=imgGalleyli.length;
var imgstart=2;
var galleyDelay=10000;
var galleryTimer;

//初始化
imgpagerhtml='<div class="opager">';
for(i=1;i<=imgNum;i++){
	imgpagerhtml=imgpagerhtml+'<a href="#'+i+'">'+i+'</a>';
}
imgpagerhtml=imgpagerhtml+'</div>';
$('#imgGallery').after(imgpagerhtml);

//$('#imgGallery li:nth-child(1)').css({'display':'block'}); 
imgGalleyli.hide();
$('#imgGallery li:nth-child(1)').show();
$('.imgNews .opager a:nth-child(1)').addClass('current');

function imgSlide(){
	galleryTimer=setInterval(function(){
	if(imgstart>imgNum)imgstart=1;
	imgGalleyli.hide();
	$('.imgNews .opager a').removeClass('current');
	$('.imgNews .opager a:nth-child('+imgstart+')').addClass('current')
	$('#imgGallery li:nth-child('+imgstart+')').fadeIn('fast');
	imgstart+=1;
	},galleyDelay)
}

imgSlide();

$('#imgGallery li').mouseover(function(){
	clearInterval(galleryTimer);
}).mouseout(function(){
	imgSlide();
})

$('.imgNews .opager a').click(function(){
	num=$(this).index()+1;
	clearInterval(galleryTimer);
	$(this).parent().find('a').removeClass('current');
	$(this).addClass('current');
	imgGalleyli.hide();
	$('#imgGallery li:nth-child('+num+')').fadeIn('fast');
	imgstart=num+1;
	imgSlide();
	return false;
})

//newsTabs
$('.newsTabs').each(function(){
	var olist=$(this).find('.olist');
	olist.find('ul.list:nth-child(1)').css({display:'block'})/*4 chrome*/
	olist.find('ul.list:nth-child(1)').show();
	$(this).find('h2 .subTitle span:nth-child(1)').addClass('now')
;	$(this).find('h2 .subTitle span').mouseover(function(){$(this).parent().find('span').removeClass('now');$(this).addClass('now');onum=$(this).index()+1;olist.find('ul.list').hide();olist.find('ul.list:nth-child('+onum+')').show();}).mouseout(function(){/*nothing*/})
	
})

//hot article

//fuck sitefactory code//////////////////////////////////////

//kill the first home link 
//$('#navi li:first').css({display:'none'})

$('.guoSiteMap ul:nth-child(3n+2)').before('<div class="clearboth" style="height:10px;"></div>')


//$('#lifeTools div:nth-child(3n+1)').addClass('clearboth')
//$('#lifeToolsAll div.border:nth-child(3n+1)').css('background','red')
$('.lifeToolsAll ul').after('<div class="clearboth" style="height:10px;"></div>')


//flash mp3 player
//mp3inside

$('.mp3inside li').each(function(){
	if($(this).find('.mp3url').text()==''){return;}
	var mp3url='/UploadFiles/'+$(this).find('.mp3url').text().split('|')[1];
	$(this).prepend('<span class="swfplayer" title="播放">123</span>');	
	$(this).find('.swfplayer').flash({swf:'/player5.swf',width:14,height:14,flashvars:{sound:mp3url},menu:false})
})

/*
$('.mp3Content').each(function(){
	var mp3url='/UploadFiles/'+$(this).find('.mp3url').text().split('|')[1];
	$(this).find('.downloadBtn').before('<span class="swfplayer" title="播放">123</span>');
	$(this).find('.swfplayer').flash({swf:'/player5.swf',width:14,height:14,flashvars:{sound:mp3url},menu:false})
	$(this).find('.downloadBtn').attr('href',mp3url);
})
http://www.google.com/reader/ui/3523697345-audio-player.swf
*/

$('.gmp3swfplayer').each(function(){
	if($(this).text()==''){return;}
	var mp3url='/UploadFiles/'+$(this).text().split('|')[1];
	//$(this).append('<div class="swfplayer" title="播放"></div>');
	$(this).css('text-align','center').css('margin-top','10px').flash({swf:'http://www.google.com/reader/ui/3523697345-audio-player.swf',width:400,height:27,flashvars:{audioUrl:mp3url},menu:false});
	$(this).append(' <a href="'+mp3url+'">下载地址</a>')
})


/*
$('.mp3Player .playBtn').click(function(){
	ourl='/UploadFiles/'+$(this).parent().find('.mp3url').text().split('|')[1];
	$(this).before('<span class="playerswf" title="播放"></span>');
	$(this).parent().find('.playerswf').flash({swf:'/player4.swf',width:14,height:14,flashvars:{sound:ourl}})
})
*/

if($('body').hasClass('home')){// home page only

	//最后加入天气
	$('body.home #gLogoDiv').append('<div id="weather"><iframe id="dis" marginwidth="0" marginheight="0" hspace="0" vspace="0" src="http://m.weather.com.cn/m/pn3/weather.htm?id=101110901T" name="pn3" frameborder="0" height="20" scrolling="No" width="225"></iframe></div>')
	
	//$('#weather').html('<iframe id="dis" marginwidth="0" marginheight="0" hspace="0" vspace="0" src="http://m.weather.com.cn/m/pn3/weather.htm?id=101110901T" name="pn3" frameborder="0" height="20" scrolling="No" width="225"></iframe>');
	
	
	//friendLinks
	var friendLinks=$('#friendLinks');
	friendLinks.find('h2 span:first').addClass('now');
	friendLinks.find('.oLinks').find('ul:first').css({display:'block'}).show();/*4 chrome*/
	friendLinks.find('h2 span').mouseover(function(){$(this).parent().find('span').removeClass('now');$(this).addClass('now');onum=$(this).index()+1;friendLinks.find('ul').hide();friendLinks.find('.oLinks').find('ul:nth-child('+onum+')').show();})

}

$('iframe').attr('frameBorder',0);
	
$('#gsLoginDiv').prependTo('#gHeaderDiv .loginDiv');//把登录挪到头部
$('#bottomNav a:last').css({border:0})

$('ul.hot').each(function(){
	$(this).find('li:nth-child(1)').addClass('first');
	$(this).find('li:nth-child(2)').addClass('second');
	$(this).find('li:nth-child(3)').addClass('third');
})


////////////////////////////////////
});
