//
//----------- <<Gloval Value>> ----------
//
var number = 1 ;
var iPhoneHomeBanner = 0 ;
var iPhoneHomeBannerId ;
var iPhoneHomeBannerArry ;
//
var Qlist = [
        "img/bnr_shop/blog_yamakawa.gif",
        "img/bnr_shop/blog_tigerkids.gif"
    ] ;        
//
//
function IncludeJSFile(astrFile)
{
　　var script = document.createElement('script') ;
//
　　script.src = astrFile ;
　　script.type = 'text/javascript' ;
　　script.defer = true ;
　　document.getElementsByTagName('head').item(0).appendChild(script);
}
//
//
function IncludeRanDomBannerArry(AttchFile) {
//
    window.document.write('<script type=\"text/javascript\" src=\"js/' + AttchFile + '"></script>') ;
}
//
//
function PutRanDomBanner() {
//
//
	var list = InitBannerArrayList() ;
//
    gr0 = Math.random() ;
    gr1 = Math.floor(gr0 * list.length) ; 
//
    do {
        gr0 = Math.random() ;
        gr2 = Math.floor(gr0 * list.length) ;
    }while (gr1 == gr2) ;
//
    do {
        do {
            gr0 = Math.random() ;
            gr3 = Math.floor(gr0 * list.length) ;
        }while (gr1 == gr3) ;
    }while (gr2 == gr3) ;
//
    window.document.write('<a href="' + list[gr1][0] + '" target= "_blank" >')
    window.document.write('<img src= "' + list[gr1][1] + '" alt="' + list[gr1][2] + '" width="200" height="60" /></a>')        
    window.document.write('<a href="' + list[gr2][0] + '" target= "_blank" >')
    window.document.write('<img src= "' + list[gr2][1] + '" alt="' + list[gr2][2] + '" width="200" height="60" /></a>')        
    window.document.write('<a href="' + list[gr3][0] + '" target= "_blank" >')
    window.document.write('<img src= "' + list[gr3][1] + '" alt="' + list[gr3][2] + '" width="200" height="60" /></a>')        
//
}
//
//----------- Slide Banner Procedur's -----------
//
function InitSliderBanner(sw_) {
//
    var list = InitSliderBannerArrayList() ;
    number = (sw_) ? -1 : Math.floor(Math.random() * list.length) ;
    PutSlideBannerFWD(list) ;
//
}
//
//
function PutSlideBannerFwdStep() {
//
    var list = InitSliderBannerArrayList() ;
/*
    DecSlideBanner(list) ;
    DecSlideBanner(list) ;
    DecSlideBanner(list) ;
    PutSlideBannerFWD(list) ;
*/
//
    ShftL_LinkURL('SCh1','SCh2') ;
    ShftL_LinkImgURL('SCi1','SCi2') ;
    ShftL_Message('SCt1','SCt2') ;
    ShftL_LinkURL('SCh2','SCh3') ;
    ShftL_LinkImgURL('SCi2','SCi3') ;
    ShftL_Message('SCt2','SCt3') ;
    ShftL_LinkURL('SCh3','SCh4') ;
    ShftL_LinkImgURL('SCi3','SCi4') ;
    ShftL_Message('SCt3','SCt4') ;
//
    IncSlideBanner(list) ;
    ChgLinkURL('SCh4',list[number][0]) ;
    ChgLinkImgURL('SCi4',list[number][1]) ;
    ChgMessage('SCt4',list[number][3]) ;
//
}
//
//
function PutSlideBanner(SlideSW) {
//
    var list = InitSliderBannerArrayList() ;
//
    if (SlideSW) {PutSlideBannerFWD(list) ;}else{PutSlideBannerRWD(list) ;}
}
//
//
function PutSlideBannerFWD(list) {

//
    ChgLinkURL('SCh1',list[number][0]) ;
    ChgLinkImgURL('SCi1',list[number][1]) ;
    ChgMessage('SCt1',list[number][3]) ;
    IncSlideBanner(list) ;
    
    ChgLinkURL('SCh2',list[number][0]) ;
    ChgLinkImgURL('SCi2',list[number][1]) ;
    ChgMessage('SCt2',list[number][3]) ;
    IncSlideBanner(list) ;

    ChgLinkURL('SCh3',list[number][0]) ;
    ChgLinkImgURL('SCi3',list[number][1]) ;
    ChgMessage('SCt3',list[number][3]) ;
    IncSlideBanner(list) ;
    
    ChgLinkURL('SCh4',list[number][0]) ;
    ChgLinkImgURL('SCi4',list[number][1]) ;
    ChgMessage('SCt4',list[number][3]) ;
    IncSlideBanner(list) ;

}
//
function PutSlideBannerRWD(list) {
//
    var Gr0 ;
//
    DecSlideBanner(list) ;
    DecSlideBanner(list) ;
    DecSlideBanner(list) ;
    DecSlideBanner(list) ;
    Gr0 = number ;
    ChgLinkURL('SCh4',list[number][0]) ;
    ChgLinkImgURL('SCi4',list[number][1]) ;
    ChgMessage('SCt4',list[number][3]) ;
    DecSlideBanner(list) ;
    ChgLinkURL('SCh3',list[number][0]) ;
    ChgLinkImgURL('SCi3',list[number][1]) ;
    ChgMessage('SCt3',list[number][3]) ;
    DecSlideBanner(list) ;
    ChgLinkURL('SCh2',list[number][0]) ;
    ChgLinkImgURL('SCi2',list[number][1]) ;
    ChgMessage('SCt2',list[number][3]) ;
    DecSlideBanner(list) ;
    ChgLinkURL('SCh1',list[number][0]) ;
    ChgLinkImgURL('SCi1',list[number][1]) ;
    ChgMessage('SCt1',list[number][3]) ;
    number = Gr0 ;
}
//
//
//
//----------- Rotary Banner Procedur's -----------
//
function InitiTuneSC_(sw_,matrix_) {
//
    var Gr0 = 0 ;
    var Gr1 = 0 ;
    var list = InitSliderBannerArrayList() ;
//
    if (!sw_) {Gr0 = Math.floor(Math.random() * list.length) ;}
//
    do {
        ++Gr1 ;
        ChgLinkURL('SCh' + String(Gr1),list[Gr0][0]) ;
        ChgLinkImgURL('SCi' + String(Gr1),list[Gr0][1]) ;
        ++Gr0 ;
        if (Gr0 == list.length) Gr0 = 0 ; 
    } while (Gr1 < matrix_) ;
//
}
//
function Rotate_iTuneSC_() {
//
    var Gr0 = 0 ;
    var Gr1 = 0 ;
    var Gr2 = "" ;
    var Gr3 = 0 ;
    var list = InitSliderBannerArrayList() ;
//
    Gr0 = Math.floor(Math.random() * list.length) + 1 ;
    do {
        Gr1 = Math.floor(Math.random() * list.length) ;
    } while (Gr0 == Gr1) ;
    Gr2 = 'SCi' + String(Gr0) ;
    SetRoteteQuelist(Qlist,document.images[Gr2].src ,list[Gr1][1]) ;
    Gr3 = Math.floor(Math.random() * 2) ;
    RotetoLinkImgURL(1,Gr3,Gr2,Qlist) ;
    ChgLinkURL('SCh' + String(Gr0),list[Gr1][0]) ;
//
}
//
//
function PutCombiBanner(SlideSW) {
//
    var list = InitSliderBannerArrayList() ;
//
    if (SlideSW) {PutCombiBannerFWD(list) ;}else{PutCombiBannerRWD(list) ;}
}
//
//
function InitCombiBanner(sw_) {
//
    var list = InitSliderBannerArrayList() ;
    number = (sw_) ? -1 : Math.floor(Math.random() * list.length) ;
    PutCombiBannerFWD(list) ;
//
}
function PutCombiBannerFwdStep() {
//
    var Gr0 ;
    var list = InitSliderBannerArrayList() ;
//
    DecSlideBanner(list) ;
    Gr0 = number ;
    IncSlideBanner(list) ;
    IncSlideBanner(list) ;
//
    ShftL_LinkImgURL('SCi1','SCi2') ;
    ShftL_LinkImgURL('SCi2','SCi3') ;
    ShftL_LinkImgURL('SCi3','SCi4') ;
    ChgLinkURL('SCh3',list[Gr0][0]) ;
    ShftL_LinkImgURL('SCi4','SCi5') ;
    ChgLinkImgURL('SCi5',list[number][1]) ;
//
}
//
//
function PutCombiBannerFWD(list) {
//    
    IncSlideBanner(list) ;
    ChgLinkImgURL('SCi1',list[number][1]) ;
    IncSlideBanner(list) ;
    ChgLinkImgURL('SCi2',list[number][1]) ;
    IncSlideBanner(list) ;
    ChgLinkURL('SCh3',list[number][0]) ;
    ChgLinkImgURL('SCi3',list[number][1]) ;
    IncSlideBanner(list) ;
    ChgLinkImgURL('SCi4',list[number][1]) ;
    IncSlideBanner(list) ;
    ChgLinkImgURL('SCi5',list[number][1]) ;
}
//
function PutCombiBannerRWD(list) {
//
    var Gr0 ;
//
    DecSlideBanner(list) ;
    DecSlideBanner(list) ;
    DecSlideBanner(list) ;
    DecSlideBanner(list) ;
    DecSlideBanner(list) ;
    Gr0 = number ;
    ChgLinkImgURL('SCi5',list[number][1]) ;
    DecSlideBanner(list) ;
    ChgLinkImgURL('SCi4',list[number][1]) ;
    DecSlideBanner(list) ;
    ChgLinkURL('SCh3',list[number][0]) ;
    ChgLinkImgURL('SCi3',list[number][1]) ;
    DecSlideBanner(list) ;
    ChgLinkImgURL('SCi2',list[number][1]) ;
    DecSlideBanner(list) ;
    ChgLinkImgURL('SCi1',list[number][1]) ;
    number = Gr0 ;
}
//
//
function RotateFwd() {
//
//
    var Gr0 ;
    var list = InitSliderBannerArrayList() ;
//
//  --- Test ---
	var CombiList = new Array() ;
        DecSlideBanner(list) ;
        DecSlideBanner(list) ;
        Gr0 = number ;
        IncSlideBanner(list) ;
        IncSlideBanner(list) ;
        CombiList[0] = list[0][1] ;
        CombiList[1] = list[1][1] ;
        CombiList[2] = list[2][1] ;
        CombiList[3] = list[3][1] ;
        CombiList[4] = list[Gr0][1] ;
//
//
        RotetoLinkImgURL(3,true,'SCi3_',CombiList) ;
//
}
//
function RotateFwdwithID(RotateID) {
//
//
    var list = InitRotetoBannerArrayList_HandMade() ;
//
	var CombiList = new Array() ;
        CombiList[0] = list[0][1] ;
        CombiList[1] = list[1][1] ;
        CombiList[2] = list[2][1] ;
        CombiList[3] = list[3][1] ;
        CombiList[4] = list[4][1] ;
        CombiList[5] = list[5][1] ;
        CombiList[6] = list[6][1] ;
        CombiList[7] = list[7][1] ;
//
        RotetoLinkImgURL(-1,true,RotateID,CombiList) ;
//
}
//
function RotateiPhoneCadishID(RotateID) {
//
    var list = InitRotetoBannerArrayList_iPhoneCadish() ;
//
	var CombiList = new Array() ;
        CombiList[0] = list[0][1] ;
        CombiList[1] = list[1][1] ;
        CombiList[2] = list[2][1] ;
        CombiList[3] = list[3][1] ;
        CombiList[4] = list[4][1] ;
//
        RotetoLinkImgURL(-1,true,RotateID,CombiList) ;
//
}
//
function InitiPhoneHomeBanner(iPhoneBanneerID) {
//
//
    iPhoneHomeBannerArry = InitRotetoBannerArrayList_iPhoneCadish() ;
    iPhoneHomeBanner = 0 ;
    iPhoneHomeBannerId = iPhoneBanneerID ;
//
}
//
//
function ChgiPhoneHomeBanner() {
//
//
    ChgLinkImgURL(iPhoneHomeBannerId,iPhoneHomeBannerArry[iPhoneHomeBanner][1]) ;
    iPhoneHomeBanner++ ;
    iPhoneHomeBanner = iPhoneHomeBanner % iPhoneHomeBannerArry.length ;
//
}
//
//
//----------- Common Function'S -----------
//
function RotetoLinkImgURL(loop_,ClockWise,ImageId,QueList) {
    var Gr0 ;
//
        Gr0 = -1 ;
        if (loop_ == 0) Gr0 = 1 ;
        if (loop_ >= 1) Gr0 = loop_ ;
    var cube = new Animation.Cube(Gr0,ImageId,QueList) ;
        cube.rotate() ;
//
        cube.clockWise = ClockWise ;
//
        cube.rotateSeconds = 1.0 ;
        cube.waitSeconds   = 1.5 ;
//
}
//
//
function SetRoteteQuelist(qlist,url1,url2) {
//
    qlist[0] = url1 ;
    qlist[1] = url2 ;
//
}
//
//
//----------- Common Function's -----------
//    
function ChgLinkImgURL(ImageID,url_) {
//
    document.images[ImageID].src = url_ ;
//
}
function ChgLinkURL(AnchorID,url_) {
//
    var anchor = document.getElementById(AnchorID) ;
        anchor.href = url_ ;
//
}
function ChgMessage(MsgID,msg_) {
//
    var msg = document.getElementById(MsgID);
        msg.innerHTML = msg_ ;
//
}
function ShftL_LinkImgURL(ImageID1,ImageID2) {
//
        document.images[ImageID1].src = document.images[ImageID2].src ;
//
}
function ShftL_LinkURL(AnchorID1,AnchorID2) {
//
    var anchor1 = document.getElementById(AnchorID1) ;
    var anchor2 = document.getElementById(AnchorID2) ;
        anchor1.href = anchor2.href ;
//
}
function ShftL_Message(AnchorID1,AnchorID2) {
//
    var msg1 = document.getElementById(AnchorID1);
    var msg2 = document.getElementById(AnchorID2);
        msg1.innerHTML = msg2.innerHTML ;
//
}
//
//
function IncSlideBanner(list) {
//
    ++number ;
    if (number >= list.length) number = 1 ;
}
function DecSlideBanner(list) {
//
var Gr0 = number ;
    --number ;
    if (number <= 0) number = list.length - 1 ;
}
//
function SetIntervalTimer(PrcName,Tim_) {
    timerID = setInterval(PrcName,Tim_) ;
}
//
// Animation.Cube
// 
if ( typeof(Animation) == "undefined" ) Animation = function () {};
 
