//
//
function InitBannerArrayList() {
//
	var List = new Array() ;
//
//草円
    List[List.length] = new Array('http://www.soene.com/','img/bnr_advert/bnr_souen.gif','草円') ;
//飛騨高山ティディベア　エコビレッジ
    List[List.length] = new Array('http://www.teddyeco.jp/','img/bnr_advert/bnr_teddybear.gif','飛騨高山ティディベア　エコビレッジ') ;

//高山エース旅行センター
    List[List.length] = new Array('http://www.takayama-ace.jp/','img/bnr_advert/bnr_jtb1.jpg','高山エース旅行センター') ;

//花水木（高山バーガー）
    List[List.length] = new Array('http://takayamahanamizuki.hida-ch.com/','img/bnr_advert/bnr_hanamizuki.png','高山バーガー') ;

//---------- End of List ----------
	return List ;
//
}

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>')        
//
}
//
//
//----------- Rotary Banner Procedur's(Add:2010/10/06) -----------
//
function IncludeRanDomBannerArry(AttchFile) {
//
    window.document.write('<script type=\"text/javascript\" src=\"js/' + AttchFile + '"></script>') ;
}
//
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 = 0 ; 
}
function DecSlideBanner(list) {
//
var Gr0 = number ;
    --number ;
    if (number < 0) number = list.length ;
}
//
function SetIntervalTimer(PrcName,Tim_) {
    timerID = setInterval(PrcName,Tim_) ;
}
//
//
function IsBrowser() {
//
  var strUA = navigator.userAgent.toLowerCase() ;
//
    if(strUA.indexOf("safari") != -1){
        return(1) ;
    }else if(strUA.indexOf("firefox") != -1){
        return(2) ;
    }else if(strUA.indexOf("opera") != -1){
        return(3) ;
    }else if(strUA.indexOf("netscape") != -1){
        return(4) ;
    }else if(strUA.indexOf("msie") != -1){
        return(-1) ;    // Hate!!
    }else if(strUA.indexOf("mozilla/4") != -1){
        return(5) ;
    }
    return(-1) ;        // None
}
//
//
//
// 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 );
} ;
/**/

