function addFavorite(url, title) {
	if (document.all) {
		window.external.addFavorite(url, title);
	} else if (window.sidebar) {
		window.sidebar.addPanel(title, url, "");
	}
}

function addBookmark(title,url) {
    if (window.sidebar) { 
        window.sidebar.addPanel(title, url,""); 
    } else if( document.all ) {
        window.external.addFavorite( url, title);
    } else if( window.opera && window.print ) {
        return true;
    }
}

function setHomepage(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) {
				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', url);
	}
}


function newsPlayer(props) {
    this.newsId = props.id ? props.id : null;
    this.lineHeight = props.lineHeight ? props.lineHeight : 0;
    this.interval = props.interval ? props.interval : 5000;
    this.currentId = 0;
    this.pause = false;
    var self = this;
    if (this.newsId) {
        var newsbox = document.getElementById(this.newsId).getElementsByTagName('UL')[0];
        var li_arr = newsbox.getElementsByTagName('LI');
        this.newsObj = newsbox;
        this.newsCount = li_arr.length;
        this.newsGroup = li_arr;
        var newsA_arr = newsbox.getElementsByTagName('A');
        for (var i = 0; i < newsA_arr.length; i++) {
            (function(i) {
                newsA_arr[i].onmouseover = function() { self.pause = true };
                newsA_arr[i].onmouseout = function() { self.pause = false };
            })(i);
        }
        var handle = document.createElement('ol');
        handle.className = 'handle';
        for (var i = 0; i < li_arr.length; i++) {
            if (this.currentId == i) {
                handle.innerHTML += '<li><a class="current" href="javascript:void(0)"></a></li>';
            } else {
                handle.innerHTML += '<li><a href="javascript:void(0)"></a></li>';
            }
        }
        newsbox.parentNode.appendChild(handle);
        var handleA_arr = handle.getElementsByTagName('A');
        this.handleGroup = handleA_arr;
        for (var i = 0; i < handleA_arr.length; i++) {
            (function(i) {
                handleA_arr[i].onclick = function() { self.next(i); };
                handleA_arr[i].onfocus = function() { this.blur(); };

            })(i);
        }
        this.play();
    }
    this.next = function(i) {
        this.currentId = i;
        clearTimeout(this.handleInterval);
        clearTimeout(this.handleInterval2);
        this.play();
    }
}

newsPlayer.prototype.play = function() {
    var self = this;
    var currObj = null;
    function event() {
        if (!self.pause) {
            var li_arr = self.newsGroup;
            for (var i = 0; i < li_arr.length; i++) {
                if (self.currentId == i) {
                    li_arr[i].style.display = 'block';
                    li_arr[i].style.marginTop = self.lineHeight + 'px';
                    self.handleGroup[i].className = 'current';
                    currObj = li_arr[i];
                } else {
                    li_arr[i].style.display = 'none';
                    li_arr[i].style.marginTop = '0px';
                    self.handleGroup[i].className = 'none';
                }
            }
            event2();
            self.currentId = (self.currentId == self.newsCount - 1 ? 0 : ++self.currentId);
        }
        self.handleInterval = setTimeout(event, self.interval);
    }
    function event2() {
        currObj.style.marginTop = parseFloat(currObj.style.marginTop) - 1 + 'px';
        if (parseFloat(currObj.style.marginTop) > 0) {
            self.handleInterval2 = setTimeout(event2, 10);
        }
    }
    event();
}