//Original sequential fly-in text script - by JavaScriptKit.com
//For the original script and 400+ more, visit http://www.javascriptkit.com
//This notice must stay intact for use

//Customized by BVanScoter to work on Safari
//And including more customization options
//If you like the customizations please donate
//Through PayPal - bvanscoter(at)juno(dot)com
//This notice must stay intact for use

/************************************************************************************/
/*  Added Support For Classes... to use multiple instances of this flyin script     */
/*  on different HTML objects (identified by the class paramater):                  */
/*                                                                                  */
/*                                  INSTRUCTIONS:                                   */
/************************************************************************************/

    /********************************************************************************/
    /*                              - REQUIRED -                                    */
    /*                                                                              */
    /*  Need to define an array with the class names:                               */
    /*      fclasses = new Array('classname_1', 'classname_2', ... 'classname_n');  */
    /*                                                                              */
	/********************************************************************************/

    /********************************************************************************/
    /*                          - OPTIONAL SETTINGS -                               */
    /*                                                                              */
    /*  To cutomize a class's object use:                                           */
    /*      flyin.[classname].[objectname] = '[value]';                             */
    /*          WHERE: [classname] is the HTML class of the object                  */
    /*          WHERE: [objectname] is the object you want to change                */
    /*          WHERE: [value] is the new setting for the object you to change      */
    /*                                                                              */
    /*  See below for all [objectname]'s you can set...                             */
    /*      * = DEFAULT VALUE FOR OPTIONS OR -> -> ->           (DEFAULT VALUE)     */
    /*------------------------------------------------------------------------------*/
    /*      PAUSES:                                                                 */
    /*                                                                              */
    /*      To customize pause in miliseconds for each message's                    */
    /*      duration (1000 = 1 second)...                                           */
    /*          flyin.[classname].pausebetweenmsg = number;     (2000)              */
    /*                                                                              */
    /*      To customize pause in miliseconds between each message's                */
    /*      appearance (1000 = 1 second)...                                         */
    /*          flyin.[classname].pausebetweenshw = number;     (0)                 */
    /*------------------------------------------------------------------------------*/
    /*      SPEED:                                                                  */
    /*                                                                              */
    /*      To customize glide speed in pixels per frame...                         */
    /*          flyin.[classname].glidespeed_ppf = number;      (1)                 */
    /*                                                                              */
    /*      To customize glide speed in miliseconds for frame duration...           */
    /*          flyin.[classname].glidespeed_mpf = number;      (10)                */
    /*------------------------------------------------------------------------------*/
    /*      DIRECTION:                                                              */
    /*                                                                              */
    /*      To customize direction of fly-in (which way it goes)...                 */
    /*      *   flyin.[classname].direction = 'right';                              */
    /*          flyin.[classname].direction = 'down';                               */
    /*          flyin.[classname].direction = 'left';                               */
    /*          flyin.[classname].direction = 'up';                                 */
    /*------------------------------------------------------------------------------*/
    /*      LOOPING:                                                                */
    /*                                                                              */
    /*      To customize looping...                                                 */
    /*          flyin.[classname].loop = number;                                    */
    /*          flyin.[classname].loop = "yes";                                     */
    /*      *   flyin.[classname].loop = "no";                                      */
    /*------------------------------------------------------------------------------*/
    /*      STICKINESS:                                                             */
    /*                                                                              */
    /*      To customize stickiness of last HTML object with classname...           */
    /*          flyin.[classname].sticky = "yes";                                   */
    /*          flyin.[classname].sticky = "no";                                    */
    /*      *   flyin.[classname].sticky = "last";                                  */
    /*                                                                              */
    /*      To customize if message hides (returns to it's original position)...    */
    /*          flyin.[classname].disappear = "yes";                                */
    /*     *    flyin.[classname].disappear = "no";                                 */
    /*                                                                              */
    /*                                                                              */
    /********************************************************************************/

/************************************************************************************/
/*                              END INSTRUCTIONS                                    */
/************************************************************************************/


function Flyin(name)
{
    
    this.pausebetweenmsg = 2000;
    this.pausebetweenshw = 0;
    this.direction = "right";
    this.glidespeed_mpf = 10;
    this.glidespeed_ppf = 1;
    this.classname = name;
    this.disappear = "no";
    this.sticky = "yes";
    this.loop = "no";
    
    this.glidetimer = null;
    this.hidetimer = null;
    this.curobjindex = 0;
    this.initpos = '';
    this.cssprop ='';
    this.lcnt = 1;
}

