﻿document.domain='kefudianhua.cn';
var announce_div_id;

// ---公告拉取--- //
function announce_init(aid)
{
	var xmlHttp;
	announce_div_id = aid;
	var stamp = Math.random() * 100000000000000000;
  send("http://service.qq.com/announce.html?nocache=" + stamp, "GET");
}

function createXMLHttpRequest()
{
  	if(window.ActiveXObject)
  	{
  		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  	}
  	else if(window.XMLHttpRequest)
  	{
			xmlHttp = new XMLHttpRequest();
  	}
}

function send(ur,meth) 
{
	var ifIE = !!document.all;
	createXMLHttpRequest();  
	xmlHttp.open(meth,ur,false);
	if (ifIE) 
	{
		xmlHttp.onreadystatechange = announce_callback;
	}
	xmlHttp.send(null);
	if (!ifIE) 
	{
		if (xmlHttp.readyState == 4 && xmlHttp.status == 200) 
		{
			var mes = xmlHttp.responseText;
			document.getElementById(announce_div_id).innerHTML=mes;
			scrollText.init(announce_div_id, 80);
    	scrollText.scrollUp(); 
		}
	}
}

function announce_callback()
{
	if(xmlHttp.readystate == 4)
	{
		if(xmlHttp.status == 200)
		{
    	var mes = xmlHttp.responseText;
      document.getElementById(announce_div_id).innerHTML=mes;
      scrollText.init(announce_div_id, 50);
    	scrollText.scrollUp(); 
		}
	}
}

// --- 滚动效果 --- //
function next(elem)
{
        do
        {
        	elem=elem.nextSibling;
        }
        while(elem&&elem.nodeType!=1);
        return elem;
}

function first(elem)
{
	elem=elem.firstChild;
	return elem && elem.nodeType!=1?next(elem):elem;
}

var scrollText=
{
	init:function(scrollbox,speed)
	{
		this.boxID = scrollbox;
		this.scrollSpeed = speed || 50; 
	},
	obj : function()
	{
		var scrollBox = document.getElementById(this.boxID);
		var appendBox=first(scrollBox).cloneNode(true);

		scrollBox.appendChild(appendBox);
		return {
                   scrollBox : scrollBox,
                   appendBox : appendBox, 
                   scrollSpeed :scrollText.scrollSpeed
            }; 
	},
	scrollUp : function()
	{   
		var m = this.obj();
		var doTimeout;
		var doScr = setInterval(function(){ 
                		if(m['appendBox'].offsetHeight <= m['scrollBox'].scrollTop)
                		{
                    	m['scrollBox'].scrollTop -= m['appendBox'].offsetHeight;
                		}
                		else if (m['scrollBox'].scrollTop % m['scrollBox'].firstChild.firstChild.offsetHeight == 0)
                		{
                			clearInterval(doScr);
                			doTimeout = setTimeout(function(){
                			scrollText.init(m['scrollBox'].id, m['scrollSpeed']);
                			scrollText.scrollUp();},1000);
                			
                			m['scrollBox'].scrollTop++;
                		}
                		else
                		{
                    	m['scrollBox'].scrollTop++;
                		}
            			},
            			this.scrollSpeed
            		);
                
   m['scrollBox'].onmouseover=function()
   					{
                clearInterval(doScr);
                clearTimeout(doTimeout);
            }
  
            m['scrollBox'].onmouseout=function()
            {     
                clearInterval(doScr);
                scrollText.init(this.id, m['scrollSpeed']);
                scrollText.scrollUp();
            }
	}
}
