/**********************************************************
* onload */

function addEvent(elm,listener,fn){
    try{
        elm.addEventListener(listener,fn,false);
    }catch(e){
        elm.attachEvent("on"+listener,fn);
    }
}




/**********************************************************
* setStyleSheet */

function fontS() {
	 setStyleSheet('font_s');
	 return false;
}
function fontM() {
	 setStyleSheet('font_m');
	 return false;
}
function fontL() {
	 setStyleSheet('font_l');
	 return false;
}
function setStyleSheet(title) {
	 var i, a, main;
	 for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		  if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
				a.disabled = true;
				if(a.getAttribute("title") == title) a.disabled = false;
		  }
	 }
}
function getStyleSheet() {
	 var i, a;
	 for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		  if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
	 }
	 return null;
}
function getPreferredStyleSheet() {
	 var i, a;
	 for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		  if(a.getAttribute("rel").indexOf("style") != -1 
		  && a.getAttribute("rel").indexOf("alt") == -1 
		  && a.getAttribute("title")
		  ) return a.getAttribute("title");
	 }
	 return null;
}
function createCookie(name,value,days) {
	 if (days) {
		  var date = new Date();
		  date.setTime(date.getTime()+(days*24*60*60*1000));
		  var expires = "; expires="+date.toGMTString();
	 }
	 else expires = "";
	 document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
	 var nameEQ = name + "=";
	 var ca = document.cookie.split(';');
	 for(var i=0;i < ca.length;i++) {
		  var c = ca[i];
		  while (c.charAt(0)==' ') c = c.substring(1,c.length);
		  if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	 }
	 return null;
}
function onloadCookie() {
	 var cookie = readCookie("style");
	 if (cookie == null) {
		  cookie = 'font_MT::Plugin::ZeroTemplate3::SiteSet=HASH(0x90f8620)->z3_ss_font_standard(2)';
	 } 
	 var title = cookie ? cookie : getPreferredStyleSheet();
	 setStyleSheet(title);
}
function onunloadCookie() {
	 var title = getStyleSheet();
	 createCookie("style", title, 365);
}
var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setStyleSheet(title);

addEvent(window,"unload",function(){onunloadCookie()});






/**********************************************************
* scroll box */

var moveBox = function(){this.initialize.apply(this,arguments);}

moveBox.prototype={
    obj:null,idName:null,speed:500,Interval:500,Duration:30,offsetTop:0,marginTop:0,marginBottom:0,timer:0,bkup_position:null,
    initialize:function(){
        this.obj = document.getElementById(arguments[0]);
        this.bkup_position = this.obj.style.position;
        this.obj.style.position= "absolute";
        this.offsetTop = this.obj.offsetTop;
        this.idName= arguments[0];
        if(window.addEventListener){
            window.addEventListener('scroll',this.bind(this.scrollEvent,arguments),false);
        }else if(window.attachEvent){
            window.attachEvent('onscroll',this.bind(this.scrollEvent,arguments),false);
        }
    },
    bind:function(method,arg){
        var _this=this;var _arg=(arg)?arg:[];return function(){
        method.apply(_this,_arg);
        }
    },
    scrollEvent:function(){
        var _this=this;
        var obj = _this.obj;
        var scrollTop  = document.body.scrollTop || document.documentElement.scrollTop;
        var objY;
        var y=obj.offsetTop;
        var round = Math.round;
        var speed= this.speed/1000;
        var duration=this.Duration/100;
        var h;
        //var h = scrollTop + _this.offsetTop;
        if (scrollTop  + this.marginTop>= _this.offsetTop){
        //     h = scrollTop;
             h = scrollTop + this.marginTop;
        }else{
             h = this.offsetTop;
        }
        clearInterval(_this.timer);
        _this.timer= setInterval(function(){
            y += (h - y) * speed * duration;
            if(round(y) != h){
                obj.style.top= y  + "px";
            }else{
                clearInterval(_this.timer);
                //obj.style.position = _this.bkup_position;
            }
        },1);
    }
}

function scrollBox() {
    var box1h = document.getElementById('scrollbox1').offsetHeight;
    var box2h = document.getElementById('scrollbox2').offsetHeight;
    var boxh;
    if (box1h > box2h) {
        boxh = box1h + 30;
    } else {
        boxh = box2h + 30;
    }
    document.getElementById('min5').style.paddingBottom = boxh+'px';
}
addEvent(window,"load",function(){scrollBox()});

