﻿var PageUnitss = {};

/**
 * 选项卡(多栏切换)
 */
PageUnitss.changeTab = Class.create({
	initialize: function(options){
		this.options = {
			id       : null,
			init     : 0,
			active   : "click",
			callback : function(){}
		}
		
		Object.extend(this.options, options || {});
		this.children = new Object;
		
		this.main = $(this.options.id);
		if(!this.main){
			alert("\"" + this.options.id + "\" has not found.");
			return;
		}
		this.children.main = this.main.childElements();
		
		this.bst = $(this.options.id + "-bst");
		
		if(this.bst)
			this.children.bst = this.bst.childElements();
		
		this.nowfocus = null;
		this._create();
	},
	
	_create: function(){	
		if(this.children.main.length < 0) return;
		
		var i=0;
		this.children.main.each(function(s){
		//for(var i=0; i<this.children.length; i++){
			s.displayOrder = i;
			Event.observe(s, this.options.active, function(){
				this.onfocu(s);
				this.handle(s.displayOrder);
				if(this.options.callback) this.options.callback(s.displayOrder);
			}.bind(this));
			
			i++;
		//}
		}.bind(this));
		
		this.init();
	},
	
	init: function(){
		if(this.options.init > this.children.main.length) this.options.init = this.children.main.length - 1;
		this.children.main[this.options.init].addClassName("focus");
		this.children.bst.each(Element.hide);
		this.children.bst[this.options.init].show();
	},
	
	onfocu: function(obj){
		this.children.main.each(function(s){s.removeClassName("focus")});
		obj.addClassName("focus");
	},
	
	handle: function(num){
		if(this.bst){
			this.children.bst.each(Element.hide);
			this.children.bst[num].show();
		}
	}
});

PageUnitss.scroller = Class.create({
	initialize: function(options){
		this.options = {
			id       : null,
			to       : "top",
			fps      : 12,
			step     : 2
		}
		
		this.state = false;
		
		Object.extend(this.options, options || {});
		
		this.timeout = Math.ceil(1000 / this.options.fps);
		
		this._create();
	},
	
	initScan: function(){
		
		this.main.style.position = "relative";
		this.scroller.style.position = "absolute";
		
		if(this.options.to == "top"){
			
			this.scroller.style.width = this.limit.x + "px";
			this.scroller.style.height = this.limit.y * 2 + "px";
			this.scroller.style.left = 0 + "px";
			this.scroller.style.top = 0 + "px";
			
		} else if(this.options.to == "right"){
			
			this.sc.each(function(s){s.addClassName("fl");});
			this.scroller.style.width = this.limit.x * 2 + "px";
			this.scroller.style.height = this.limit.y + "px";
			this.scroller.style.top = 0 + "px";
			this.scroller.style.left = 0 - this.limit.x + "px";
			
		} else if(this.options.to == "bottom"){
			
			this.scroller.style.width = this.limit.x + "px";
			this.scroller.style.height = this.limit.y * 2 + "px";
			this.scroller.style.left = 0 + "px";
			this.scroller.style.top = 0 - this.limit.y + "px";
			
		} else if(this.options.to == "left"){
			
			this.sc.each(function(s){s.addClassName("fl");});
			this.scroller.style.width = this.limit.x * 2 + "px";
			this.scroller.style.height = this.limit.y + "px";
			this.scroller.style.top = 0 + "px";
			this.scroller.style.left = 0 + "px";
			
		} else {
			return;
		}
	},
	
	_create: function(){
		
		this.main = $(this.options.id);
		
		if(!this.main) return;
		
		this.scroller = this.main.down(0);
		this.scroller.innerHTML += this.scroller.innerHTML;
		
		this.sc = Element.childElements(this.scroller);
		
		var sc_Dim = this.sc[0].getDimensions();
		this.limit = {x:sc_Dim.width, y:sc_Dim.height};
		sc_Dim = null;

		this.initScan();
		
		this.start();
		
		Event.observe(this.scroller, "mouseover", function(){
			this.stop();
		}.bind(this));
		Event.observe(this.scroller, "mouseout", function(){
			this.start();
		}.bind(this));
		
	},
	
	mymar: function(){
		if(this.options.to == "top"){
			
			var tp_now = parseInt(this.scroller.offsetTop);
			
			if(Math.abs(tp_now) >= this.limit.y){
				this.scroller.style.top = 0 + "px";
				tp_now = 0;
			}
			tp_now -= this.options.step;
			this.scroller.style.top = tp_now + "px";
			
		} else if(this.options.to == "right"){
			
			var tp_now = parseInt(this.scroller.offsetLeft);
			
			if(tp_now >= 0){
				this.scroller.style.left = 0 - this.limit.x + "px";
				tp_now = 0 - this.limit.x;
			}
			tp_now += this.options.step;
			this.scroller.style.left = tp_now + "px";
			
		} else if(this.options.to == "bottom"){
			
			var tp_now = this.scroller.offsetTop;
			
			if(tp_now >= 0){
				this.scroller.style.top = 0 - this.limit.y + "px";
				tp_now = 0 - this.limit.y;
			}
			tp_now += this.options.step;
			this.scroller.style.top = tp_now + "px";
			
		} else if(this.options.to == "left"){
			
			var tp_now = this.scroller.offsetLeft;
			
			if(Math.abs(tp_now) >= this.limit.x){
				this.scroller.style.left = 0 + "px";
				tp_now = 0;
			}
			tp_now -= this.options.step;
			this.scroller.style.left = tp_now + "px";
			
		} else {
			return;
		}
	},
	
	start: function(){
		if(!this.state){
			this.state = true;
			this.lsn = window.setInterval(function(){
				this.mymar();
			}.bind(this), this.timeout);
		} else {
			return;
		}
		return;
	},
	
	stop: function(){
		this.state = false;
		window.clearInterval(this.lsn);
	}
});


function huanImage(url)
{
	document.getElementById("huanimg").src = url;
	
}






/*  折叠菜单  */

function myshow(str)
{
        if(document.getElementById(str).style.display!="block")
	  	{
		  document.getElementById(str).style.display="block";
		}
	  	else
	   	{
			document.getElementById(str).style.display="none";
		}  
}

/*  导航 */

   function displaySubMenu(ver){
	   
	  for(var i=0;i<20;i++)
	  {
	   		var k = document.getElementById("mun"+i);
			if(k) k.style.display = "none";
	  }
	  
	 var subMenu = document.getElementById(ver);
	 if(subMenu)
	 	subMenu.style.display = "block";
  }



<!--     鼠标滑过效果    -->

function newblack (did){
	did.style.backgroundColor = "#57DAFC";
	}



function oldblack (did){
	did.style.backgroundColor = "";
	}




