var my_config = [];

with (my_config) {
	my_config.speed = "20";
	my_config.scroll = 1;
	my_config.width = "450";
	my_config.height = "35";
	my_config.direction = "left";
	my_config.banners;
	my_config.slider;
	my_config.slider_1;
	my_config.slider_2;
	my_config.timer;
}

function autoScroll(type){
	my_config.direction = type;
	this.items = [];
	this.add_banner = function(image,link,title,target){
	var newItem  = {};
	newItem.image = image;
	newItem.link = link;
	newItem.title = title;
	newItem.target = target;
	this.items[this.items.length] = newItem;
}
 
this.play = function(){
	my_config.banners = this.items;
	scroll_html();
	with (my_config) {
		slider=document.getElementById("slider_box");
		slider_1=document.getElementById("slider_box_1");
		slider_2=document.getElementById("slider_box_2");
		slider_2.innerHTML=slider_1.innerHTML;
		timer=setInterval(do_timer,speed);
		}
	}
}
 
function scroll_html(){
	var str = "", tmp = "", b = "", c ="", d = "";
	for(var i=0;i<my_config.banners.length;i++){
		var a = my_config.banners[i]
		str += "<li><a href='"+a.link+"' target='"+a.target+"'><img src='"+a.image+"'alt='"+a.title+"'></a></li>";
	}
	if (my_config.direction == "left" || my_config.direction == "right"){
		b = "<div id=slider_scroller style='float:left; width:800%'>";
		c = " style='float: left'";
		d = "</div>";
	}
	tmp += "<div id=slider_box onmouseover='do_stop()' onmouseout='do_move()' style='overflow:hidden; width:"+my_config.width+"px; height:"+my_config.height+"px'>";
	tmp += b + "<div id=slider_box_1"+c+">" + str;
	tmp += "</div><div id=slider_box_2"+c+">"+d+"</div></div>";
	document.getElementById("slider_show").innerHTML = tmp;
}
 
function do_left() {my_config.direction='left'}
function do_right() {my_config.direction='right'}
function do_stop() {my_config.scroll=0}
function do_move() {my_config.scroll=1}
 
function do_timer(){
	with(my_config){ 
		if (scroll) {
			if (direction == "top"){
				if (slider_2.offsetTop-slider.scrollTop<=0)
					{ slider.scrollTop-=slider_1.offsetHeight 
				}else {
					slider.scrollTop++
				}
			} else if(direction == "down"){
				if (slider_1.offsetTop-slider.scrollTop>=0) slider.scrollTop+=slider_2.offsetHeight
				else {
					slider.scrollTop--
				}
			} else if (direction == "left"){
				if (slider_2.offsetWidth-slider.scrollLeft<=0) slider.scrollLeft-=slider_1.offsetWidth
				else {
					slider.scrollLeft++;
				}
			} else if (direction == "right"){
				if (slider.scrollLeft<=0) slider.scrollLeft+=slider_2.offsetWidth
				else {
					slider.scrollLeft--
				}
			}
		}
	}
}
 
function play_game (type){
	if (my_config.timer) clearInterval(my_config.timer);
	var direction = type;
	var obj = new autoScroll(type);
	obj.add_banner("/images/layout/footer_tt.gif","http://www.moel.go.kr","고용노동부","_blank");
	obj.add_banner("/images/layout/footer_tt1.gif","http://www.me.go.kr","환경부","_blank");
	obj.add_banner("/images/layout/footer_tt2.gif","http://www.mw.go.kr","보건복지부","_blank");
	obj.add_banner("/images/layout/footer_tt3.gif","http://www.kosha.or.kr","한국산업안전공단","_blank");
	obj.add_banner("/images/layout/footer_tt4.gif","http://www.kcomwel.or.kr","근로복지공단","_blank");
	obj.add_banner("/images/layout/footer_tt5.gif","http://www.keco.or.kr","한국환경공단","_blank");
	obj.play();
}
