﻿
/*
 * moveControl v1.5
 * http://www.yao018.com/
 * Copyright (c) 2010 Rudder.D.Zhang
 * Date: 2010-03-10 11:23
 * 参数：外容器ID，容器ID，默认显示个数，每次移动个数
 */

var MoveControl = {
	iniUnit : function(wrapId, id, dftNum, intStep) {
		var obj = $(id).find(".moveUnit");
		var objNum = obj.length;
		if (objNum > dftNum) {
			MoveControl.addEvent(wrapId, id, dftNum, "next", intStep)
		}
	},
	addEvent : function(wrapId, id, dftNum, strPN, intStep) {
		var strTitle;
		var objClick = $(wrapId + " ." + strPN + "Enabled");
		var objNumHref = objClick.find("a").length;
		objClick.removeClass(strPN + "Disabled");
		
		if (objNumHref != 0)
			objClick = objClick.find("a");
		
		strTitle =  objClick.text();
		objClick.attr("title", strTitle);
		objClick.click(function(){
			MoveControl.moveUnit(wrapId, id, dftNum, strPN, intStep);
			return false;
		});
	},
	moveUnit : function(wrapId, id, dftNum, strPN, intStep) {
		if ($(wrapId).data("currSubName") != null)
			id = $(wrapId).data("currSubName");
		var n = $(id).data("nowUnit");
		if (isNaN(n) || n == null) n = 0;
		
		var objClick = $(wrapId + " ." + strPN + "Enabled");
		var objNumHref = objClick.find("a").length;
		objClick.removeClass(strPN + "Disabled");
		if (objNumHref != 0)
			objClick = objClick.find("a");
	
		var obj = $(id).find(".moveUnit");
		var objNum = obj.length;
		
		if (strPN == "next") {
			for (var i = 0; i < intStep; i++) {
				$(obj[n]).hide("fast");
				if (n == 0) {
					$(wrapId + " .previousEnabled").removeClass("previousDisabled");
					MoveControl.addEvent(wrapId, id, dftNum, "previous", intStep);
				}
				n++;
				if (n == (objNum - dftNum)) {
					n = objNum - dftNum;
					$(wrapId + " .nextEnabled").addClass("nextDisabled");
					objClick.unbind("click").attr("title", "");
					break;
				}
			}
		}else {
			for (var i = 0; i < intStep; i++) {
				n--;
				if (n >= 0){
					$(obj[n]).show("fast");
				}
				if (n + dftNum + intStep == objNum) {
					$(wrapId + " .nextEnabled").removeClass("nextDisabled");
					MoveControl.addEvent(wrapId, id, dftNum, "next", intStep);
					if (n < 0) {
						n = 0;
						break;
					}
				}
				if (n <= 0) {
					$(wrapId + " .previousEnabled").addClass("previousDisabled");
					objClick.unbind("click").attr("title", "");
					if (i + 1 == intStep) n = 0;
				}
			}
		}
		
		$(id).data("nowUnit", n);
	}
}

function H$(i) {return document.getElementById(i)}
function H$$(c, p) {return p.getElementsByTagName(c)}


var FadeSlider = function () {
	function init (o) {
		this.isOver = false;
		this.id = o.id;
		$('#'+o.id).bind('mouseover', {thisobj: this}, function(event) { event.data.thisobj.pause();});
		$('#'+o.id).bind('mouseout', {thisobj: this}, function(event) { event.data.thisobj.resume();});
		this.at = o.auto ? o.auto : 3;
		this.o = 0;
		var wp = H$(o.id), ul = H$$('ul', wp)[0], li = H$$('li', ul); _this = this;
		this.l =  li.length;
		wp.style.cssText = 'position:relative;overflow:hidden;width:'+ul.offsetWidth+'px;height:'+o.height+'px';
		ul.style.cssText = 'position:absolute;left:0;top:0;width:'+ul.offsetWidth+'px';
		this.ulid = ul.id = !!ul.id ? ul.id : 'my-fade-slide-ul-'+o.id;

		for(i = 0; i < parseInt(Math.random() * li.length) ; i++)
		{
			var el = H$(this.ulid), li = H$$('li', el);
			var cl = li[this.l-1].cloneNode(true);
			el.insertBefore(cl, el.firstChild);
			var list = H$$('li',H$(this.ulid));
			H$(this.ulid).removeChild(list[list.length-1]);
		}

		this.pos();
	}
	init.prototype = {
		pos : function () {
			//alert(this.isOver)
			if (this.isOver) return;
			clearInterval(this.__b);clearInterval(this.__a);clearInterval(this.__c);
			this.o = 0;
			var el = H$(this.ulid), li = H$$('li', el);
			var _t = li[this.l-1].offsetWidth;
			var cl = li[this.l-1].cloneNode(true);
			el.insertBefore(cl, el.firstChild);
			el.style.left = -_t + 'px';
			this.anim();
		},
		anim : function () {
			var _this = this;
			this.__a = setInterval(function(){_this.animH()}, 1);
		},
		animH : function () {
			var _t = parseInt(H$(this.ulid).style.left), _this = this;
			if (_t >= -1) {
				clearInterval(this.__a);
				H$(this.ulid).style.left = 0;
				var list = H$$('li',H$(this.ulid));
				H$(this.ulid).removeChild(list[list.length-1]);
				//list[list.length-1] = null;
				this.__c = setInterval(function(){_this.animO()}, 20);
				//this.auto();
			}else {
				var __t = Math.abs(_t) - Math.ceil(Math.abs(_t)*.3);
				H$(this.ulid).style.left = -__t + 'px';
			}
		},
		animO : function () {
			this.o += 10;
			if (this.o == 100) {
				clearInterval(this.__c);
				if (!this.isOver) this.auto();
			}else {
			}
		},
		auto : function () {
			var _this = this;
			this.__b = setInterval(function(){_this.pos()}, this.at*1000);
		},
		pause : function () {
			clearInterval(this.__b);
			this.isOver = true;
		},
		resume : function () {
			if (this.isOver) {
				clearInterval(this.__b);
				this.auto();
				this.isOver = false;
			}
		}
	}
	return init;
}();