Animation.Cube = function (loop_, ifrom, idest ) {
    this.imageLoaded = false;           // next image is loaded or not
    this.startOnLoad = false;           // start commanded received
    this.is_running = false;            // all done flag
    var init = this.initialize(loop_,ifrom,idest);
    if (!init) return;
    return this;
};
 
Animation.Cube.VERSION = "0.04";
Animation.Cube.prototype.onComplete    = null ;      // callback function
Animation.Cube.prototype.onInterval    = null ;      // callback function
Animation.Cube.prototype.background    = null ;
Animation.Cube.prototype.waitSeconds   = 0.000 ;
Animation.Cube.prototype.rotateSeconds = 0.500 ;
Animation.Cube.prototype.viewDistance  = 2.000 ;     // or 1.414, 1.732
Animation.Cube.prototype.minResolution =  2 ;
Animation.Cube.prototype.maxResolution = 32 ;
Animation.Cube.prototype.cursor        =  0 ;
Animation.Cube.prototype.repeat        = true ;
Animation.Cube.prototype.clockWise     = true ;
Animation.Cube.prototype.loopCount     = -1 ;     // -1:ForeEver,0-n:Loop Count
Animation.Cube.prototype.imageLength   = 0 ;
//
Animation.Cube.prototype.initialize = function (loop_, ifrom, idest ) {
    var imglist ;
    this.canvas = document.createElement( "div" );
    this.canvas.style.position = "relative";

// canvas base
    this.imgBase = new Animation.Cube.Image( this.canvas );
    var ebase = this.imgBase.fromElement( ifrom );
    if ( ! ebase ) return;
    
    var Gr0 = ebase.offsetWidth ;
    var Gr1 = ebase.offsetHeight ;

    this.canvasWidth  = ebase.offsetWidth ;
    this.canvasHeight = ebase.offsetHeight ;
//?????ずれる・・・・
    ebase.parentNode.insertBefore( this.canvas, ebase ) ;
//
    if ( typeof(idest) == "string" ) {
        imglist = [ ebase.src, idest ] ;
        this.repeat = false ;
    } else {
        imglist = idest ;
        this.repeat = true ;
    }
// Make Image
    this.imgBuffer = [];
    var __this = this;
    var __len  = imglist.length;
    var trigcheck = function (elem) {
        for( var i=0; i<__len; i++ ) {
            if ( ! __this.imgBuffer[i].loaded ) return;
        }
        __this.imageLoaded = true;
        if ( __this.startOnLoad ) {
            __this.startOnLoad = false;
            __this.beginAnimation();
        } 
    };
// Image Set 
    for( var i=0; i<imglist.length; i++ ) {
        this.imgBuffer[i] = new Animation.Cube.Image( this.canvas );
        this.imgBuffer[i].onLoad = trigcheck;
        this.imgBuffer[i].fromURL(imglist[i]);
    }
// Loop Set
    this.loopCount = loop_ ;
    this.imageLength = imglist.length - 1 ;
    return true;
};
 
