// functions to load job elements

// global variable
var arImgRoll = Array();

// 2005/05/04 - this thing is just taking way too long
//-dynamic image preload and rollover, also assign onmouseover/onmouseout handlers
// note: to assign an image to roll you must set up your tags like this:
// <a> class is "imageRoll" with the name attribute set
// <img> id is <a> tag name appended with "Img"
// <img> src split at the dot, which does two things:
// 1) path & filename are preserved in array key 0
// 2) extension is preserved in array key 1
// <img> over state src file must be the same as image filename with "_over" appended

function preloadImg()
{
    if( document.images )
    {
        // step one: determine image rollover links and assign mouseover handlers
        // declare variables, arrays and objects with all named links
        var eLinkObj = document.getElementsByTagName("a"); // a tag elements
        var eImgSrc = Array(); // temp array to hold image object info
        var imageRollId = null; // temp variable to hold array key index


        for( var i = 0; i < eLinkObj.length; i++ )
        {
            if( eLinkObj[i].className == "imageRoll" )
            {
                // parse object filename; split at "." so [0] is filename, [1] is extension
                // onmouseover "roll" state is filename + "_over"
                // this script requires both images to have same extension
                imageRollId = eLinkObj[i].name + "Img";
                eImgSrc["complete"] = xGetElementById( imageRollId ).src;

                // store filename in ["fname"], extension in ["ext"] and verify it's an image type
                eImgSrc["fname"] = eImgSrc["complete"].substring( 0, eImgSrc["complete"].length - 4 );
                eImgSrc["ext"] = eImgSrc["complete"].substring( eImgSrc["complete"].length - 3 );
                if( "gifjpgpng".indexOf( eImgSrc["ext"] ) == -1 )
                {
                    alert( eImgSrc["ext"] + "is not a valid image type" );
                    continue;
                }

                arImgRoll[imageRollId] = Array();
                arImgRoll[imageRollId]["over"] = new Image();
                arImgRoll[imageRollId]["over"].src = eImgSrc["fname"] + "_over." + eImgSrc["ext"];
                arImgRoll[imageRollId]["up"] = new Image();
                arImgRoll[imageRollId]["up"].src = eImgSrc["fname"] + "." + eImgSrc["ext"];

                eLinkObj[i].onmouseover = function()
                {
                    if( arImgRoll["preload"] )
                    {
                        var imageRollId = this.name + "Img";
                        xGetElementById( imageRollId ).src = arImgRoll[imageRollId]["over"].src;
                    }
                }
                eLinkObj[i].onmouseout = function()
                {
                    if( arImgRoll["preload"] )
                    {
                        var imageRollId = this.name + "Img";
                        xGetElementById( imageRollId ).src = arImgRoll[imageRollId]["up"].src;
                    }
                }
            }
        }

        // step 2 start the image flip timer
        var eLinkObj = document.getElementsByTagName( "img" );

        for( var i = 0; i < eLinkObj.length; i++ )
        {
            if( eLinkObj[i].className == "imageFlip" )
            {
                // parse object filename; split at "." so [0] is filename, [1] is extension
                // onmouseover "roll" state is filename + "_over"
                // this script requires both images to have same extension
                // note: when accessing images directly, we only need an id tag
                imageRollId = eLinkObj[i].id;
                eImgSrc["complete"] = xGetElementById( imageRollId ).src;

                // store filename in ["fname"], extension in ["ext"] and verify it's an image type
                eImgSrc["fname"] = eImgSrc["complete"].substring( 0, eImgSrc["complete"].length - 4 );
                eImgSrc["ext"] = eImgSrc["complete"].substring( eImgSrc["complete"].length - 3 );
                if( "gifjpgpng".indexOf( eImgSrc["ext"] ) == -1 )
                {
                    alert( eImgSrc["ext"] + "is not a valid image type" );
                    continue;
                }

                arImgRoll[imageRollId] = Array();
                arImgRoll[imageRollId]["over"] = new Image();
                arImgRoll[imageRollId]["over"].src = eImgSrc["fname"] + "_over." + eImgSrc["ext"];
                arImgRoll[imageRollId]["up"] = new Image();
                arImgRoll[imageRollId]["up"].src = eImgSrc["fname"] + "." + eImgSrc["ext"];

                flipTimer = window.setTimeout( "imgFlip();", 3879 );
                arImgRoll["imgflip"] = true;
                }
        }
        arImgRoll["preload"] = true;
    }
    else
    {
        arImgRoll["preload"] = false;
    } // end else
}


function imgFlip()
{
    if( arImgRoll["imgflip"] )
    {
        imgid = "imageFlip";
        var i = xGetElementById( imgid );
        if( i.src == arImgRoll[imgid]["over"].src )
        {
            fliper = "up";
        }
        else
        {
            fliper = "over";
        }
        xGetElementById( imgid ).src = arImgRoll[imgid][fliper].src;
        flipTimer = window.setTimeout( "imgFlip();", 500 );
    }
}