function actualstyle(el, cssproperty)
{
    if (el.currentStyle) {
        return el.currentStyle[cssproperty];
    }
    else
    if( document.defaultView &&
        document.defaultView.getComputedStyle )
    {
        var elstyle = document.defaultView.getComputedStyle(el,null);
        return elstyle.getPropertyValue(cssproperty);
    }
}

function collectElementbyClass()
{
    this.glidearray = new Array();
    var inc = 0;
    var alltags = document.all? document.all : document.getElementsByTagName("*");
    
    for( i=0; i < alltags.length; i++ )
    {
        if( alltags[i].className == this.classname )
        {
            this.glidearray[inc++] = alltags[i];
        }
    }
    
    if( this.glidearray.length > 0 )
    {
        this.onebyoneglide(this.classname);
    }
}

//start on next text area
function onebyoneglide(cclass)
{
    if( (
            flyin[cclass].loop == "yes" ||
            flyin[cclass].lcnt < flyin[cclass].loop
        ) &&
        flyin[cclass].curobjindex == flyin[cclass].glidearray.length )
    {
        flyin[cclass].curobjindex = 0;
        flyin[cclass].lcnt++;
    }
    
    if( flyin[cclass].curobjindex < flyin[cclass].glidearray.length )
    {
        if( flyin[cclass].direction == "right" ||
            flyin[cclass].direction == "left" )
        {
            flyin[cclass].cssprop = "left";
        }
        
        if( flyin[cclass].direction == "down" ||
            flyin[cclass].direction == "up" )
        {
            flyin[cclass].cssprop = "top";
        }
        
        if( flyin[cclass].initpos == '' )
        {
            flyin[cclass].initpos = parseInt( actualstyle(flyin[cclass].glidearray[flyin[cclass].curobjindex], flyin[cclass].cssprop) );
        }
        
        flyin[cclass].glidetimer = setInterval( "glideroutine('show', '"+cclass+"')", flyin[cclass].glidespeed_mpf );
    }
}

