
var UI={
  _browser : null
};
// ±܀ڼ�·Á¦ȑ
UI.limitInputLength = function(obj, limitbyte) {
	if(obj.value.getByte() > limitbyte) {
	   alert('T·Æ�܀ہ¦ȑ: '+limitbyte+'Byte± T´ϴ׮');
	   obj.value = UI.length(obj.value, limitbyte);	
	}
}
//L¹́�L® Ġ¼­
UI.imageResize = function(obj, width) {
	if(obj == undefined) return;
	if(obj.tagName != "IMG") return;
	this.obj = obj;
	this.width = width;
	
	this.resize();
}
UI.imageResize.prototype = {
	resize : function() {
		if(this.obj.readyState != "complete") {
			var self = this;
		    window.setTimeout(function(){self.resize()}, 50);
		}
		if(this.obj.width > this.width) {
		  this.obj.width = this.width;
		}
	}
}
Object.extend=function(a, b){
  for (var property in b){a[property] = b[property];}
  return a;
};
UI.$=function(s) { return document.getElementById(s) };
UI.toogle=function(id) { UI.$(id).style.display=(UI.getStyle(UI.$(id),'display')=='none') ? 'block':'none' };
UI.toggle=function(idprefix, options) {
	try {
		this.idprefix = idprefix;
		this.options = {
		   init_value : 'none'
		};
		Object.extend(this.options, options);
		
		var obj = UI.$("btn_" + idprefix);
		var self = this;
		UI.addEvent(obj, "click", function(){self.on()});
		
		if(UI.getStyle(UI.$("div_"+this.idprefix ), 'display') != this.options.init_value) {
			this.on();
		}
	} catch(e){}
}

UI.RollingX = function(preId, speed, totalcnt, viewcnt) {
	this.frame   = UI.$(preId + "Frame");
    this.obj     = UI.$(preId + "List");
    this.obj.style.width = Math.ceil(totalcnt/viewcnt) * viewcnt * speed + "px";
    
    this.actFalg = false;
    
    this.btn_prev = UI.$("btn_" + preId + "_prev");
    this.btn_next = UI.$("btn_" + preId + "_next");
    
    var self = this;
    var initspeed = speed * viewcnt;
    if(this.btn_prev) this.btn_prev.onclick = function(){self.play("left", initspeed);}
    if(this.btn_next) this.btn_next.onclick = function(){self.play("right", initspeed);}
} 
UI.RollingX.prototype = {
    play : function(dir, speed) {
        if(!this.actFlag) {
            if(dir == "left") {
                this.prev(speed);
            } else if(dir == "right") {
                this.next(speed);
            }
        }    
    },
    
    prev : function(speed) {
        if(this.obj.offsetLeft < 0 && speed > 0) {
            this.actFlag = true;
            var len = Math.ceil(speed/3);
            var nextspeed = speed-len;
            this.obj.style.left = eval(this.obj.offsetLeft + len) + "px";
            
            var self = this;
            window.setTimeout(function(){self.prev(nextspeed)}, 50);
        } else {
            this.actFlag = false;
        }
    },
    
    next : function(speed) {
        if((this.obj.offsetLeft+this.obj.offsetWidth) > this.frame.offsetWidth && speed > 0) {
            this.actFlag = true;
            var len = Math.ceil(speed/3);
            var nextspeed = speed-len;
            this.obj.style.left = eval(this.obj.offsetLeft - len) + "px";
            
            var self = this;
            window.setTimeout(function(){self.next(nextspeed)}, 50);
        } else {
            this.actFlag = false;
        }
    }
};
