/* 360sc.js Scroll script Copyright(c)M.Murakami 2002-2007 mmurakami@mx4.kiti.ne.jp */
/* 360sc2 2007.06.24 corresponds to FireFox2 */
/* 360sc3 2007.07.01 corresponds to Netscape7 */

pic1x = 0;
pic2x = 0;
mdot = 1 ; // dot
tms = 20 ; // ms
ds = 20 ; // dot
sp = 0 ;
dw = 0 ;
pn_flg = true ;
play_flg = true ;
down_flg = false ;
pic_flg = false ;
ctl = true ;
spd = ">" ;
p2 = "" ;
var scrID;
var timerID;

/* Controller */
if (ctl) {
	document.write(
	"<TABLE id='cont1' style='visibility:hidden' width='100%' cellpadding='0' cellspacing='0'>",
	" <TBODY>",
	"  <TR>",
	"   <TD>",
	"    <TABLE cellpadding='0' cellspacing='4'>",
	"     <TBODY>",
	"      <TR>",
	"       <TD nowrap width='70' id='pic' onmousedown='b_click(\"pic\")' style='background-color:#cccccc; color:#000000; font-size:13px; text-align:center; cursor:hand'>Scroll off</TD>",
	"       <TD nowrap width='16'></TD>",
	"       <TD nowrap width='50' id='play' onmousedown='b_click(\"play\")' style='background-color:#bbbb99; color:#000000; font-size:13px; text-align:center; cursor:hand'>Play</TD>",
	"       <TD nowrap width='40' id='rev' onmousedown='b_click(\"rev\")' style='background-color:#bbbb99; color:#000000; font-size:13px; text-align:center; cursor:hand'>Rev.</TD>",
	"       <TD nowrap width='24' id='f' onmousedown='b_click(\"f\")' style='background-color:#bbbb99; color:#000000; font-size:10px; text-align:center; cursor:hand'>&gt;</TD>",
	"       <TD nowrap width='24' id='ff' onmousedown='b_click(\"ff\")' style='background-color:#bbbb99; color:#000000; font-size:10px; text-align:center; cursor:hand'>&gt;&gt;</TD>",
	"       <TD nowrap width='24' id='fff' onmousedown='b_click(\"fff\")' style='background-color:#bbbb99; color:#000000; font-size:10px; text-align:center; cursor:hand'>&gt;&gt;&gt;</TD>",
	"       <TD nowrap width='16'></TD>",
	"       <TD nowrap width='30' onmousedown='b_updown(\"f_down\")' onmouseup='b_updown(\"f_up\")' onmouseout='b_updown(\"out\")' style='background-color:#bbbb99; color:#000000; font-size:10px; text-align:center; cursor:hand'>&lt;--</TD>",
	"       <TD nowrap width='30' onmousedown='b_updown(\"r_down\")' onmouseup='b_updown(\"r_up\")' onmouseout='b_updown(\"out\")' style='background-color:#bbbb99; color:#000000; font-size:10px; text-align:center; cursor:hand'>--&gt;</TD>",
	"       <TD nowrap width='16'></TD>",
	"      </TR>",
	"     </TBODY>",
	"    </TABLE>",
	"   </TD>",
	"   <TD id='cont2' align='right' nowrap width='100%'><A href='http://ww4.tiki.ne.jp/~mmurakami/setoy/' target='_blank'><FONT size='-1' color='#aaaa88'>JavaScript by M.Murakami</FONT></A></TD>",
	"  </TR>",
	" </TBODY>",
	"</TABLE>"
	);
};

/* size */
function pwset(){
	if ( p2 != "" ){ document.getElementById("pic2").src = p2 };
	if ( document.getElementById("pic2").src == ""){ document.getElementById("pic2").src = document.getElementById("pic1").src };
	document.getElementById("pic1").style.position = "relative" ;
	document.getElementById("pic2").style.position = "relative" ;
	dw = mdot ;
	spmax = mdot * 10 ;

	switch (spd){
		case '>' : dw = mdot ; break ;
		case '>>' : dw = mdot * 2 ; break ;
		case '>>>' : dw = mdot * 4 ; break ;
	}

	if ((document.referrer.search(/setoy/i) > 0 ) && ctl) {document.getElementById("cont2").style.visibility="hidden" };

	b_set();
	pn_flg = true ; s_mov();
}

/* start move */
function s_mov(){
	clearInterval(scrID);
	if ( pn_flg ) { scrID=setInterval('p_mov()',tms)} else { scrID=setInterval('n_mov()',tms)};
}

