﻿
// 栏目首页图片幻灯 by worms3000 2009-01-04
// 注释上下滑动，采用左右滑动

//var $ = function (id) {
//	return "string" == typeof id ? document.getElementById(id) : id;
//};

//以下是脚本
var $w = window;
var $d = document;
var $l = location;
function $i(s){return $d.getElementById(s);}
function $t(s){return $d.getElementsByTagName(s);}
function $n(s){return $d.getElementsByName(s);}

var _jsc = {};

_jsc.loaded = false;

_jsc.client = (function(){	
	var t = {};
	var b = navigator.userAgent.toLowerCase();
	t.isOpera = (b.indexOf('opera') > -1);
	t.isIE = (!t.isOpera && b.indexOf('msie') > -1);
	t.isFF = (!t.isOpera &&!t.isIE&&b.indexOf('firefox') > -1);
	return t;
})();

_jsc.util = (function(){
	var t = {};
	t.addEvent = function(o,c,h){
		if(_jsc.client.isIE){
			o.attachEvent('on'+c,h);
		}else{
			o.addEventListener(c,h,false);
		}
		return true;
	};


	return t;
})();



_jsc.evt = (function(){
	var t = {};
	t.gTar = function(oe){
		if(_jsc.client.isIE){
			return oe.srcElement;
		}else{
			return oe.target;
		}
	};
	
	return t;
})();



// tab切换
function tabswitch(c, config){
	this.config = config ? config : {start_delay:5000, delay:5000};
	this.container = $i(c);
	this.pause = false;
	this.nexttb = 1;
	this.tabs = this.container.getElementsByTagName('dt');
	var _this = this;
	if(this.tabs.length<1)this.tabs = this.container.getElementsByTagName('li');
	for(var i = 0; i < this.tabs.length; i++){
		var _ec = this.tabs[i].getElementsByTagName('span');
		if(_ec.length<1)_ec = this.tabs[i].getElementsByTagName('a');
		if(_ec.length<1){
			_ec = this.tabs[i]
		}else{
			_ec = _ec[0];
		}
		_ec.onmouseover = function(e) {
			_this.pause = true;
			var ev = !e ? window.event : e;
			_this.start(ev, false, null);
		};
		
		_ec.onmouseout = function() {
			_this.pause = false;
		};
		
		try{
			$i(this.tabs[i].id + '_body').onmouseover = function(){
				_this.pause = true;
			};
			
			$i(this.tabs[i].id + '_body').onmouseout = function(){
				_this.pause = false;
			};
		}catch(e){}
	}

	if ($i(c + '_sts')) {
		var _sts = $i(c + '_sts');
		var _step = _sts.getElementsByTagName('li');
		if(_step.length<1)_step = _sts.getElementsByTagName('div');
		_step[0].onclick = function() {
			if (_this.tabs[_this.tabs.length-1].className.indexOf('current') > -1) {
				_this.nexttb = _this.tabs.length + 1;
			};
			_this.nexttb = _this.nexttb - 2 < 1 ? _this.tabs.length : _this.nexttb - 2;
			//alert(_this.nexttb);
			_this.start(null, null, _this.nexttb);
		};
		
		_step[1].onclick = function() {
			_this.nexttb = _this.nexttb < 1 ? 1 : _this.nexttb;
			_this.start(null, null, _this.nexttb);
		};
	};
	
	this.start = function(e, r, n){
		if(_this.pause && !e)return;
		if(r){
			curr_tab = $i(_this.container.id + '_' + rand(4));
		}else{
			if(n){
				//alert(_this.container.id + '_' + _this.nexttb);
				curr_tab = $i(_this.container.id + '_' + _this.nexttb);
			}else{
				curr_tab = _jsc.evt.gTar(e);
				if(curr_tab.id=="")curr_tab = curr_tab.parentNode;
			}
		}
		
		var tb = curr_tab.id.split("_");
		for(var i = 0; i < _this.tabs.length; i++){
			if(_this.tabs[i]==curr_tab){
				_this.tabs[i].className="cn6";
				try{
					//alert(_this.tabs[i].id);
					$i(_this.tabs[i].id + '_body').style.display = "block";
				}catch(e){}
			}else{
				_this.tabs[i].className="cn7";
				try{
					$i(_this.tabs[i].id + '_body').style.display = "none";
				}catch(e){}
			}
		}
		_this.nexttb = parseInt(tb[tb.length-1]) >= _this.tabs.length ? 1 : parseInt(tb[tb.length-1]) + 1;
		setTimeout("banners.start(null, null, 1);", 5000);
	};
}


var banners, new_trans, super_rec, crazy_buy, star,bargain_scroll,buy_ok_div;
var select_pr,select_pc,select_cpk;
//_jsc.util.addEvent(window, 'load', function() {
//	if ($i('banners')) {	
//		banners = new tabswitch('banners', {});
//		banners.start(null, null, 1);
//	}
//});


var AutoChagePhoto={
photoList:null,
fotosay_width:464,
fotosay_height:300,
init:function(domID,photoList){
	var divWrap = $('#'+domID);
	if(divWrap.length<=0) return;
	divWrap.append('<ul class="banners_body" id="promotion_banners"></ul>\
                    <div class="points ppt w5" style="bottom:3px;right:0px;z-index:10;">\
                    <div id="banners">\
                        <ul class="left">\
                            <li id="banners_1">1</li>\
                            <li id="banners_2">2</li>\
                            <li id="banners_3">3</li>\
                            <li id="banners_4">4</li>\
                            <li id="banners_5">5</li>\
                            <li id="banners_6">6</li>\
                            <li id="banners_7">7</li>\
                            <li id="banners_8">8</li>\
                            <li id="banners_9">9</li>\
                            <li id="banners_10">10</li>\
                        </ul>\
                        <div class="clear"></div>\
                        </div>\
                    <div class="steps hide" id="banners_sts">\
                    <div class="up">&lt;</div>\
                    <div class="down">&gt;</div>\
                    <div class="clear"></div>\
                    </div>\
                    <div class="clear"></div>\
                    </div>\
    ');
	this.photoList = photoList;
	this.changephoto();
	if ($i('banners')) {	
		banners = new tabswitch('banners', {});
		banners.start(null, null, 1);
	}
},
changephoto:function(){
 if(!this.photoList)return;
 
 //src="'+this.photoList[i].PhotoUrl+'"                  loading完成的
 //src="/common/images/fweb/loading/loading_10.jpg"      loading。。。图片
 
		 for(var i=0;i<this.photoList.length;i++){
		  document.getElementById('promotion_banners').innerHTML += '<li id="banners_'+(i+1)+'_body"><a href="/picture/'+this.photoList[i].PhotoID+'.shtml"><img style="width:'+this.fotosay_width+'px;height:'+this.fotosay_height+'px;" src="'+this.photoList[i].PhotoUrl+'" /></a><div class="f14 fwhite fws color17 h26 lh26 w6a fws"><a href="/u/'+this.photoList[i].UserName+'" target="_blank">'+this.photoList[i].NickName+'</a>：<a href="/picture/'+this.photoList[i].PhotoID+'.shtml">'+this.photoList[i].PhotoTitle+'</a> </div></li>';
		if(i==0){
		    jQuery('#banners_1_body').attr("class","current"); 
		}
		}
}

};

