// shootnhunt.js | based on alexjet JavaScript function library | VERSION 3.0
// Copyright 2006-2008 Alexander Media, Inc. - All rights reserved.
// By: 12.17.2008_rg

function dataobject(imagesnamelist, currentimage){
	// function to initialize data object	
	this.imagesnamelist = imagesnamelist;
	this.currentimage = currentimage;
}

function imageobject(imagePath){
	// function to initialize image object	
	this.imagePath = imagePath;
}

function showimage(n, m){ // n = image number, m = image name attribute value
	// show image in the document
	if (document.imagesarray != null && m.length > 0){
		if (document.imagesarray.length >= n){ // image must exist
			dt.currentimage = n-1;
			if (navigator.userAgent.indexOf('Safari') != -1) // Safari workaround for proper resizing
				document[m].src = 'http://images.shootnhunt.com/templateobjects/clear.gif';
			document[m].src = document.imagesarray[dt.currentimage].src;
		}
	}
	return;
}

function rotateimages(){
	if (dt.imagesnamelist.length >= 1){ // there are images to be shown
		if ((dt.currentimage+1) < dt.imagesnamelist.length){
			var tmpcurrentimage = dt.currentimage+2;
			showimage(tmpcurrentimage, 'polaroidpic');
		}
		else // cycle around
			showimage(1, 'polaroidpic');
	}
}

function preloadimages(){
  // preload images onto an array under the document object
  mgsrry = new Array();
  if (dt.imagesnamelist.length >= 1){ // there are images to be preloaded
  	for(k=0; k<dt.imagesnamelist.length; k++){
		mgsrry[k] = new Image;
		mgsrry[k].src = dt.imagesnamelist[k].imagePath;
	} // for
  } // if
  if (document.images && mgsrry.length > 0){
  	document.imagesarray = mgsrry;
	return true;
  }	
  return false;
}

function startup(){
    // start the system
	if (preloadimages())
	    showimage(1, 'polaroidpic');
	setInterval("rotateimages()", 4000);
}

// data
dt = new dataobject(new Array(), -1);
dt.imagesnamelist.push(new imageobject('http://images.shootnhunt.com/templateobjects/polaroids/polaroid_01.jpg'));
dt.imagesnamelist.push(new imageobject('http://images.shootnhunt.com/templateobjects/polaroids/polaroid_02.jpg'));