﻿var my_config = [];
with (my_config) {
 my_config.speed = "20";
 my_config.scroll = 1;
 my_config.width = "480";
 my_config.height = "40";
 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 += "<a href="+a.link+" target="+a.target+"><img src='"+a.image+"' height=40 border=0 alt='"+a.title+"'></a>&nbsp;";
 }
 if (my_config.direction == "left" || my_config.direction == "right"){
  b = "<div id=slider_scroller style='float: left; width: 1000%'>";
  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("../main/images/scroll/001.gif","http://www.busan.go.kr","부산광역시","_blank");
obj.add_banner("../main/images/scroll/002.gif","http://www.bexco.co.kr","벡스코","_blank");
obj.add_banner("../main/images/scroll/004.gif","http://www.kama.or.kr/","한국자동차공업협회","_blank");
obj.add_banner("../main/images/scroll/005.gif","http://www.kaida.co.kr/","한국수입자동차협회","_blank");
obj.add_banner("../main/images/scroll/006.gif","http://www.kaica.or.kr/","한국자동차공업협동조합","_blank");
obj.add_banner("../main/images/scroll/009.gif","http://www.busanbank.co.kr/","부산은행","_blank");
obj.add_banner("../main/images/scroll/010.gif","http://www.lotteshopping.com/","롯데백화점","_blank");
obj.add_banner("../main/images/scroll/012.gif","http://www.daum.net/","다음","_blank");
obj.add_banner("../main/images/scroll/011.gif","http://www.erencom.com/","이렌컴","_blank");
obj.add_banner("../main/images/scroll/013.gif","http://www.vitro.co.kr/","비트로","_blank");
 obj.play();
}