//move the text area
function glideroutine(fnc, cclass)
{
    var css_prop = flyin[cclass].cssprop;
    var dirisDorR = false;
    var dirisUorL = false;
    var next = 'hide';
    
    if( flyin[cclass].direction == "down" ||
        flyin[cclass].direction == "right" )
    {
        dirisDorR = true;
    }
    
    if( flyin[cclass].direction == "up" ||
        flyin[cclass].direction == "left" )
    {
        dirisUorL = true;
	}
	
	if( fnc != "show" &&
	    flyin[cclass].glidearray.length > 1 &&
	    (
	        flyin[cclass].lcnt == flyin[cclass].loop ||
	        flyin[cclass].loop == "no"
	    ) &&
	    (
	        (
	            flyin[cclass].sticky == "last" &&
	            flyin[cclass].curobjindex == (flyin[cclass].glidearray.length - 1)
	        ) ||
	        flyin[cclass].sticky == "yes"
	    ) )
	{
	    flyin[cclass].curobjindex++;
	    clearInterval(flyin[cclass].hidetimer);
	    clearInterval(flyin[cclass].glidetimer);
	    fnc = null;
	    setTimeout("onebyoneglide('"+cclass+"')", flyin[cclass].pausebetweenshw);
	}
	
	if( fnc == "show" )
	{
	    if( dirisDorR &&
	        parseInt( actualstyle(flyin[cclass].glidearray[flyin[cclass].curobjindex], css_prop) ) < 0 )
	    {
	        flyin[cclass].glidearray[flyin[cclass].curobjindex].style[css_prop] = (parseInt( actualstyle(flyin[cclass].glidearray[flyin[cclass].curobjindex], css_prop) ) + this.glidespeed_ppf) + "px";
		}
		else
		if( dirisUorL &&
		    parseInt( actualstyle(flyin[cclass].glidearray[flyin[cclass].curobjindex], css_prop) ) > 0 )
		{
		    flyin[cclass].glidearray[flyin[cclass].curobjindex].style[css_prop] = (parseInt( actualstyle(flyin[cclass].glidearray[flyin[cclass].curobjindex], css_prop) ) - this.glidespeed_ppf) + "px";
		}
		else
		{
		    flyin[cclass].obj = flyin[cclass].glidearray[flyin[cclass].curobjindex];
		    flyin[cclass].obj.style[css_prop] = 0;
		    clearInterval(flyin[cclass].glidetimer);
		    
		    if( flyin[cclass].disappear == "yes" )
		    {
		        next = "disappear";
		    }
		    
		    if( flyin[cclass].glidearray.length > 1 )
		    {
		        flyin[cclass].hidetimer = setInterval("glideroutine('"+next+"', '"+cclass+"')", flyin[cclass].pausebetweenmsg);
		    }
		}
    }
    
    if( fnc == "hide" )
    {
        clearInterval(flyin[cclass].hidetimer);
        flyin[cclass].hidetimer = setInterval("glideroutine('hide', '"+cclass+"')", flyin[cclass].glidespeed_mpf);
        
        if( dirisDorR &&
            parseInt( actualstyle(flyin[cclass].glidearray[flyin[cclass].curobjindex], css_prop) ) > flyin[cclass].initpos )
        {
            flyin[cclass].glidearray[flyin[cclass].curobjindex].style[css_prop] = (parseInt( actualstyle(flyin[cclass].glidearray[flyin[cclass].curobjindex], css_prop) ) - flyin[cclass].glidespeed_ppf) + "px";
        }
        else
        if( dirisUorL &&
            parseInt( actualstyle(flyin[cclass].glidearray[flyin[cclass].curobjindex], css_prop) ) < flyin[cclass].initpos )
        {
            flyin[cclass].glidearray[flyin[cclass].curobjindex].style[css_prop] = (parseInt( actualstyle(flyin[cclass].glidearray[flyin[cclass].curobjindex], css_prop) ) + glidespeed_ppf) + "px";
         }
         else
         {
             glideroutine("disappear", cclass);
         }
    }
    
    if( fnc == "disappear" )
    {
        flyin[cclass].glidearray[flyin[cclass].curobjindex].style[css_prop] = flyin[cclass].initpos + "px";
        flyin[cclass].curobjindex++;
        clearInterval(flyin[cclass].hidetimer);
        clearInterval(flyin[cclass].glidetimer);
        
        setTimeout("onebyoneglide('"+cclass+"')", flyin[cclass].pausebetweenshw);
    }
}

function hide(cclass)
{
    clearInterval(flyin[cclass].hidetimer);
    clearInterval(flyin[cclass].glidetimer);
    
    flyin[cclass].curobjindex = 0;
    flyin[cclass].lcnt = 1;
    
    for( x = 0; x < flyin[cclass].glidearray.length; x++ )
    {
        flyin[cclass].glidearray[x].style[flyin[cclass].cssprop] = flyin[cclass].initpos;
    }
}

function show(cclass)
{
    clearInterval(flyin[cclass].hidetimer);
    clearInterval(flyin[cclass].glidetimer);
    
    flyin[cclass].curobjindex = 0;
    flyin[cclass].lcnt = 1;
    
    for( x = 0; x < flyin[cclass].glidearray.length; x++ )
    {
        flyin[cclass].glidearray[x].style[flyin[cclass].cssprop] = flyin[cclass].initpos;
    }
    
    flyin[cclass].onebyoneglide(cclass);
}

function startFlyinScript()
{
    for( x = 0; x < flyin_class_names.length; x++ )
    {
        current = flyin[flyin_class_names[x]];
        current.collectElementbyClass();
    }
}

// Assign prototype method(s)
Flyin.prototype.collectElementbyClass = collectElementbyClass;
Flyin.prototype.onebyoneglide = onebyoneglide;
// */


// SETS flyin.classname.object FROM flyin_class_names ARRAY:
var flyin = new Array();
var myself = new Array();
for( x = 0; x < flyin_class_names.length; x++ )
{
    flyin[flyin_class_names[x]] = new Flyin(flyin_class_names[x]);
    myself[flyin_class_names[x]] = Flyin(flyin_class_names[x]);
}

// Starts script onLoad:
// (Seems to start all classes onLoad)
if( window.addEventListener )
{
    window.addEventListener("load", startFlyinScript, false);
}
else
if( window.attachEvent )
{
    window.attachEvent("onload", startFlyinScript);
}
else
if( document.getElementById )
{
    window.onload = startFlyinScript;
}