function swoopSwap( arg )
{
    arg = arg ? 6 : 1;
    xZIndex( "pageSidebar", arg );
}

function validateFields()
{
    // right now we only check for blanks;
    // there is also a validator in the main program in case of disabled javascript
    var frmFields = arguments;

    // first argument is form name
    var frmName = "document." + frmFields[0];
    var chkValue, blFields;

    for( var i = 0; i < frmFields.length; i++ )
    {
        // if only 1 field, field name is same as form name
        // otherwise the field names start with argument 2
        if( frmFields.length > 1 && i == 0 )
        {
            continue;
        }

        chkValue = eval( frmName + "." + frmFields[i] + ".value" );

        if( typeof( chkValue ) == "undefined" || chkValue == "" )
        {
            blFields = true;
            break;
        }
    }

    if( blFields )
    {
        if( typeof( errmsg ) == "undefined" )
        {
            errmsg = "Please fill in blank fields";
        }


        alert( errmsg );
        return false;
    }
    else
    {
        eval( frmName + ".submit()" );
    }
}

function reszContent( htOffset )
{
    // version 1: fit the footer to the content and stretch "earnings"
    // to extend the sidebar
    // htOffset is only used for videoindex because it somehow breaks
    // the form, even though it's the same coding as search results!

    var pgContBot = ( xHeight( "pageContent" ) + xOffsetTop( "pageContent" ) );
    var pgFootTop = ( xOffsetTop( "pageFooter" ) );
    var pgSbarHt = ( xHeight( "pageSidebar" ) );
    var eHeight = ( xHeight( "profileEarnings" ) );

    if( pgContBot > pgFootTop )
    {
        var pgFootTop = pgContBot;
        xTop( "pageFooter", pgFootTop );
    }
    else
    {
    //  if( pgContBot < pgSbarHt || pgContBot > pgSbarHt )
        pgContBot = pgFootTop;
    }

    eHeight = ( pgContBot - ( pgSbarHt - eHeight ) + htOffset );
    xHeight( "profileEarnings", eHeight );
    xShow( "pageFooter" );
}

function reposFooter()
{
    // version 2: fit the footer to the content and reposition "sidebar"
    var pgContBot = ( xHeight( "pageContent" ) + xOffsetTop( "pageContent" ) );
    var pgFootTop = ( xOffsetTop( "pageFooter" ) );
    var pgSbarHt = xHeight( "pageSidebar" );

    var botOffset = 5;
    var sBarOffset = -10;

    if( pgContBot > pgFootTop )
    {
        xTop( "pageFooter", ( pgContBot + botOffset ) );
        xTop( "pageSidebar", ( pgContBot - ( pgSbarHt + sBarOffset ) ) );
    }
    xShow( "pageFooter" );
}


// scrollbar functions
// many thanks to x creator Michael Foster http://www.Cross-Browser.com

var scrollActive = false, scrollStop = true, scrollIncrement = 10, scrollInterval = 60;

function activateScroller()
{
  var up = xGetElementById('upBtn');
  var dn = xGetElementById('dnBtn');
  var sc = xGetElementById('vScroller1');

  up.onmouseover = onScrollUpStart;
  up.onmouseout = onScrollStop;
//  xMoveTo(up, xPageX(sc) + xWidth(sc), xPageY(sc));

  dn.onmouseover = onScrollDnStart;
  dn.onmouseout = onScrollStop;
//  xMoveTo(dn, xPageX(sc) + xWidth(sc), xPageY(sc) + xHeight(sc) - xHeight(dn));
}

function onScrollDnStart()
{
  if (!scrollActive)
  {
    scrollStop = false;
    onScrollDn();
  }
}

function onScrollDn()
{
  if (!scrollStop)
  {
    scrollActive = true;
    setTimeout('onScrollDn()', scrollInterval);
    var sc = xGetElementById('vScrollee1');
    var y = xTop(sc) - scrollIncrement;

    if (y >= -(xHeight(sc) - xHeight('vScroller1')) -12)
    {
      xTop(sc, y);
    }
    else
    {
      scrollStop = true;
      scrollActive = false;
    }
  }
}

function onScrollUpStart()
{
  if (!scrollActive)
  {
    scrollStop = false;
    onScrollUp();
 }
}

function onScrollUp()
{
  if (!scrollStop)
  {
    scrollActive = true;
    setTimeout('onScrollUp()', scrollInterval);
    var sc = xGetElementById('vScrollee1');
    var y = xTop(sc) + scrollIncrement;
    if (y <= 0)
    {
      xTop(sc, y);
    }
    else
    {
      scrollStop = true;
      scrollActive = false;
    }
  }
}

function onScrollStop()
{
  scrollStop = true;
  scrollActive = false;
}