Animation.Cube.appendEvent = function( elem, type, func ) {
    if ( elem.addEventListener ) {
        return elem.addEventListener( type, func, false );
    } else if ( elem.attachEvent ) {
        return elem.attachEvent( "on"+type, func );
    }
};
 
Animation.Cube.prototype.rotate = function() {
    if ( this.is_running ) return;      // already started
    if ( this.imageLoaded ) {
        this.beginAnimation() ;
    } else {
        this.startOnLoad = true  ;      // wait until image loaded
    }
};
 
Animation.Cube.prototype.beginAnimation = function() {
//
    var Gr0 ;
//
    if (this.background) 
        this.canvas.style.background = this.background ;
    Gr0 = this.nextCursor(this.cursor) ;
//
    this.imgBase.elem.style.visibility = "hidden"; 
    this.rotation = this.clockWise ? 0.0 : 1.0;
    if ( this.clockWise ) {
        this.imgLeft  = this.imgBuffer[this.cursor];
        this.imgRight = this.imgBuffer[Gr0];
    } else {
        this.imgLeft  = this.imgBuffer[Gr0];
        this.imgRight = this.imgBuffer[this.cursor];
    }
//
    this.startWise = this.clockWise ;
    this.is_running = true;
    this.timer = new Animation.Cube.Timer(this);    // timer object
    this.timer.start() ;
} ;
 