/* primary banner slide effect */
var TINY={};

function T$(i){return document.getElementById(i)}
function T$$(e,p){return p.getElementsByTagName(e)}

TINY.slider=function(){
	function slide(n,p){this.n=n; this.init(p)};
	slide.prototype.init=function(p){
		var s=T$(p.id), u=this.u=T$$('ul',s)[0], c=T$$('li',u), l=c.length, i=this.l=this.c=0;
		if(c.length == 0) return;
		if(p.navid&&p.activeclass){this.g=T$$('li',T$(p.navid)); this.s=p.activeclass}
		this.a=p.auto||0; this.p=p.resume||0; this.v=p.vertical||0; s.style.overflow='hidden';
		for(i;i<l;i++){if(c[i].parentNode==u){this.l++}}
		if(this.v){;
			u.style.top=0; this.h=p.height||c[0].offsetHeight; u.style.height=(this.l*this.h)+'px'
		}else{
			u.style.left=0; this.w=p.width||c[0].offsetWidth; u.style.width=(this.l*this.w)+'px'
		}
		this.pos(p.position||0,this.a?1:0)
	},
	slide.prototype.auto=function(){
		this.u.ai=setInterval(new Function(this.n+'.move(1,1)'),this.a*1000)
	},
	slide.prototype.move=function(d,a){
		var n=this.c+d, i=d==1?n==this.l?0:n:n<0?this.l-1:n; this.pos(i,a)
	},
	slide.prototype.pos=function(p,a){
		clearInterval(this.u.ai); clearInterval(this.u.si);
		var o=this.v?parseInt(this.u.style.top):parseInt(this.u.style.left),
		t=this.v?p*this.h:p*this.w, d=t>Math.abs(o)?1:-1; t=t*-1; this.c=p;
		if(this.g){for(var i=0;i<this.l;i++){this.g[i].className=i==p?this.s:''}}
		this.u.si=setInterval(new Function(this.n+'.slide('+t+','+d+','+a+')'),20)
	},
	slide.prototype.slide=function(t,d,a){
		var o=this.v?parseInt(this.u.style.top):parseInt(this.u.style.left);
		if(o==t){
			clearInterval(this.u.si); if(a||(this.a&&this.p)){this.auto()}
		}else{
			var v=o-Math.ceil(Math.abs(t-o)*.15)*d+'px';
			this.v?this.u.style.top=v:this.u.style.left=v
		}
	};
	return{slide:slide}
}();

function showCertSample(obj) {
    if (obj.shown != undefined && obj.shown == true) {
        obj.src = "/images/cert-sample-small.jpg";
        obj.style.width = '169px';
        obj.style.height = '239px';
        document.getElementById("certintro1").className = "intro-answer-smallimage";
        document.getElementById("certintro2").className = "intro-answer-smallimage";
        obj.title = "点击放大";
        obj.shown = false;
    } else {
        obj.src = "/images/cert-sample.jpg";
        obj.style.width = '558px';
        obj.style.height = '788px';
        document.getElementById("certintro1").className = "intro-answer-largeimage";
        document.getElementById("certintro2").className = "intro-answer-largeimage";
        obj.title = "点击缩小";
	    obj.shown = true;
    }
}

