﻿// JavaScript Document

function SampleSwitch(){
	if(arguments.length<1){
		alert("SampleSwith Object needs one DOM object as argument.");
		return;
	}
	
	var object=null;
	if((typeof(arguments[0])=="string")&&arguments[0].constructor==String){
		object=document.getElementById(arguments[0]);
	}else{
		object=arguments[0];
	}
	
	if(object){
		this.container=new StyleControl(object);
		this.list=new Array();
		this.text=new Array();
		var items=object.getElementsByTagName("a");
		for(var i in items){
			if(items[i].tagName && items[i].tagName.toLowerCase()=="a"){
				var temp=new StyleControl(items[i]);
				this.text.push(temp.object.innerHTML);
				this.list.push(temp);
			}
		}
		this.container.clearObject();
		this.current=0;
		this.interval=2000;
		this.status=false;
	}else{
		return;
	}
}

SampleSwitch.prototype={
	container:null,
	list:null,
	text:null,
	current:null,
	interval:null,
	status:null,
	timer:null,
	
	start:function(){
		this.status=true;
		this.timer=setInterval(this.change,this.interval)
	},
	
	change:function(){
		var object=eval(ObjectRegister.objectSampleSwitch);
		object.list[object.current].clearObject();
		var temp=document.createTextNode(object.text[object.current])
		object.list[object.current].appendObject(temp);
		object.list[object.current].object.onmouseover=function(){
			object.halt();
		}
		object.list[object.current].object.onmouseout=function(){
			object.start();
		}
		object.container.clearObject();
		object.container.appendObject(object.list[object.current].object);
		eval(ObjectRegister.objectSampleSwitch+".movenext()");
	},
	
	halt:function(){
		if(this.status){
			this.status=false;
			clearInterval(this.timer);
		}
	},
	
	movenext:function(){
		++this.current;
		if(this.current>=this.list.length){
			this.current=0;
		}
	}
}