Animation.Cube.prototype.nextCursor = function(cur) {
//
    exp_ = true
    if (this.clockWise) {
        cur++ ;
        cur = cur % this.imgBuffer.length ;
    } else {
        cur --;
        cur += this.imgBuffer.length ;
    }
    return cur ;
} ;
// 
Animation.Cube.prototype.dispEdge = function() {
    if ( this.timer ) {
        if ( this.timer.is_running() ) this.timer.stop();
        this.timer = null;
    }
    if ( ! this.is_running ) return;
 
    this.imgLeft.hideClip( 0 );
    this.imgRight.hideClip( 0 );
 
    if ( this.startWise == this.clockWise ) {
        this.cursor = this.nextCursor(this.cursor);
    }
    this.startWise = null;
    this.imgBase.elem.src = this.imgBuffer[this.cursor].elem.src ;
    this.imgBase.elem.style.width  = this.canvasWidth +"px";
    this.imgBase.elem.style.height = this.canvasHeight+"px";
    this.imgBase.elem.style.visibility = "visible";
//
//
    if (this.loopCount > 0) {
        this.imageLength-- ;
        if (this.imageLength == 0) {
                this.imageLength = this.imgBuffer.length ;
                this.loopCount-- ;
                if (this.loopCount == 0 ) this.is_running = false ;
        }
    }
//
//
};
 
