﻿/*
Description: Blue Homing Script
Version: 1.0.4
Last Modified:　09-07-25
*/

DD_roundies.addRule('#main-content', '8px 8px 0 0', true);

jQuery(this).ready(
	function(){ 
		var _uIE = navigator.userAgent.toLowerCase().indexOf('msie'), //user-agent
		    _uIEv = navigator.userAgent.substr(_uIE+5,1), //IE verson
			_IEtooOld = (_uIE>=0&&_uIEv<=6)?1:0;
		
		if(_IEtooOld){  //Fuck IE!
		}else{
			if(_uIE === -1){
			DD_roundies.addRule('ol.comment-list li', '10px 0 0 0', true);
			DD_roundies.addRule('ol.comment-list li.thread-alt', '0 10px 0 0', true);
			DD_roundies.addRule('#search-query, .children .comment', '3px', true);
			}
			//DD_roundies.addRule('#dsq-comments .dsq-comment', '10px 0 0 0', true);
			//DD_roundies.addRule('#dsq-comments .dsq-odd', '0 10px 0 0', true);
			DD_roundies.addRule('table','4px',true)
			DD_roundies.addRule('#widgets h4', '4px', true);
			DD_roundies.addRule('.widget', '5px', true);
			DD_roundies.addRule('#more-articles li p', '3px', true);
		}
	
		//tweets scrolling
		jQuery('#laodao li').eq(0).addClass('current');
		jQuery('#laodao a').hover(function(){twiOver()},function(){twiOut()});
		//Prettify the twitter dates
		jQuery('#laodao .time').prettyDate();
		setInterval(function(){ jQuery("a").prettyDate(); }, 5000);
		
		if(jQuery('#laodao li.current pre')[0]){
		twi_scroll();
		}

	})


/*
 * JavaScript Pretty Date
 * Copyright (c) 2008 John Resig (jquery.com)
 * Licensed under the MIT license.
 */

// Takes an ISO time and returns a string representing how
// long ago the date represents.
function prettyDate(_time){
	var _date = new Date(_time),
		diff = (((new Date()).getTime() - _date.getTime()) / 1000),
		day_diff = Math.floor(diff / 86400);
			
	if ( isNaN(day_diff) || day_diff < 0 || day_diff >= 31 )
		return;
			
	return day_diff === 0 && (
			diff < 60 && "刚刚发表" ||
			diff < 120 && "1分钟前" ||
			diff < 3600 && Math.floor( diff / 60 ) + " 分钟前" ||
			diff < 7200 && "1 小时前" ||
			diff < 86400 && Math.floor( diff / 3600 ) + " 小时前") ||
		day_diff === 1 && "昨天" ||
		day_diff < 7 && day_diff + " 天前" ||
		day_diff < 31 && Math.ceil( day_diff / 7 ) + " 周前";
}

// If jQuery is included in the page, adds a jQuery plugin to handle it as well
if ( typeof jQuery != "undefined" )
	jQuery.fn.prettyDate = function(){
		return this.each(function(){
			var date = prettyDate(this.title);
			if ( date )
				jQuery(this).text( date );
		});
	};


function twi_scroll() {
	_w1 = jQuery('#laodao li.current pre')[0].clientWidth;
	_w2 = jQuery('#laodao li.current div.content')[0].clientWidth - 10;
	if(_w1>_w2){
		_duration = 200*(jQuery('#laodao li.current a').text().length - 30);
		setTimeout('twi_go()',800);
	}else{
		tr_timeOut = setTimeout('twi_rotate()',4600);
	}
}

function twi_go(){
	try {
			clearTimeout(tr_timeOut);
		} catch(_e) {}
	jQuery('#laodao li.current pre')
		.animate({left: 0},800)
		.animate({left: _w2-_w1},_duration,'linear')
		.animate({left: _w2-_w1},800)
		.animate({left: 0},(_duration+5000)/30,function(){});
	tr_timeOut = setTimeout('twi_rotate()',2400+(_duration+3000)/30+_duration);
}

function twi_rotate(){
	jQuery('#laodao pre').stop(true);
	jQuery('#laodao li.current').next().addClass('current').prev().removeClass('current').animate({marginTop: -18},800,function(){
	jQuery(this).css('marginTop','0').appendTo('#laodao ul');
	jQuery('#laodao pre').css('left','0'); });
	twi_scroll();
}

twiOver = function() {
		try {
			clearTimeout(tr_timeOut);
		} catch(_e) {}
	}

twiOut = function() {
		 tr_timeOut = setTimeout('twi_rotate()',800);
	}