﻿//获取目标id或相应id下的某个元素集合
var _$ = function(id,elN){
		if(elN && id){
			return document.getElementById(id).getElementsByTagName(elN);
		}else{
			return document.getElementById(id);
		}
	},
	
	//浏览器判断
	isIE = document.all,
	isFF = window.XMLHttpRequest;
	
/*容器垂直滚动
 div为主要容器ID；
 delay为延迟执行时间,也就是setTimeout的时间；
 speed容器滚动的速度；
 lh，滚动的高度。
 bType,为滚动容器的类型
*/
function slideLine(div, delay, speed,lh,bType) {
	var slideBox = _$(div);
	var tid = null, pause = false;
	var start = function() {
		tid = setInterval(slide, speed);
	}
	var slide = function() {
		if (pause) return;
			slideBox.scrollTop += 2;
		if (slideBox.scrollTop % lh == 0) {
			clearInterval(tid);
			slideBox.appendChild(_$(div,bType)[0]);
			slideBox.scrollTop = 0;
			setTimeout(start, delay);
		}
	}
	slideBox.onmouseover=function(){pause=true;}
	slideBox.onmouseout=function(){pause=false;}
	setTimeout(start, delay);
}

//选项卡
function chgTab(theObj,cId,n,reC){
	var reC,liW,lis;
	if(theObj.className == reC)return;
	var tabList2 = _$(cId,"li");
	for(var i = 0; i < tabList2.length; i++){
		var dIds=cId+i;
		var dbox = _$(dIds);
		if (i == n){
			theObj.className = reC;
			dbox.style.display = "block";
		}else{
			tabList2[i].className = ""; 
			dbox.style.display = "none";
		}
	} 
}

//公用的类生成与绑定函数
function doNew(c,p){
	function thsNew(){
		c.creat.apply(this,p);
	};
	thsNew.prototype = c;
	return new thsNew();
}

var inScroll = {
	creat:function(bid,pclass,fd,i){
		this.bid = bid;
		this.fd = fd;
	},
	init:function(){//初始化
		var ul = _$(this.bid,"ul")[0],
			lis = _$(this.bid,"li"),
			lw = lis[0].scrollWidth + this.fd,
			ls = lis.length,
			sps = _$(this.bid,"span"),
			iN,iB;
		for(var i = 0;i<sps.length;i++){
			if(sps[i].className == "next"){
				iN = sps[i];
			}
			if(sps[i].className == "back"){
				iB = sps[i];
			}
		}
		ul.style.width = (lw * ls) + "px";
		ul.style.marginLeft = "0";
		
		iN.onclick = function(){
			inScroll.isNext(ul,lw,ul,lis)
		}
		iB.onclick = function(){
			inScroll.isBack(ul,lw,ul,lis)
		}

	},
	isNext:function(ul,lw,ul,lis){
		var aN
		function goNext(){
			var tm = Math.abs(parseInt(ul.style.marginLeft));
			if(tm < lw){
				ul.style.marginLeft = "-" + Math.ceil(tm + lw/10) + "px"
			}else{
				clearInterval(aN);
				ul.style.marginLeft = "0";
				inScroll.reSet(ul,lis,0);
			}
		}
		aN = setInterval(function(){goNext()},50);
	},
	isBack:function(ul,lw,ul,lis){
		var aB;
		function goBack(){
			var tb = Math.abs(parseInt(ul.style.marginLeft));
			if(tb < lw){
				ul.style.marginLeft = Math.ceil(tb + lw/5) + "px"
			}else{
				clearInterval(aB);
				ul.style.marginLeft = "0";
				inScroll.reSet(ul,lis,1);
			}
		}
		aB = setInterval(function(){goBack()},30);
	},
	reSet:function(ul,lis,t){
		if(t == 0){ul.appendChild(lis[0]);}
		if(t == 1){
			var tt = lis.length -1
			ul.insertBefore(lis[tt],lis[0])
		}
		 
	}
}

function scrollPic(bid,pclass,fd,i){
	var newPic = doNew(inScroll,[bid,pclass,fd,i]);
	newPic.init();
}
var jq = jQuery.noConflict();
/*function showTip(tid,w,class,pf){
	var t = jq("#" + tid),
		arr = jq("#" + tid + " b");
		
	arr.addClass(class)
	t.click(function(){
		t.animate({
			left:"toggle",
			opacity:"hide"
		},300)
	})
	var showIs = function(){
		t.css({
		width:w + "px",
		left:pf + "px",
		})
		
		t.animate({
			left:"toggle",
			opacity:"show"
		},300)
		
		
	}
	showIs()
}
*/
function showImgTip(tag){
	var tg = jq(tag),
		pt = document.createElement("p"),ot;
	pt.className = "gameTip";
	pt.id="gTp"
	pt.innerHTML = "点击图片可放大";
	tg.offsetParent().append(pt);	
	jq("#gTp").animate({
		opacity:"show"
	},"slow")
	
	var hidet = function(){
		jq("#gTp").animate({
			opacity:"hide"
		},"slow")
		jq("#gTp").remove()
		clearTimeout(ot)
	}
	jq(document).click(function(){hidet()})
	ot = setTimeout(function(){hidet()},1000)
}




function alerts(){alert("1")}


function showTip2(tid2,class2,fd,w2,info){
	if(_$("tips")){return}
	var tg = jq("#" + tid2),
		tbox = document.createElement("div");

	tbox.className = "theTip";
	tbox.id = "tips";
	tbox.innerHTML = "<div><p></p><b></b></div>"
	jq("body").append(tbox);
	
	
	
	var arr = jq("#tips b:first"),
		pp = jq("#tips p:first"),
		t = jq("#tips");	
	
	t.css({
		width:w2 + "px",
		left:tg.offset().left + "px",
		top:tg.offset().top + tg.height() + "px"
	})
	arr.addClass(class2)
	pp.html(info)
	var showIs = function(){
		t.animate({
			left:tg.offset().left + fd + "px",
			opacity:"show"
		},600)		
	},
	hidets = function(){
		jq("#tips").animate({
			opacity:"hide"
		},600)
		jq("#tips").remove()
		clearTimeout(ot)
	}
	jq(document).click(function(){hidets()});
	t.click(function(){hidets()});
	showIs();
	ot = setTimeout(function(){hidets()},3000);
}

function showAd(Bp,Sp,cClass,num,d){
	var bigs = jq("#" + Bp),
		bs = jq("#" + Bp + " li"),
		smalls = jq("#" + Sp),
		ss = jq("#" + Sp + " li");
		
	var showBig = function(ns){
			bs.removeAttr("style");
			bs.eq(ns).css("display","block");
		},
		ctrlBar = function(){
			for(var ti = 0;ti<ss.length;ti++){
				ss[ti].onclick = function(){
					var nt = jq(this).attr("value") -1;
					ss.removeClass("isOn");
					jq(this).addClass("isOn");
					showBig(nt)
				}
			}
		},
		innt = function(){
			bs.eq(0).css("display","block");
			ss.eq(0).addClass(cClass);
			ctrlBar();
			//autoPlay();
		}
	innt();
}








