/*
* ¼¼·Î·Î
¾ÆÀÌÅÛÀ» ÀÏÁ¤ ½Ã°£ °£°ÝÀ¸·Î À§ ¾Æ·¡·Î ·Ñ¸µÇÏ´Â ÄÞÆ÷³ÍÆ®
* Require : prototype, scriptaculous
*/
function VerticalRoller(id, interval) {
this.rollUpTimer= null;
this.feedCount = 0;
this.id = id;
this.roller = $(id);
this.rollUpInterval = interval==null?3000:interval;
this.rollUpCount = 0;
this.rolling = false;
this.feedHeight = 0;
}
VerticalRoller.prototype.initRoller = function() {
this.rolling = true;
this.roller.style.position = 'relative';
var feedList = this.roller.getElementsByTagName("li");
for(i = 0 ; i < feedList.length ; i++ ){
feedList[i].id = this.id + "-item" + (i+1);
this.feedHeight += feedList[i].offsetHeight;
}
this.feedCount = feedList.length;
//get canvas
if(this.rollUpCount == 0) {
rollUpAmount = $(this.id + "-item" + (this.rollUpCount+1)).offsetHeight;
} else {
rollUpAmount = $(this.id + "-item" + (this.rollUpCount+1)).offsetHeight;
}
if(this.rollUpTimer) window.clearTimeout(this.rollUpTimer);
this.rollUpTimer = window.setTimeout(this.rollUp(rollUpAmount,this),this.rollUpInterval);
};
VerticalRoller.prototype.rollStop = function() {
if(this.rollUpTimer) window.clearTimeout(this.rollUpTimer);
this.rolling = false;
};
VerticalRoller.prototype.resumeRollUp = function() {
if(this.rollUpTimer) window.clearTimeout(this.rollUpTimer);
rollUpAmount = $(this.id + "-item" + (this.rollUpCount+1)).offsetHeight;
this.rolling = true;
this.rollUpTimer = window.setTimeout(this.rollUp(rollUpAmount,this),this.rollUpInterval);
};
VerticalRoller.prototype.resumeRollDown = function() {
if(this.rollUpTimer) window.clearTimeout(this.rollUpTimer);
rollUpAmount = $(this.id + "-item" + (this.rollUpCount+1)).offsetHeight;
this.rolling = true;
this.rollUpTimer = window.setTimeout(this.rollDown(rollUpAmount,this),this.rollUpInterval);
};
VerticalRoller.prototype.rollUp = function(rollUpAmount, vr){
return (function() {
if(!vr.rolling) return;
var feedList = vr.roller.getElementsByTagName("li");
var moveList = new Array();
for(i = 0 ; i < feedList.length ; i++ ){
moveList[moveList.length] = new Effect.Move(feedList[i], {
sync:true
, x:0
, y: -rollUpAmount
, mode: 'relative'} );
}
new Effect.Parallel(moveList, {
duration: 1 ,
beforeStart : function( effect ) {
/* rollUpCount ¹øÂ° À§Ä¡ ¹ØÀ¸·Î À̵¿*/
new Effect.Move(vr.id + "-item" + (vr.rollUpCount + 1),
{x:0, y: +(vr.feedHeight), mode:'relative', duration:0});
},
afterFinish : function( effect ) {
vr.rollUpCount++;
vr.rollUpCount = (vr.rollUpCount) % vr.feedCount;
if(vr.rollUpCount == 0) {
rollUpAmount = $(vr.id + "-item" + (vr.rollUpCount+1)).offsetHeight;
} else {
rollUpAmount = $(vr.id + "-item" + (vr.rollUpCount+1)).offsetHeight;
}
if(vr.rollUpTimer) clearTimeout(vr.rollUpTimer);
vr.rollUpTimer = setTimeout(vr.rollUp(rollUpAmount,vr),vr.rollUpInterval);
}
});
});
};
VerticalRoller.prototype.rollDown = function(rollUpAmount, vr){
return (function() {
if(!vr.rolling) return;
var feedList = vr.roller.getElementsByTagName("li");
var moveList = new Array();
for(i = 0 ; i < feedList.length ; i++ ){
moveList[moveList.length] = new Effect.Move(feedList[i], {
sync:true
, x:0
, y: +rollUpAmount
, mode: 'relative'} );
}
vr.rollUpCount--;
if(vr.rollUpCount < 0) vr.rollUpCount = vr.feedCount -1;
new Effect.Parallel(moveList, {
duration: 1 ,
beforeStart : function( effect ) {
/* rollUpCount ¹øÂ° À§Ä¡ ¹ØÀ¸·Î À̵¿*/
new Effect.Move(vr.id + "-item" + (vr.rollUpCount + 1),
{x:0, y: -(vr.feedHeight), mode:'relative', duration:0});
},
afterFinish : function( effect ) {
if(vr.rollUpCount == 0) {
rollUpAmount = $(vr.id + "-item" + (vr.rollUpCount+1)).offsetHeight;
} else {
rollUpAmount = $(vr.id + "-item" + (vr.rollUpCount+1)).offsetHeight;
}
if(vr.rollUpTimer) clearTimeout(vr.rollUpTimer);
vr.rollUpTimer = setTimeout(vr.rollDown(rollUpAmount,vr),vr.rollUpInterval);
}
});
});
};