Animation.Cube.prototype.nextAnimation = function() {
    this.dispEdge();
    var __this = this;
    var func = function () {
        if ( ! __this.is_running ) return;
        __this.beginAnimation();
    }
    if ( this.onInterval ) this.onInterval(this.cursor);
    if ( ! this.is_running ) return;
    setTimeout( func, this.waitSeconds * 1000 ) ;
} ;
 
Animation.Cube.prototype.finish = function() {
    this.dispEdge() ;
    this.is_running = false ;
    if ( this.onComplete ) this.onComplete(this.cursor) ;
};
 
Animation.Cube.prototype.loop = function(secs,diff,count) {
    if ( ! this.is_running ) return;
    if ( ! this.clockWise ) diff = - diff;
    this.rotation += diff * 0.001 / this.rotateSeconds;
 
    var fincheck = false;
    if ( this.rotation > 1.0 ) {
        this.rotation = 1.0;
        fincheck = true;
    } else if ( this.rotation < 0.0 ) {
        this.rotation = 0.0;
        fincheck = true;
    }
 
    this.display( this.rotation );
 
    if ( fincheck ) {
        if ( this.repeat ) {
            this.nextAnimation();
        } else {
            this.finish() ;
        }
        return false;
    } else {
        return true;
    }
};
 
