var the_timeout;
var theWidth = 0;
strip = new Array();
indi = new Array();


function WM_netscapeCssFix() {
  /*
    Source: Webmonkey Code Library
    (http://www.hotwired.com/webmonkey/javascript/code_library/)

    Author: Taylor
    Author Email: taylor@wired.com
    Author URL: http://www.taylor.org/
    */

  // This part was inspired by Matthew_Baird@wayfarer.com
  // It gets around another unfortunate bug whereby Netscape 
  // fires a resize event when the scrollbars pop up. This 
  // checks to make sure that the window's available size 
  // has actually changed.
  if (document.WM.WM_netscapeCssFix.initWindowWidth != window.innerWidth || document.WM.WM_netscapeCssFix.initWindowHeight != window.innerHeight) {
    document.location = document.location;
  }
}

function WM_netscapeCssFixCheckIn() {
  // This function checks to make sure the version of Netscape 
  // in use contains the bug; if so, it records the window's 
  // width and height and sets all resize events to be handled 
  // by the WM_netscapeCssFix() function.
  if ((navigator.appName == 'Netscape') && (parseInt(navigator.appVersion) == 4)) {
    if (typeof document.WM == 'undefined'){
      document.WM = new Object;
    }
    if (typeof document.WM.WM_scaleFont == 'undefined') {
      document.WM.WM_netscapeCssFix = new Object;
      document.WM.WM_netscapeCssFix.initWindowWidth = window.innerWidth;
      document.WM.WM_netscapeCssFix.initWindowHeight = window.innerHeight;
    }
    window.onresize = WM_netscapeCssFix;
  }
}

WM_netscapeCssFixCheckIn();



////////////////////////////
// PRINT IMAGES


function addPic(whichOne, index){
   tmpStr = '';
   
   //srcStr is the source to restore to on rollovers
   tmpStr += '';
   tmpStr += '';
   tmpStr += '<img src="portfolio/'+whichOne+'" name="'+whichOne+'" height="296" border=0>';
   tmpStr+='</a>';
   return tmpStr;
}

////////////////////////////
// SCROLL DIV LAYER


function layerWidth()
{
  for(i=0;i<strip.length;i++){
  	var imgRef = strip[i];
    if (document.documentElement || document.all) 
    {
      //theWidth = theWidth + document.images[imgRef].width;
	  theWidth = 25600;
    } 
    else if (document.layers)
    {
      theWidth = theWidth + document.myDiv.document.images[imgRef].width;
    }  
  }
}


function setUp(){
   var the_style = getStyleObject("myDiv");
   the_style.width = theWidth;
}


function getStyleObject(objectId) {
    // cross-browser function to get an object's style object given its
    if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
	return document.layers[objectId];
    } else {
	return false;
    }
}


function moveDivRR()
{
  // get the stylesheet
  //
  var the_style = getStyleObject("myDiv");
  if (the_style)
  {
    // get the current coordinate and add 5
    //
    var current_left = parseInt(the_style.left);
    var new_left = current_left - 5;

    // set the left property of the DIV, add px at the
    // end unless this is NN4
    //
    if((current_left > (theWidth-814)*-1)){
    if (document.layers) 
    {
      the_style.left = new_left;
    }
    else 
    {  
      the_style.left = new_left + "px";
    }
    }
    if((new_left > (theWidth-814)*-1)){
         the_timeout = setTimeout('moveDivRR();',10);
    }
	else {
		clearTimeout(the_timeout); 
	}
  }
}

function moveDivLL()
{
  // get the stylesheet
  //
  var the_style = getStyleObject("myDiv");
  if (the_style)
  {
    // get the current coordinate and add 5
    //
    var current_left = parseInt(the_style.left);
    var new_left = current_left + 5;

    // set the left property of the DIV, add px at the
    // end unless this is NN4
    //
	if (current_left < 0){
    if (document.layers) 
    {
      the_style.left = new_left;
    }
    else 
    {  
      the_style.left = new_left + "px";
    }
    }
    if((new_left < 0)){
         the_timeout = setTimeout('moveDivLL();',1);
    }
	else {
		clearTimeout(the_timeout); 
	}
  }
}

function moveDivR()
{
  // get the stylesheet
  //
  var the_style = getStyleObject("myDiv");
  if (the_style)
  {
    // get the current coordinate and add 5
    //
    var current_left = parseInt(the_style.left);
    var new_left = current_left - 1;

    // set the left property of the DIV, add px at the
    // end unless this is NN4
    //
    if((current_left > (theWidth-814)*-1)){
    if (document.layers) 
    {
      the_style.left = new_left;
    }
    else 
    {  
      the_style.left = new_left + "px";
    }
    }
    if((new_left > (theWidth-814)*-1)){
         the_timeout = setTimeout('moveDivR();',4);
    }
	else {
		clearTimeout(the_timeout); 
	}
  }
}

function moveDivL()
{
  // get the stylesheet
  //
  var the_style = getStyleObject("myDiv");
  if (the_style)
  {
    // get the current coordinate and add 5
    //
    var current_left = parseInt(the_style.left);
    var new_left = current_left + 1;

    // set the left property of the DIV, add px at the
    // end unless this is NN4
    //
	if (current_left < 0){
    if (document.layers) 
    {
      the_style.left = new_left;
    }
    else 
    {  
      the_style.left = new_left + "px";
    }
    }
    if((new_left < 0)){
         the_timeout = setTimeout('moveDivL();',4);
    }
	else {
		clearTimeout(the_timeout); 
	}
  }
}

function toStart()
{
  // get the stylesheet
  //
  var the_style = getStyleObject("myDiv");
  if (the_style)
  {
    // get the current coordinate and add 5
    //
    var new_left = 0;

    // set the left property of the DIV, add px at the
    // end unless this is NN4
    //
	if (document.layers) 
    {
      the_style.left = new_left;
    }
    else 
    {  
      the_style.left = new_left + "px";
    }
    
  }
}

function toEnd()
{
  // get the stylesheet
  //
  var the_style = getStyleObject("myDiv");
  if (the_style)
  {
    // get the current coordinate and add 5
    //
    var new_left = (theWidth-814)*-1;

    // set the left property of the DIV, add px at the
    // end unless this is NN4
    //
	if (document.layers) 
    {
      the_style.left = new_left;
    }
    else 
    {  
      the_style.left = new_left + "px";
    }    
  }
}


function scrollLeftt(){
	the_timeout=setTimeout('moveDivL();',100); 
	return false;	
}

function scrollRight(){
	the_timeout=setTimeout('moveDivR();',100); 
	return false;	
}

function scrollLefttFast(){
	the_timeout=setTimeout('moveDivLL();',100); 
	return false;	
}

function scrollRightFast(){
	the_timeout=setTimeout('moveDivRR();',100); 
	return false;	
}


////////////////////////////
// LOADING

function preLoad(){
   tmpArr = new Array();
   changeObjectVisibility('myDiv', 'hidden');
   changeObjectVisibility('loading', 'visible');
   for(i=0;i<strip.length;i++){
      tmpArr[i] = new Image();
	  tmpArr[i].src = "images/"+catalouge+"/b_"+strip[i];
   }                  
   changeObjectVisibility('loading', 'hidden');
   changeObjectVisibility('myDiv', 'visible'); 
}


function changeObjectVisibility(objectId, newVisibility) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	styleObject.visibility = newVisibility;
	return true;
    } else {
	// we couldn't find the object, so we can't change its visibility
	return false;
    }
} // changeObjectVisibility
