/* ################################################################# */
/*                                                                   */
/*  TITLE:        UTILS.JS                                           */
/*  SITE:         weddingatelier.com                                 */
/*  AUTHOR:       Brian Maniere                                      */
/*  VERSION:      1.00                                               */
/*  LAST UPDATED: 2006/05/04                                         */
/*                                                                   */
/*                                                                   */
/*  DEFINITIONS                                                      */
/*   imagePath                                                       */
/*                                                                   */
/*  CONSTRUCTORS:                                                    */
/*    img()                                                          */
/*    preloadImg()                                                   */
/*                                                                   */
/*  FUNCTIONS:                                                       */
/*    randomizeArray()                                               */
/*    swapImage()                                                    */
/*    addLoadEvent()                                                 */ 
/*    preloadImages()                                                */
/*    doWindowStatus()                                               */
/*                                                                   */
/* ################################################################# */


var imagePath = "../images/";

	// img constructor
function img(file,width,height,text) {
	this.file = file;
	this.width = width;
	this.height = height;
	this.text = text;
	return this;
}

	// preloadImg constructor
function preloadImg(file) {
	this.file = file;
	return this;
}

	// randomize an array
function randomizeArray(array_in) {
  var i = array_in.length;
  if (i == 0) return false;
  while (--i) {
     var j = Math.floor(Math.random()*(i+1));
     var temp_i = array_in[i];
     var temp_j = array_in[j];
     array_in[i] = temp_j;
     array_in[j] = temp_i;
   }
}

	// swap an image
function swapImage(img,src,text) {
	img.setAttribute("src", src);
	img.setAttribute("alt", text);
	var parent = img.parentNode;
	if (parent.tagName == "a") {
		parent.setAttribute("title",text);
	}
	return false;
}

	// add an event to window.onload
function addLoadEvent(func) {
	var oldOnload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldOnload();
			func();
		}
	}
}

	// requires properly formatted array parameter
function preloadImages(arrImages) {
  for(var i=0; i < arrImages.length; i++) {
    var img = new Image();
    img.src = imagePath + arrImages[i]["file"];
  }
}

	// set window status
function doWindowStatus(msg) {
	window.status = msg;
	return true;
}