Animation.Cube.prototype.display = function( prog ) {
    var alpha = (1.0-2.0*prog)/4.0*Math.PI;
    var sina = Math.sin( alpha );
    var cosa = Math.cos( alpha );
    var ah = this.viewDistance / ( this.viewDistance +(cosa+sina));
    var bh = 1;
    var ch = this.viewDistance / ( this.viewDistance +(cosa-sina));
    var aw = cosa * ah;
    var bw = sina;
    var cw = -cosa * ch;
 
    var ow = 0;
    if ( aw >  Math.SQRT1_2 ) ow = aw-Math.SQRT1_2;
    if ( cw < -Math.SQRT1_2 ) ow = cw+Math.SQRT1_2;
    if ( ow ) {
        aw -= ow;
        bw -= ow;
        cw -= ow;
    }
 
    if ( aw > bw ) {
        this.dispPanel( this.imgRight, bw, bh, aw, ah);
    } else {
        this.imgRight.hideClip( 0 );
    }
    if ( cw < bw ) {
        this.dispPanel( this.imgLeft, cw, ch, bw, bh );
    } else {
        this.imgLeft.hideClip( 0 );
    }
};
 
Animation.Cube.prototype.dispPanel = function( img, x1, h1, x2, h2 ) {
    if ( x1 > x2 ) {
        var x0 = x1;
        x1 = x2;
        x2 = x0;
        var h0 = h1;
        h1 = h2;
        h2 = h0;
    }
 
    var lx = Math.round( Math.SQRT1_2 * this.canvasWidth * (x1+Math.SQRT1_2) );
    var lh = Math.round( this.canvasHeight * h1 );
    var ly = Math.round((this.canvasHeight-lh)/2);
    var rx = Math.round( Math.SQRT1_2 * this.canvasWidth * (x2+Math.SQRT1_2) );
    var rh = Math.round( this.canvasHeight * h2 );
    var ry = Math.round((this.canvasHeight-rh)/2);
 
    var reso = this.canvasWidth;
    if ( ry != ly ) {
        reso = Math.round(Math.abs(2.0*(rx-lx)/(ry-ly)));
        if ( reso > this.maxResolution ) reso = this.maxResolution;
        if ( reso < this.minResolution ) reso = this.minResolution;
    }
 
    var ww = rx-lx;
    var clipnum = 0;
    for( var ix=lx; ix<rx; ix+=reso ) {
        var prog = (ix-lx)/(rx-lx);
        var iy = Math.round( ly + (ry-ly)*prog );
        var ih = Math.round( lh + (rh-lh)*prog );
        var iw = reso;
        if ( ix+iw > this.canvasWidth ) iw = this.canvasWidth - ix;
        img.dispClip( clipnum, ix,iy,iw,ih,prog,ww );
        clipnum ++;
    }
    img.hideClip( clipnum );
};
 
//  Animation.Cube.Image class
 
Animation.Cube.Image = function( work ) {
    this.plane = null;
    this.work = work;           // work div element
    this.elem = null;           // image element
    this.onLoad = null;         // callback function
    this.clipbuf = [];
    this.loaded = false;
    this.lasthided = null;
    return this;
};
 
Animation.Cube.Image.prototype.getClip = function( num ) {
    if ( this.clipbuf[num] ) return this.clipbuf[num];
    var line = this.elem.cloneNode(true);
    line.style.position   = "absolute";
    line.style.display    = "";
    line.style.visibility = "hidden";
    this.clipbuf[num] = line;
    return line;
};
 
