﻿function search(form){
    switch(parseInt(form.sType.value)){
        case 1:
            window.open('http://www.google.com/search?hl=zh-CN&inlang=zh-CN&ie=GB2312&oe=GB2312&q=' + form.key.value, '', '');
            break;
        case 2:
            window.open('http://search.cn.yahoo.com/search?p=' + form.key.value, '', '');
            break;
        case 3:
            window.open('http://www.baidu.com/baidu?tn=haohu&word=' + form.key.value, '', '');
            break;
        case 4:
            window.open('http://sz.bendibao.com/sou/?key=' + escape(form.key.value), '', '');
            break;
    }
    return (false);
}


function SlideBox(container, frequency, direction) {
 if (typeof(container) == 'string') {
 container = document.getElementById(container);
 }
 this.container = container;
 this.frequency = frequency;
 this.direction = direction;
 this.films = [];
 var lis = this.container.getElementsByTagName('li');
 for (var i = 0; i < lis.length; i++) {
 //if (lis[i].className == 'item') {
 lis[i].onmouseover = function(self){return function(){self._mouseover()};}(this);
 lis[i].onmouseout = function(self){return function(){self._mouseout()};}(this);
 this.films[this.films.length] = lis[i];
 //}
 }
 this._playTimeoutId = null;
 this._slideTimeoutId = null;
 this._slidable = true;
 this._loop();
}

SlideBox.prototype = {
 _loop : function() {
 var sb = this;
 this._playTimeoutId = setTimeout(function(){sb._slide()}, this.frequency);
 },
 _slide : function() {
 var sb = this;
 var _slide = function() {
 if (!sb._slidable) return;
 var c = sb.container;
 if (sb.direction == 'top') {
 if (c.scrollTop < c.offsetHeight-2) {
 c.scrollTop += 2;
 } else {
 clearInterval(sb._slideTimeoutId);
 sb._loop();
 var ul = c.getElementsByTagName('ul')[0];
 ul.appendChild(c.getElementsByTagName('li')[0]);
 c.scrollTop = 0;
 }
 } else if (sb.direction == 'left') {
 if (c.scrollLeft < c.offsetWidth-2) {
 c.scrollLeft += 2;
 } else {
 clearInterval(sb._slideTimeoutId);
 sb._loop();
 var ul = c.getElementsByTagName('ul')[0];
 ul.appendChild(c.getElementsByTagName('li')[0]);
 c.scrollLeft = 0;
 }
 }
 }
 this._slideTimeoutId = setInterval(_slide, 10);
 },
 _mouseover : function() {
 this._slidable = false;
 },
 _mouseout : function() {
 this._slidable = true;
 }
}
