/* PreLoader */
Prototype.preloadCssImages = function() {
  var allImgs = [];

  $A(document.styleSheets).each(function(sheet) {
    var cssPile = '',
     csshref    = sheet.href || window.location.href,
     baseURLarr = csshref.split('/');

    baseURLarr.pop();//remove file path from baseURL array
    var baseURL = baseURLarr.join('/'); //create base url for the images in this sheet (css file's dir)
    if (baseURL) baseURL += '/'; //tack on a / if needed

    if (sheet.cssRules) {
      $A(sheet.cssRules).each(function(rule) {
        cssPile += rule.cssText;
      });
    } else cssPile += sheet.cssText;

    //parse cssPile for image urls and load them into the DOM
    cssPile.gsub(/[^\(]+\.(?:gif|jpg|jpeg|png)/, function(match) { //reg ex to get a string of between a "(" and a ".filename"
       var url = match[0];
       allImgs.push(new Image());
       allImgs.last().src = (url[0] == '/' || url.match('http://')) ? 
         url : baseURL + url;  //set src either absolute or rel to css dir
    });
  });

  return allImgs;
};


/* Portfolio Scripts */
var curimage = 'print1';

function ShowImages(divid, imageid)
{
    //Scroll out current image
    if(curimage != '')
    {
        ScrollOut('right');
    }
    
    setTimeout("ShowDiv('"+divid+"')",700);
        
    //Scroll in new image
    curimage = imageid;
    setTimeout("ScrollIn('left')",1400);
    return true;
}

function ShowDiv(divid)
{
    //Show correct Div
    if(divid == 'LogoImages')
        document.getElementById('LogoImages').style.display = 'block';
    else
        document.getElementById('LogoImages').style.display = 'none';
    if(divid == 'WebImages')
        document.getElementById('WebImages').style.display = 'block';
    else
        document.getElementById('WebImages').style.display = 'none';
    if(divid == 'PrintImages')
        document.getElementById('PrintImages').style.display = 'block';
    else
        document.getElementById('PrintImages').style.display = 'none';}

function ScrollOut(direction)
{
    var newimage = curimage;
    if(direction == 'left')
    {
        //scrollout visible
        new Effect.Move(newimage, { x: -800, y: 0 });
        //scroll in invisible to put it back
        setTimeout("document.getElementById('"+newimage+"').style.display = 'none'",900);
        setTimeout("new Effect.Move('"+newimage+"', { x: 800, y: 0 })", 1000);
    }
    else
    {
        //scrollout visible
        new Effect.Move(newimage, { x: 800, y: 0 });
        //scroll in invisible to put it back
        setTimeout("document.getElementById('"+newimage+"').style.display = 'none'",900);
        setTimeout("new Effect.Move('"+newimage+"', { x: -800, y: 0 })", 1000);
    }
    
}

function ScrollIn(direction)
{
    var newimage = curimage;
    if(direction == 'left')
    {
        //Scroll out invisible
        new Effect.Move(newimage, { x: -800, y: 0 });
        //Scroll in visible
        setTimeout("document.getElementById('"+newimage+"').style.display = 'block'",900);
        setTimeout("new Effect.Move('"+newimage+"', { x: 800, y: 0 })",1000);
    }
    else
    {
        //Scroll out invisible
        new Effect.Move(newimage, { x: 800, y: 0 });
        //Scroll in visible
        setTimeout("document.getElementById('"+newimage+"').style.display = 'block'", 900);
        setTimeout("new Effect.Move('"+newimage+"', { x: -800, y: 0 })", 1000);
    }
}

function SetCurImage(direction)
{
    var len = curimage.length;
    if(direction == 'right')
    {
        if(curimage[len-1] == '8')
            curimage = curimage.substr(0,len-1) + '1';
        else
            curimage = curimage.substr(0,len-1) + (parseInt(curimage.substr(len-1))+1).toString();
    }
    else
    {
        if(curimage[len-1] == '1')
            curimage = curimage.substr(0,len-1) + '8';
        else
            curimage = curimage.substr(0,len-1) + (parseInt(curimage.substr(len-1))-1).toString();
    }
}