Animation.Cube.Image.prototype.hideClip = function( num ) {
    var lastclip = this.clipbuf.length;
    if ( this.lasthided != null ) lastclip = this.lasthided;
    for( var i=num; i<lastclip; i++ ) {
        this.clipbuf[i].style.visibility = "hidden";
    }
    this.lasthided = num;
};
 
Animation.Cube.Image.prototype.dispClip = function( num,left,top,width,height,prog,xcomp) {
    var line = this.getClip( num );
    var offset = Math.round(xcomp*prog);
    var lstyle = line.style;
    lstyle.left   = (left-offset)+"px";
    lstyle.width  = xcomp+"px";
    lstyle.top    = top+"px";
    lstyle.height = height+"px";
    lstyle.visibility = "visible";
    lstyle.clip = "rect(0px,"+(offset+width)+"px,"+(height)+"px,"+offset+"px)";
    this.work.appendChild( line );
};
 
Animation.Cube.Image.prototype.fromElement = function( elem ) {
    if ( typeof elem == "string" ) {
        elem = document.getElementById(elem);
    }
    if ( ! elem ) return;
    this.elem = elem;
    this.loaded = true;
    return elem;
};
 
Animation.Cube.Image.prototype.fromURL = function( url ) {
    var elem = document.createElement( "img" );    // new image
    elem.src = url;
    elem.style.visibility = "hidden";
    elem.style.position = "absolute";
    this.work.appendChild( elem );
    this.checkLoaded( elem );
    this.elem = elem;
    return elem;
};
 
Animation.Cube.Image.prototype.checkLoaded = function( orig ) {
    var check = orig.cloneNode(true);                   // image to check
    var __this = this;
    var ldfunc = function(e){
        if ( ! e && window.event ) e = window.event;    // IE event
        __this.loaded = true;
        check.parentNode.removeChild( check );
        if ( __this.onLoad ) __this.onLoad();
    };
    Animation.Cube.appendEvent( check, "load", ldfunc );        // onload image
    this.work.appendChild( check );
};
 
//  Animation.Cube.Timer class
 
Animation.Cube.Timer = function (target) {
    this.target = target;
    this.started = false;
    this.stoped = false;
    this.count = 0;
    var __this = this;
    this.next = function(){
        if ( __this.stoped ) return;
        var now_time = (new Date()).getTime();
        if ( ! __this.begin_time ) __this.begin_time = now_time;
        if ( ! __this.prev_time ) __this.prev_time = now_time;
        var spent_time = now_time-__this.begin_time;
        var diff_time = now_time - __this.prev_time;
        __this.prev_time = now_time;
        var flag = __this.target.loop(spent_time,diff_time,__this.count++);
        if ( flag ) {
            setTimeout( __this.next, 1 );
        } else {
            __this.stop();
        }
    };
    return this;
};
 
Animation.Cube.Timer.prototype.start = function () {
    this.started = true;
    this.stoped = false;
    this.next();
};
 
Animation.Cube.Timer.prototype.now = function () {
    return (new Date()).getTime();
};
Animation.Cube.Timer.prototype.stop = function () {
    this.stoped = true;
};
 
Animation.Cube.Timer.prototype.is_running = function () {
    return ( this.started && ! this.stoped );
};
 
/*
// ========================================================================
 
=head1 NAME
 
Animation.Cube -- Rotating Cube Animation
 
=head1 SYNOPSIS
 
    var ras = new Animation.Cube( id_or_elem, image_url );
    ras.rotate();
 
=head1 DESCRIPTION
 
This library provides a rotating cube animation.
 
=head1 METHODS
 
=head2 ras = new Animation.Cube( id_or_elem, image_url );
 
This constructor method returns a new Animation.Cube object.
 
=head2 ras.rotate();
 
This method starts a animation effect.
 
=head2 ras.finish();
 
This method forces to stop a animation effect if it's running.
 
=head1 AUTHOR
 
Yusuke Kawasaki http://www.kawa.net/
 
=head1 COPYRIGHT AND LICENSE
 
Copyright (c) 2005-2006 Yusuke Kawasaki. All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the Artistic license. Or whatever license I choose,
which I will do instead of keeping this documentation like it is.
======================================================================
*/

