document.write("                                                                                            ");

/************************************************************************/
/* rainbow link version 1.00 (1999.6.10)                                */
/*                                                                      */
/* copyright (c) 1999-2001 takanashi mizuki                             */
/* takanasi@hamal.freemail.ne.jp                                        */
/*----------------------------------------------------------------------*/
/* read it somehow even if my english text is a little wrong! ;-)       */
/*                                                                      */
/* usage:                                                               */
/*  insert '<script src="rainbow.js"></script>' into the body section,  */
/*  right after the body tag itself, before anything else.              */
/*  you don't need to add "onmouseover" and "onmouseout" attributes!!   */
/*                                                                      */
/*  if you'd like to add effect to other texts(not link texts), then    */
/*  add 'onmouseover="dorainbow();"' and 'onmouseout="stoprainbow();"'  */
/*  to the target tags.                                                 */
/*                                                                      */
/* this script works with ie4 and above only, but no error occurs on    */
/* other browsers.                                                      */
/************************************************************************/


////////////////////////////////////////////////////////////////////
// setting

var rate = 20;  // increase amount(the degree of the transmutation)


////////////////////////////////////////////////////////////////////
// main routine

var obj;        // the object which event occured in
var act = 0;    // flag during the action
var elmh = 0;   // hue
var elms = 128; // saturation
var elmv = 255; // value
var clrorg;     // a color before the change
var timerid;    // timer id


if (navigator.appname.indexof("microsoft",0) != -1 && parseint(navigator.appversion) >= 4) {
    browser = true;
} else {
    browser = false;
}

if (browser) {
    document.onmouseover = dorainbowanchor;
    document.onmouseout = stoprainbowanchor;
}


//=============================================================================
// dorainbow
//  this function begins to change a color.
//=============================================================================
function dorainbow()
{
    if (browser && act != 1) {
        act = 1;
        obj = event.srcelement;
        clrorg = obj.style.color;
        timerid = setinterval("changecolor()",100);
    }
}


//=============================================================================
// stoprainbow
//  this function stops to change a color.
//=============================================================================
function stoprainbow()
{
    if (browser && act != 0) {
        obj.style.color = clrorg;
        clearinterval(timerid);
        act = 0;
    }
}


//=============================================================================
// dorainbowanchor
//  this function begins to change a color. (of a anchor, automatically)
//=============================================================================
function dorainbowanchor()
{
    if (browser && act != 1) {
        obj = event.srcelement;

        while (obj.tagname != 'a' && obj.tagname != 'body') {
            obj = obj.parentelement;
            if (obj.tagname == 'a' || obj.tagname == 'body')
                break;
        }

        if (obj.tagname == 'a' && obj.href != '') {
            act = 1;
            clrorg = obj.style.color;
            timerid = setinterval("changecolor()",100);
        }
    }
}


//=============================================================================
// stoprainbowanchor
//  this function stops to change a color. (of a anchor, automatically)
//=============================================================================
function stoprainbowanchor()
{
    if (browser && act != 0) {
        if (obj.tagname == 'a') {
            obj.style.color = clrorg;
            clearinterval(timerid);
            act = 0;
        }
    }
}


//=============================================================================
// change color
//  this function changes a color actually.
//=============================================================================
function changecolor()
{
    obj.style.color = makecolor();
}


//=============================================================================
// makecolor
//  this function makes rainbow colors.
//=============================================================================
function makecolor()
{
    // don't you think color gamut to look like rainbow?

    // hsvtorgb
    if (elms == 0) {
        elmr = elmv;    elmg = elmv;    elmb = elmv;
    }
    else {
        t1 = elmv;
        t2 = (255 - elms) * elmv / 255;
        t3 = elmh % 60;
        t3 = (t1 - t2) * t3 / 60;

        if (elmh < 60) {
            elmr = t1;  elmb = t2;  elmg = t2 + t3;
        }
        else if (elmh < 120) {
            elmg = t1;  elmb = t2;  elmr = t1 - t3;
        }
        else if (elmh < 180) {
            elmg = t1;  elmr = t2;  elmb = t2 + t3;
        }
        else if (elmh < 240) {
            elmb = t1;  elmr = t2;  elmg = t1 - t3;
        }
        else if (elmh < 300) {
            elmb = t1;  elmg = t2;  elmr = t2 + t3;
        }
        else if (elmh < 360) {
            elmr = t1;  elmg = t2;  elmb = t1 - t3;
        }
        else {
            elmr = 0;   elmg = 0;   elmb = 0;
        }
    }

    elmr = math.floor(elmr);
    elmg = math.floor(elmg);
    elmb = math.floor(elmb);

    clrrgb = '#' + elmr.tostring(16) + elmg.tostring(16) + elmb.tostring(16);

    elmh = elmh + rate;
    if (elmh >= 360)
        elmh = 0;

    return clrrgb;
}
