// 
// @name marquee.js
// @author miya2000
// @namespace http://d.hatena.ne.jp/miya2000/
// @version 1.0.0
// 

var Marquee = function ( id, opt ){
    if( ! document.getElementById(id) ) throw 'invalid id. [' + id + ']';
    var option = opt || {};
    this.id     = id;
    this.amount = option.amount || 6;
    this.delay  = option.delay  || 100;
    this.position = Number.POSITIVE_INFINITY; // means out of range.
    this._wrap();
    this.start();
}
Marquee.prototype = {
    /* wrap child nodes */
    _wrap : function() {
        var t = document.getElementById( this.id );
        with ( t.style ){
            position = 'relative'; // for ie6.
            overflow = 'hidden';
        }
        var w = document.createElement( 'div' );
        with ( w.style ){
            margin     = '0';
            padding    = '0';
            background = 'transparent';
            border     = 'none';
        }
        t.normalize();
        while( t.firstChild ){
            w.appendChild( t.removeChild( t.firstChild ) );
        }
        t.appendChild(w);
        /* get minimum width. */
        w.style.position = 'absolute';
        this.minWidth = w.offsetWidth;
        /* put back */
        w.style.position = 'relative';
        w.style.width = '100%'; // for ie6.
    },
    start : function() {
        this.stop();
        this._next();
    },
    _next : function() {
        var t = document.getElementById( this.id );
        this.curWidth = Math.min(t.offsetWidth,t.parentNode.offsetWidth); // dirty. (for "overflow:hidden" parent)
        this.position = this.position - this.amount;
        if ( this._isOutOfRange() ) {
            this.position = this._startPosition();
        }
        var w = t.firstChild;
        w.style.left = this.position + 'px';
        var self = this;
        this.tid = window.setTimeout(
            function(){ self._next(); },
            this.delay
        );
    },
    _startPosition : function() {
        return ( this.amount > 0 ) ?  this.curWidth
                                   : -this.minWidth;
    },
    _isOutOfRange : function() {
        return this.position < -this.minWidth || this.curWidth < this.position;
    },
    stop : function() {
        if ( this.tid ) window.clearTimeout( this.tid );
        this.tid = null;
    },
    isMarqueeing : function() {
        return ( this.tid ) ? true : false;
    }
}

/*--------------------------------------------------------------------------*
 *  
 *  SmoothScroll JavaScript Library V2
 *  
 *  MIT-style license. 
 *  
 *  2007-2011 Kazuma Nishihata 
 *  http://www.to-r.net
 *  
 *--------------------------------------------------------------------------*/
 
new function(){

	var attr ="data-tor-smoothScroll";//for html5 , if you can't use html5 , this value change "class"
	var attrPatt = /noSmooth/;
	var d = document;//document short cut
	
	/*
	 *add Event
	  -------------------------------------------------*/
	function addEvent(elm,listener,fn){
		try{ // IE
			elm.addEventListener(listener,fn,false);
		}catch(e){
			elm.attachEvent(
				"on"+listener
				,function(){
					fn.apply(elm,arguments)
				}
			);
		}
	}

	/*
	 *Start SmoothScroll
	  -------------------------------------------------*/
	function SmoothScroll(a){
		if(d.getElementById(a.rel.replace(/.*\#/,""))){
			var e = d.getElementById(a.rel.replace(/.*\#/,""));
		}else{
			return;
		}
		
		//Move point
		var end=e.offsetTop
		var docHeight = d.documentElement.scrollHeight;
		var winHeight = window.innerHeight || d.documentElement.clientHeight
		if(docHeight-winHeight<end){
			var end = docHeight-winHeight;
		}
		
		//Current Point
		var start=window.pageYOffset || d.documentElement.scrollTop || d.body.scrollTop || 0;
		
		
		var flag=(end<start)?"up":"down";

		function scrollMe(start,end,flag) {
			setTimeout(
				function(){
					if(flag=="up" && start >= end){
						start=start-(start-end)/20-1;
						window.scrollTo(0,start)
						scrollMe(start,end,flag);
					}else if(flag=="down" && start <= end){
						start=start+(end-start)/20+1;
						window.scrollTo(0,start)
						scrollMe(start,end,flag);
					}else{
						scrollTo(0,end);
					}
					return ;
				}
				,10
			);
			
		}

		scrollMe(start,end,flag);
		
	}

	/*
	 *Add SmoothScroll
	  -------------------------------------------------*/
	addEvent(window,"load",function(){
		var anchors = d.getElementsByTagName("a");
		for(var i = 0 ,len=anchors.length; i<len ; i++){
			if(!attrPatt.test(anchors[i].getAttribute(attr)) && 
				anchors[i].href.replace(/\#[a-zA-Z0-9_]+/,"") == location.href.replace(/\#[a-zA-Z0-9_]+/,"")){
				anchors[i].rel = anchors[i].href;
				anchors[i].href = "javascript:void(0)";
				anchors[i].onclick=function(){SmoothScroll(this)}
			}
		}
	});

}
/*image roll over*/
function initRollovers() {
	if (!document.getElementById) return
	
	var aPreLoad = new Array();
	var sTempSrc;
	var aImages = document.getElementsByTagName('img');

	for (var i = 0; i < aImages.length; i++) {		
		if (aImages[i].className == 'imgover') {
			var src = aImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var hsrc = src.replace(ftype, '_ovr'+ftype);

			aImages[i].setAttribute('hsrc', hsrc);
			
			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;
			
			aImages[i].onmouseover = function() {
				sTempSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));
			}	
			
			aImages[i].onmouseout = function() {
				if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_w'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		}
	}
}

var params = {wmode: "transparent"};

// initialize
window.onload = function(){
  swfobject.embedSWF("design/main.swf", "mainflash", "900", "198", "9.0.0","","","");
  initRollovers();
}

