// JavaScript Document
if(typeof sprink == "undefined")
var sprink = {};

sprink.Rotator = function(name) {
this.name = name;
this.isset = false;
}
sprink.Rotator.prototype = {
create: function(preset_html) {
if(!document.getElementById(this.name))
{
if(!preset_html)
preset_html = "";

var html = "<div id='" + this.name + "'>" + preset_html + "</div>";
document.write(html);
}
this.initialize();
},
initialize: function() {
this.rot_el = document.getElementById(this.name);
if(this.rot_el)
this.isset = true;

this.obj_list = new Array();
this.detectUI();
this.accuracy = 10;
this.interval = 5;
this.auto_rotate = false;
this.mode = "stopped";
this.UI_catch_list = new Array();
this.UI_catch_list[0] = "prev";
this.UI_catch_list[1] = "next";
this.rotate_timer = false;
this.current_pos = 0;
},
detectUI: function() {
this.hasUI = false;
this.respondToUI = false;
if(document.getElementById(this.name + "_UI"))
{
this.hasUI = true;
this.respondToUI = true;
}
},
startAutoRotate: function(call_back_fn) {
this.speed = this.interval * this.accuracy;
if(this.auto_rotate === true)
this.rotate_timer = setInterval(this.name + "." + call_back_fn, this.speed);
},
stopAutoRotate: function() {
clearInterval(this.rotate_timer);
},
initializeDisplay: function() {
this.setCurrentObj(this.obj_list[0]);
},
showNext: function() {
var next_pos = this.checkObjLen(this.current_pos + 1, "max");
this.setCurrentObj(this.obj_list[next_pos]);
this.current_pos = next_pos;
},
showPrev: function() {
var prev_pos = this.checkObjLen(this.current_pos - 1, "min");
this.setCurrentObj(this.obj_list[prev_pos]);
this.current_pos = prev_pos;
},
addObj: function(obj_content) {
if(this.obj_list)
{
var next_index = this.obj_list.length;
this.obj_list[next_index] = obj_content;
}
},
checkObjLen: function(value, type) {
var len = this.obj_list.length-1;
switch(type)
{
case "max":
if(value > len)
return 0;
break;
case "min":
if(value < 0)
return len;
break;
}
return value;
},
setCurrentObj: function(obj) {
if(this.isset === true)
{
this.rot_el.innerHTML = obj;
}
},
playSR: function() {
if(this.mode != "playing")
{
this.auto_rotate = true;
this.startAutoRotate("showNext()");
this.mode = "playing";
}
},
revPlaySR: function() {
if(this.mode != "playingRev")
{
this.auto_rotate = true;
this.startAutoRotate("showPrev()");
this.mode = "playingRev";
}
},
pauseSR: function() {
this.stopAutoRotate();
this.mode = "paused";
},
stopSR: function() {
if(this.mode != "stopped")
{
this.stopAutoRotate();
this.current_pos = 0;
this.setCurrentObj(this.obj_list[0]);
this.mode = "stopped";
}
},
BtnNext: function() {
this.checkUICatchList("next");
this.showNext();
},
BtnPrev: function() {
this.checkUICatchList("prev");
this.showPrev();
},
BtnPlay: function() {
this.playSR();
},
checkUICatchList: function(action_to_catch) {
for(x in this.UI_catch_list)
{
if(action_to_catch == this.UI_catch_list[x])
{
this.pauseSR();
return true;
}
}
return false;
}
}

/* Shortcut variables */
var $SR = sprink.Rotator;