/* move left */
function p_mov(){
	pic1x -= dw;
	pic2x -= dw;
	if ( pic1x < -(document.getElementById("pic1").width + ds)) { pic1x = pic2x + document.getElementById("pic1").width + document.getElementById("pic2").width } ;
	if ( pic2x < -(document.getElementById("pic1").width + document.getElementById("pic2").width + ds)) { pic2x = pic1x} ;
	document.getElementById("pic1").style.left = pic1x + "px" ;  document.getElementById("pic2").style.left = pic2x + "px" ;
}

/* move right */
function n_mov(){
	pic1x += dw;
	pic2x += dw;
	if ( pic1x > document.getElementById("pic2").width - ds) { pic1x = pic2x} ;
	if ( pic2x > -ds) { pic2x = pic1x - (document.getElementById("pic1").width + document.getElementById("pic2").width)} ;
	document.getElementById("pic1").style.left = pic1x + "px" ;  document.getElementById("pic2").style.left = pic2x + "px" ;
}

/* turn */
function t_mov(){
	timerID = setTimeout( "s_mov()", st );
	b_set();
}

/* show buttons */
function b_set(){
	if (ctl) {
		document.getElementById("cont1").style.visibility = "visible";
		if (play_flg){document.getElementById("play").innerText="Stop"} else { document.getElementById("play").innerText="Play" };
		if (pn_flg){document.getElementById("f").innerText=">";document.getElementById("ff").innerText=">>";document.getElementById("fff").innerText=">>>"}
			else {document.getElementById("f").innerText="<";document.getElementById("ff").innerText="<<";document.getElementById("fff").innerText="<<<"};
		if (pic_flg) {document.getElementById("pic").innerText="Scroll On"}
			else {document.getElementById("pic").innerText="Scroll Off"};
	};
}

/* button click */
function b_click(b){
	clearInterval(scrID);
	switch (b){
		case 'play' : play_flg = !play_flg ; break;
		case 'f' : dw = mdot ; play_flg = true ; break;
		case 'ff' : dw = mdot * 2 ; play_flg = true ; break;
		case 'fff' : dw = mdot * 4 ; play_flg = true ; break;
		case 'rev' : pn_flg = !pn_flg ; break;
		case 'pic' : if (pic_flg) { pic_flg = false ; pn_flg = true ; play_flg = true }
				else { pic_flg = true ; pn_flg = true ; play_flg = false ; pic1x = 0; pic2x = 0 ; document.getElementById("pic1").style.left = pic1x + "px" ;  document.getElementById("pic2").style.left = pic2x + "px" ;} ; break;
	}
	if (play_flg) { pic_flg = false };
	b_set();
	if (play_flg) { pic_flg = false ;  s_mov() };
}

/* Arrow move right */
function pf_mov(){
	pic1x -= sp ;
	pic2x -= sp ;
	if ( pic1x < -(document.getElementById("pic1").width + ds)) { pic1x = pic2x + document.getElementById("pic1").width + document.getElementById("pic2").width } ;
	if ( pic2x < -(document.getElementById("pic1").width + document.getElementById("pic2").width + ds)) { pic2x = pic1x} ;
	document.getElementById("pic1").style.left = pic1x + "px";  document.getElementById("pic2").style.left = pic2x + "px" ;
	if ( sp < spmax ) { sp += 1 } ;
	if (down_flg) { timerID = setTimeout( "pf_mov()", tms ) } 
}
/* Arrow move left */
function nf_mov(){
	pic1x += sp ;
	pic2x += sp ;
	if ( pic1x > document.getElementById("pic2").width - ds) { pic1x = pic2x} ;
	if ( pic2x > -ds) { pic2x = pic1x - (document.getElementById("pic1").width + document.getElementById("pic2").width)} ;
	document.getElementById("pic1").style.left = pic1x + "px";  document.getElementById("pic2").style.left = pic2x + "px" ;
	if ( sp < spmax ) { sp += 1 } ;
	if (down_flg) {  timerID = setTimeout( "nf_mov(sp)", tms ) } 
}

/* Arrow click */
function b_updown(b){
	switch (b){
		case 'r_down' : pn_flg = true  ; down_flg = true ; break ;
		case 'f_down' : pn_flg = false ; down_flg = true ; break ;
		default : down_flg = false ;
	}
	if (down_flg) {
		if (!play_flg) {sp = 0}  else {sp = dw}; 
		clearInterval(scrID) ; play_flg = false ; pic_flg = false ; b_set();
		if (pn_flg) {pf_mov()} else {nf_mov()};
	};
}
